Skip to main content

Module tool_loop

Module tool_loop 

Source
Expand description

Tool loop - deterministic multi-turn fake-tool conformance harness (feedback 02, suite 40-multi-turn-tool-loop).

This is the most important Hermes test: a LIVE model must complete a three-step fixture workflow through OpenAI-format tool calls backed by deterministic in-memory fake tools - no filesystem, terminal, or network side effects beyond the one chat-completions POST per assistant turn:

  1. read_fixture - the runner returns the fixture source;
  2. run_fixture_test - the runner returns a CONTROLLED failure report;
  3. write_fixture_patch - the runner returns a success report;
  4. the model delivers a concise final answer with no tool calls.

Acceptance (feedback 02): correct ordering (read before run before write; re-reading after a successful run is a violation), no invalid tool names, all argument JSON valid and schema-conformant, no duplicate call of the same tool with identical arguments after a successful result, a final answer, and at most TOOL_LOOP_MAX_TURNS turns. Every violation maps to exactly one FailureClass: a first turn with no tool calls is FailureClass::NoToolCall, an unknown tool name is FailureClass::InvalidToolName, unparseable or schema-violating arguments are FailureClass::InvalidToolArguments, a repeated (name + identical arguments) call is FailureClass::DuplicateToolCall, and an incomplete or mis-ordered workflow (including a final answer that skips part of the workflow) or a turn-budget breach is FailureClass::ToolLoopDidNotConverge.

Cost gate: the live loop is opt-in. run_tool_loop refuses with CloudflareError::MissingEnv naming AUTH_CLOUDFLARE_LIVE_TESTS unless live_tests_enabled is true, so CI and unit tests can never trigger a paid call by accident.

Security contract: ToolLoopOutcome carries only tool-call observations (name + arguments + turn) and a truncated final answer - never tool outputs, never prompts, never the token. The Authorization header is built exclusively through crate::fetch::auth_header, and every error string is token-scrubbed before it is returned.

Structs§

ToolCallObservation
One observed tool call from one assistant turn (serialized snake_case).
ToolLoopOutcome
Outcome of one tool-loop run.

Constants§

LIVE_TESTS_ENV
Environment variable gating the LIVE tool-loop harness. Must equal exactly "1" for run_tool_loop to run; anything else (unset, "0", "yes", whitespace) refuses with CloudflareError::MissingEnv.
TOOL_LOOP_MAX_TURNS
Maximum assistant turns allowed for one tool-loop run (feedback 02: “total turns ≤ 8”). A final answer ON the max turn is within budget; tool calls on the max turn are a breach.
TOOL_LOOP_SYSTEM_PROMPT
System prompt for the tool-loop harness (fixed fixture - never derived from user input, so it can never carry secrets).
TOOL_LOOP_USER_PROMPT
User prompt for the tool-loop harness: names the deterministic target fixture so the enum-constrained fixture_id argument is unambiguous.

Functions§

all_arguments_valid
Argument acceptance: every call’s arguments must parse as a JSON object and satisfy the tool’s schema - required fields present, correct types, enum values respected, and no extra properties (additionalProperties: false). Unknown tool names fail (no schema exists for them). Pure and hand-rolled: no jsonschema dependency.
execute_tool
Execute one fake tool in memory. Deterministic per (tool, arguments); never touches the filesystem, terminal, or network.
find_duplicates
Duplicate acceptance: references to every call whose (name, identical arguments) pair was already issued earlier in the sequence - including a repeated run_fixture_test after a successful run, and a re-read of the same fixture. Argument equality is content-based (JSON object key order does not matter).
fixture_source
The fixture source for a known fixture id, if any (deterministic, in-memory only).
live_tests_enabled
True when the live harness is allowed to run: AUTH_CLOUDFLARE_LIVE_TESTS must equal exactly "1" (no trimming, no aliases). Shared with the sibling verify.rs integration runner via the crate root.
run_tool_loop
Run the LIVE multi-turn tool-loop conformance suite for one model.
tool_schemas
The three OpenAI-format fake-tool schemas, built from [TOOL_SPECS].
validate_ordering
Ordering acceptance: the full read → run → write workflow must appear in that order, with no re-read after a run and no run after a write.