Skip to main content

Module fighter_loop

Module fighter_loop 

Source
Expand description

The core agent execution loop.

run_fighter_loop is the heart of the Punch runtime. It orchestrates the conversation between the user, the LLM, and the tools (moves), persisting messages to the memory substrate and enforcing loop guards.

§Production features

  • Context window management: Tracks estimated token count and trims messages when approaching the context limit.
  • Session repair: Fixes orphaned tool results, empty messages, duplicate results, and missing results on startup and after errors.
  • Error recovery: Handles empty responses, MaxTokens continuation, and per-tool timeouts.
  • Loop guard: Graduated response (Allow → Warn → Block → CircuitBreak) with ping-pong detection and poll-tool relaxation.

Structs§

FighterLoopParams
Parameters for the fighter loop.
FighterLoopResult
Result of a completed fighter loop run.

Functions§

run_fighter_loop
Run the fighter loop: the core agent execution engine.