Expand description
Built-in ReAct loop.
Per iteration: assemble context via derive_model_context, call the
resolved model slot, persist request/response events before they fly,
dispatch tool calls (side effects logged before execution), respect
promote boundaries and the steer allowance, and terminate honestly.
Local process execution runs via spawn_blocking so a sleeping tool
cannot stall concurrent drains.
The loop is a passenger inside the drain (layered iron rule): it
only ever appends events through DrainCtx and reads projections;
admission, claims, interrupts, the end write and episode supervision
belong to the engine.
§Event payload conventions (frozen, additions-only discipline)
turn/start/turn/end:{"iteration": <n>,...}— the iteration counter, derived from the stream (number of priorturn/starts), never from resident state.step/request:{"slot", "provider", "model", "iteration", "body"}— the A2 audit copy of the request, appended before the provider is called (the provider-levelPersistSink, additionally covers fallback-request bytes at the HTTP edge).assistant/message: content{"text": str, "tool_calls"?: [...]}.tool/call(logged before execution): content{"id", "name", "arguments"}with roleassistant(fixture convention).tool/result: content{"call_id", "output", "is_error"}with roletool.
§Honest termination (constraint 7)
An empty model response is a soft failure: the loop consults the
declarative RecoveryPolicySource table for the class
CLASS_EMPTY_RESPONSE and reports LoopOutcome::SoftFailed — the
engine settles it as failed, never completed. The loop itself never
retries (constraint 8: recovery disposition is one-shot-guarded and
owned by the caller).
§Evidence gate on the stop path
When mounted via ReActLoop::with_evidence_gate, every terminal stop
flow (Settled — the final-answer “done” claim — and Stopped) passes
through crate::evidence before it is reported: pass appends
evidence/verdict{passed:true} and lets the stop proceed; fail appends
the failed verdict, buys at most max_retries extra provider turns,
then reports a soft failure the engine settles as failed — never
completed with a failed gate. The gate makes no provider call and
never mutates context. Default-off (built-in behavior unchanged).
Structs§
- ReAct
Config - Tuning for the built-in ReAct loop.
- ReAct
Loop - The built-in async ReAct
LoopDriver(DESIGN §6.2). Cheap to clone.
Enums§
- Budget
Scope - How a loop’s iteration budget is scoped (ADR-024).
- Loop
Error - Loop-level failures. Every one degrades honestly to a soft report — the loop has no code path that could masquerade an error as completion.
Constants§
- CLASS_
EMPTY_ RESPONSE - Recovery-policy class for an empty model response (constraint 7).
- DEFAULT_
MAX_ ITERATIONS - Iteration budget default: stops honest loops that never converge.
Functions§
- to_
chat_ message - Converts a projected
Messageinto the request-body chat shape (dialect v2). Plain string content passes through unchanged (byte-identical to dialect v1); structured content is translated to the strict openai wire shape — anything else is serialized compactly, deterministic under the frozen serialization (lexicographic keys).