← Back to overview

The Agent Loop

Every request follows the same path: prepare context, reason about the task, then loop through tool calls until the work is done. This is the core processing logic behind every Arlo run — in the TUI, the one-shot CLI, or the library.

Flowchart of the agent loop: a prompt from a user, schedule, event, notification, or MCP request enters context preparation and model reasoning, then repeats plan, tool selection, permission check, tool execute, observe result, memory update, and task evaluation until no more action is needed, ending in a final response, post processing, and a session end that can later resume.
The full run loop, from trigger to session end — click to enlarge.
Triggers

A turn starts from a user prompt, a scheduled task, an event or webhook, a notification, or an MCP request. Whatever the source, it enters the same pipeline — nothing gets a private code path.

Each request
  1. Prompt — the incoming request, normalized regardless of which trigger produced it.
  2. Context preparation — retrieve, assemble, and compress history, files, and tool schemas to fit the context window.
  3. Model reasoning — the model understands the task and plans an approach before touching anything.
Agentic loop
  1. Plan next action — decide the single next step.
  2. Tool selection — choose the best tool for that step.
  3. Permission check — the human-in-the-loop gate; a rejected call never runs.
  4. Tool execute — perform the action.
  5. Observe result — collect output and feedback, including failures.
  6. Memory update — fold the result back into context and session state.
  7. Task evaluation — is more work needed? If yes, loop back to planning; if no, exit the loop.
Completion
  1. Final response — generate, summarize, and deliver the answer.
  2. Post processing — logs, audit trail, and telemetry.
  3. Session end — state is persisted, so a later trigger can resume the same session.

Each step streams as an event, which is what the TUI renders live and what an embedding application can subscribe to. See how it's built →