Autobot::Agent::ToolExecutor
Executes the ReAct-style tool-calling loop.
Calls the LLM, executes any requested tool calls, appends results, and repeats until the LLM returns a text response or max iterations is reached.
Applies a sliding-window truncation strategy: tool results older than one iteration are compressed when they exceed TRUNCATION_THRESHOLD to reduce prompt tokens on subsequent LLM calls.
Used by Loop (for user messages, system messages, cron) and SubagentManager (for background tasks) to avoid duplicating the core agentic loop logic.
Constants
Log = ::Log.for("agent.tool_executor")
MESSAGE_PREVIEW_LENGTH = 120
TRUNCATION_THRESHOLD = 500
Tool results smaller than this (in chars) are kept verbatim. Short results like "Successfully edited file" or error messages are cheap and often useful as ongoing context.
Constructors
Instance methods
execute(messages : Array(Hash(String, JSON::Any)), tools : Tools::Registry, session_key : String | Nil = nil, exclude_tools : Array(String) | Nil = nil, stop_after_tool : String | Nil = nil) : Result
Run the tool-calling loop.
messages: the full message array (system + history + user)tools: registry of available toolssession_key: for per-session rate limiting (nil for subagents)exclude_tools: tool names to omit from LLM tool definitionsstop_after_tool: break early after this tool is called (e.g. "message" for cron)