Expand description
The ReAct agentic loop.
A turn: assemble the request (system + instruction + transcript + the
scoped tool catalogue) → call intelligence → if the model requested tools,
run them via MCP and feed the results back as observations; otherwise the
text is the final answer. Stopping is a disjunction of cheap checks, each
with a distinct TerminalStatus, and the loop enforces the
step/token/deadline budget itself rather than trusting the model to stop.
This loop produces neither Stalled nor LoopDetected: it has no
no-progress or repeated-tool detector, so a spinning agent is bounded by the
step and token budget instead.
The root agent runs as a subagent process behind the control channel; the loop body here is identical whether driven by the root or a nested child, so there is one code path to reason about regardless of tree position.
Structs§
- Loop
Input - The explicit inputs the loop needs, independent of where they came from
(CLI
Configfor once-mode, or aSpawnPayloadfor a subagent). This is the seam that lets the same loop body run in-process or in a child. - Session
- The durable state of an agent session: the scoped tool catalogue, the
resource-awareness map, and the conversation transcript — everything that
persists across turns. A once-mode / per-event run is a session of exactly
one turn (
run_loop); a warm continue-session runs many turns over the same transcript, each new event appended viaSession::deliverbefore anotherSession::run_turn.
Enums§
- Loop
Abort - A fatal infrastructure failure that aborts the run; the caller maps it to exit 4 or 6. Tool-domain errors are not aborts — a tool that returns an error is fed back to the model as an observation so it can adapt, because only the infrastructure being gone makes further progress impossible.
Functions§
- run_
loop - The agentic loop over explicit inputs — one session, one turn. Used by
once-mode (
run_root) and a per-event subagent run (subagent::control).self_handlersupplies agentd’s in-process self-tools (e.g.subagent.spawn); the loop tries it before MCP. A warm continue-session instead drivesSessiondirectly across many turns.