Turn Loop
What it is
The complete path for one user request, from context construction through model calls, tools, and finalization.
In plain terms
Every car rolling off a factory line gets pushed through the same weld-check station, paint booth, and final inspection bay, whether it’s the base trim or a fully loaded model. A message reaching Hermes crosses an equivalent set of fixed stations before an answer comes back out, no matter if it arrived through a chat window, a bot, or a timer.
Why it matters
One user request in Hermes travels a fixed path: context gets assembled, a model gets called, whatever tools it requests get run, and the result gets written back to session state. Cron jobs, gateway messages, and desktop chat all funnel into this same loop, so a scheduled job and a live conversation are handled by identical machinery rather than parallel code. Debugging a missing tool call or an incomplete reply usually starts with figuring out where in this loop things went sideways.
How it works
This path runs inside conversation_loop.py’s run_conversation function: it first calls turn_context.py’s build_turn_context to do everything that only needs to happen once — sanitizing the incoming message, restoring the cached system prompt, compressing history if it’s grown too large — before any model call happens. From there it enters a loop bounded by agent.max_iterations and an iteration budget; each pass calls the model, and if the reply asks for tools, those get routed into agent._execute_tool_calls (agent/tool_executor.py) before the loop calls the model again. Once a reply arrives with no further tool requests, that content is handed back as the finished answer.
A concrete example
Someone asks Hermes to check their calendar and email a summary of the day.
- The loop assembles context and sees calendar and email tools switched on.
- The first model call asks to read the calendar; the loop runs that tool and appends the result.
- The second call asks to send an email; the loop runs that tool too.
- The third call comes back as plain confirmation text with no further tool requests, so the loop stops there and that becomes the reply the user reads.
How it connects
This note belongs to the Runtime family. Its closest neighboring concepts are: Agent Runtime, Turn Context, Personal OS.
Source evidence
vendor/hermes-agent/agent/conversation_loop.py:593-603#run_conversation— Verified Source Map evidence for run_conversation. The conversation loop injects the active prompt, plus any ephemeral prompt, as the first system message, builds provider request kwargs fromapi_messages, and sends the representative streaming branch through LLM execution middleware to_interruptible_streaming_api_call.
Workflows
- No first-pass workflow mapping yet; this concept still appears in the vault graph through articles and source evidence.
Related articles
- Inside Hermes: How the Agent Loop, Context, Memory, Gateways, and Cron Jobs Work Together
- How to Use Hermes Better Than Most People: Architecture, Project Isolation, and Scalable Workflows
