Agent loop
Look, think, act, check, repeat until the job is done.
What it is
The conductor: it gathers an observation, asks the model for the next action, dispatches it, records the result, and decides whether to continue, re-plan, ask a human or stop.
When to use it
- Any task with more than one step whose path depends on what the agent sees
When to skip it
- A fixed procedure that never changes: record a script (RPA) and skip the model
Why (the trade-off)
Real tasks branch: pages differ, popups appear, data is missing. A loop reacts to each step instead of following a script blindly.
Where it sits
The middle of everything. It calls perception, then the model, then the action layer, and logs each turn.
What it needs first
- one ofVision-capable modelorGeneral assistant modelorCoding modelthe loop asks a model for every next action
What can be added to it
- builds on itConnectors (APIs and MCP)Connectors (APIs and MCP) needs it: the loop decides when to call a tool
- builds on itPlanner (plan, then execute)Planner (plan, then execute) needs it: it plans for the loop
- builds on itStep and spend budgetStep and spend budget needs it: it guards the loop
- builds on itCheckpoint and resumeCheckpoint and resume needs it: the loop writes the checkpoints
- builds on itAction ledger (check before acting)Action ledger (check before acting) needs it: the loop writes it around each action
- builds on itAction policyAction policy needs it: it inspects every action the loop dispatches
- builds on itLong-term memoryLong-term memory needs it: the loop reads and writes it
- builds on itCode tools (read, search, edit, run)Code tools (read, search, edit, run) needs it: the loop chooses each tool call
- builds on itProject memory (AGENTS.md)Project memory (AGENTS.md) needs it: it's loaded into every session
- builds on itContext compactionContext compaction needs it: it manages the loop's context
- builds on itSubagentsSubagents needs it: the main loop delegates
- builds on itMCP clientMCP client needs it: the model's loop decides which tool to call
- builds on itA2A clientA2A client needs it: the loop decides what to delegate
- builds on itLead agent (orchestrator)Lead agent (orchestrator) needs it: the lead is itself an agent loop that can call tools, including "start a subagent"
- builds on itShared memory (plan and notes)Shared memory (plan and notes) needs it: agents read and write it through tools
- builds on itContext budgeterContext budgeter needs it: it assembles each turn's context
- builds on itOne agent or many? (topology router)One agent or many? (topology router) needs it: it configures how the loop runs
- builds on itShared prompt cacheShared prompt cache needs it: it orders each call's context
- builds on itTrace and replayTrace and replay needs it: something has to produce the steps being traced
Effect of adding it
- cost —
- latency —
- reliability —
- safety —
Learn first (AI Engineering)
depth 4+1 production note with numbers.