File size: 2,092 Bytes
f5d03aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import json

from .models import WorkflowNode


def decision_prompt(instructions: str, item: str, choices: list[tuple[str, str]]) -> str:
    options = "\n".join(f"- {node_id}: {label}" for node_id, label in choices)
    return f"""You apply explicit decision rules in an educational workflow.
Rules:
{instructions or 'Choose the most suitable route.'}

Current item:
{item}

Available routes (target ID: route label):
{options}

Return only one target ID exactly as shown. Do not explain or invent a route."""


def tool_prompt(tool: WorkflowNode, tool_input: str) -> str:
    return f"""You are a simulated tool in an educational sandbox. Never perform a real action.
Tool name: {tool.data.label}
Tool description: {tool.data.description}
Expected input: {tool.data.input_guidance or 'Plain text relevant to the tool.'}
Simulation instructions: {tool.data.prompt or 'Produce a plausible simulated result.'}

Tool input:
{tool_input}

Return only the simulated tool output as concise plain text. Clearly label simulated side effects as simulated."""


def worker_prompt(instructions: str, item: str, tools: list[WorkflowNode], tool_results: list[dict]) -> str:
    tool_list = "\n".join(
        f"- {tool.id} | {tool.data.label}: {tool.data.description} | Input: {tool.data.input_guidance or 'plain text'}"
        for tool in tools
    ) or "- No tools are available."
    results = json.dumps(tool_results, ensure_ascii=False, indent=2) if tool_results else "None yet."
    return f"""You are an AI Worker in an educational agentic workflow.
Instructions:
{instructions or 'Complete the task using your best judgment.'}

Current item:
{item}

Tools you are permitted to call:
{tool_list}

Tool results already received:
{results}

Decide whether another tool is genuinely needed. Return exactly one JSON object, with no markdown:
{{"action":"call_tool","tool_id":"exact tool ID","tool_input":"specific input for the tool"}}
or
{{"action":"final","output":"your completed work, incorporating any useful tool results"}}

Only call listed tools. Never claim a real-world action occurred."""