Skip to main content

Module agent_loop

Module agent_loop 

Source
Expand description

Generic agent loop — drives agent + tools until completion or limit.

Includes 3-tier loop detection (exact signature, tool name frequency, output stagnation). Features from Claude Code (HitCC analysis):

  • Tool result pairing repair — ensures every tool_use has a matching tool_result
  • Context modifiers — tools can adjust runtime behavior via ToolOutput::modifier
  • Max output tokens recovery — auto-continuation when response is truncated

Structs§

LoopConfig
Loop configuration.

Enums§

LoopEvent
Events emitted during the agent loop.

Functions§

ensure_tool_result_pairing
Ensure every tool_use in messages has a matching tool_result, and vice versa.
run_loop
Run the agent loop: decide → execute tools → feed results → repeat.
run_loop_interactive
Core agent loop — single implementation for both interactive and non-interactive modes.