Expand description
Multi-turn agent loop driving an LLM through tool calls to completion.
Why: A task needing file reads, tool runs, and reaction to results cannot be
done in one chat call; the loop is the bounded control structure that calls
the model, dispatches gated tool calls, feeds results back, and iterates.
What: AgentLoop, AgentLoopConfig, AgentLoopError, and Transcript. The
loop is bounded by a turn cap and a wall-clock timeout, accrues token usage
via PerfCollector, and returns an AgentOutput.
Test: agent_loop::tests::* (stubbed two-turn flow, turn-cap abort,
recoverable tool error, usage accrual) plus an #[ignore]-gated live test.
Multi-turn agent loop: drive an LLM through tool calls until it stops.
Why: A single chat call cannot accomplish a task that requires reading files,
running tools, and reacting to results. The agent loop is the control
structure that repeatedly calls the model, dispatches any requested tool
calls through the gated registry, feeds results back, and iterates until the
model produces a final answer — bounded by a turn cap, a wall-clock timeout,
and token-usage accounting so runs stay cheap and observable.
What: Exposes AgentLoop, AgentLoopConfig, AgentLoopError, and (#2056)
ToolEventSink. run seeds a Transcript, then loops: build a
ChatRequest from the running history + registry schemas, call
LlmClientTrait::chat, accrue usage into a PerfCollector, append the
assistant turn, and — if there are tool calls — dispatch each via
ToolRegistry::dispatch_gated (notifying the optional sink around each
dispatch) and append the results. Exits with AgentOutput in either of two
ways: the first assistant turn that has NO tool calls (the D3 no-tool-call
finish convention, preserved unchanged as the fallback), or (#2072) an
explicit, successfully-validated finish_task tool call, whose structured
status/summary/changes/test-count fields become the final
AgentOutput via build_finish_output. Aborts with a partial output when
the turn cap, timeout, (#2056) an external cancellation flag, or (#2265
fix #5) an external stop signal fires.
What: The whole chat → dispatch → iterate body runs inside a single
tokio::time::timeout so a stalled model or hung tool cannot block forever.
Test: agent_loop::tests — stubbed two-turn flow, turn-cap abort, recoverable
tool-error continuation, usage accrual, sink notification order, cancellation,
plus an #[ignore]-gated live test.
Structs§
- Agent
Loop - Drives an LLM through a bounded multi-turn tool-calling conversation.
- Agent
Loop Config - Tuning knobs for a single agent-loop run.
- Compaction
Config - Tuning knobs for non-destructive context compaction (#2070, §5.4).
- Transcript
- Running conversation history for one agent-loop run.
Enums§
- Agent
Loop Error - Failure modes of
AgentLoop::run.
Traits§
- Tool
Event Sink - Observes tool dispatch lifecycle events from an
AgentLooprun.