Skip to main content

Module worker

Module worker 

Source
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 (ToolRequestToolResult) so state changes are made by the state owner. Before each model call it may ask for budget admission (BudgetRequestBudgetGrant).

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§

BudgetReply
A budget grant as the worker sees it.
ChildBridge
The process bridge: frames over the control channel.
McpClients
The connected MCP clients as an McpCaller.
TurnLimits
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 TurnResult status.
run_turn_child
The process entry for a Role::Turn child: run the turn, report Usage + 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.