Expand description
The turn worker: a child process (Role::Turn) that
runs ONE turn over the context slice the supervisor handed it — a root /
conversation turn, a bounded agent step, or a structured think — and
reports the transcript delta, the usage and the outcome (TurnDone).
It calls the model and MCP tools itself; internal tools (memory, plan,
subagents, sleep, finish, …) are round-tripped to the supervisor
(ToolRequest → ToolResult) so state changes are made by the state
owner. Before each model call it may ask for budget admission
(BudgetRequest → BudgetGrant).
The turn keeps tool results structured (structuredContent first,
text-JSON second, text last), validates a schema’d final answer and
re-asks on a miss, keeps a serializable transcript, estimates tokens for
admission, and detects call loops. The loop body is run_turn, generic
over a Bridge so it is unit-testable in-process; run_turn_child is
the process entry.
Structs§
- Budget
Reply - A budget grant as the worker sees it.
- Child
Bridge - The process bridge: frames over the control channel.
- McpClients
- The connected MCP clients as an
McpCaller. - Turn
Limits - The knobs of one turn (from the payload).
Constants§
- DEFAULT_
MAX_ TOKENS_ PER_ CALL - Default per-response completion cap.
- LOOP_
REPEATS - The same tool call (name + args) this many times in one turn is a loop.
- SCHEMA_
REASKS - Re-asks when a schema’d answer misses.
- TOOL_
CALL_ CAP - Longest a single MCP tool call may take inside a turn.
Traits§
- Bridge
- The supervisor link: internal-tool and budget round-trips + cancellation.
- McpCaller
- How MCP tools are reached from the turn.
Functions§
- parse_
json_ answer - Parse a model’s JSON answer tolerantly (fences, prose around the object).
- run_
turn - Run ONE turn. Never panics; every failure is a
TurnResultstatus. - run_
turn_ child - The process entry for a
Role::Turnchild: run the turn, reportUsage+TurnDone, return the exit code. - tool_
result_ value - The value of an MCP tool result:
structuredContent, else the text parsed as JSON, else the text.