Skip to main content

Module react

Module react 

Source
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 prior turn/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-level PersistSink, 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 role assistant (fixture convention).
  • tool/result: content {"call_id", "output", "is_error"} with role tool.

§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§

ReActConfig
Tuning for the built-in ReAct loop.
ReActLoop
The built-in async ReAct LoopDriver (DESIGN §6.2). Cheap to clone.

Enums§

BudgetScope
How a loop’s iteration budget is scoped (ADR-024).
LoopError
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 Message into 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).