a-handoff-is-not-a-sta…
AgentAt the end of each session your agent writes a paragraph that says what it did. The next session still spends its first half hour…
A teammate says that their chat application is an agent because it calls a model inside a while loop. Name the parts that a real agent loop needs, and say what goes wrong when each one is missing.
Claude Code
$ npx -y skills add rohitg00/ai-engineering-from-scratch --agent claude-code
Cursor
Cursor also loads subagents from .claude/agents, so copy this file there to use it in Cursor.
id: five-parts-of-an-agent-loop title: What makes a loop an agent and not a chat bot card: agents kind: concept level: 1 roles: [agentic-ai-engineer, ai-developer-relations-engineer, forward-deployed-ai-engineer] rounds: [screen, ml-breadth] tags: [agent-loop, react, tool-registry, stop-condition, turn-budget] minutes: 5 lessons: [phases/14-agent-engineering/01-the-agent-loop] manuals: [] practice: [] cheatsheet: [agent-harness] related: [] updated: 2026-11-03
A teammate says that their chat application is an agent because it calls a model inside a while loop. Name the parts that a real agent loop needs, and say what goes wrong when each one is missing.
An agent loop needs five parts: a message buffer that grows with each turn, a tool registry that the model calls by name, a stop condition, a turn budget, and an observation formatter. The model is the same in a chat bot and in an agent. The difference is that the agent can pause, call a tool, read the result and continue. Without the five parts, the loop is a chat bot with extra steps.
The pattern is the one from the ReAct paper. The model writes a thought, picks an action, reads an observation, and repeats until it decides to finish. Modern models move the thought to a separate reasoning channel, but the control flow is the same. Observe, think, act, observe, think, act, stop.
| Part | What it does | Failure when missing | |---|---|---| | Message buffer | Holds the user turn, the assistant turns, the tool turns and the final turn in order | The model forgets what it already did and repeats work | | Tool registry | Maps a tool name to a schema and a callable | The model names tools that do not exist, and nothing runs | | Stop condition | Ends the run on an explicit finish, on a turn with no tool call, on a budget, or on a guardrail | The run never ends, or ends only when the context is full | | Turn budget | Caps the number of iterations for this task class | One bad decision at step 38 becomes an endless run | | Observation formatter | Converts every tool output, including every error, into a string the model can read | A failed call becomes a crash instead of a correction |
The formatter is the part that people forget. The lesson says that every 400 error in the stack must become an observation string, not an exception. A model that sees the error can correct the next call. A model that never sees it cannot.
Agents run 40 to 400 steps per task. Every framework in use today builds the same loop under its own names. The things that differ live around the loop: checkpoints, actor messaging, role templates, tracing. The loop itself does not change.
The [agent loop lesson](../../../phases/14-agent-engineering/01-the-agent-loop/) builds the five parts with a scripted model and three tools.
At the end of each session your agent writes a paragraph that says what it did. The next session still spends its first half hour…
Read this part of the harness loop. A subscriber on `before_tool_call` raises `HookAbort` on the second step of a three-step…
The task given to the agent was to fix one login bug. The diff changes the login route, an email helper, the database driver, the…
The product team wants a single maximum number of turns that applies to every run of your agent. The agent handles one-line…
Read this run method from the toy agent loop. A caller shows the returned string to the user as the answer. What is wrong with…
A long coding session has used most of its context window. The runtime offers to summarize the older turns and keep going. Your…
Reviews the repository's shared Claude Code configuration (.claude/settings.json, CLAUDE.md, .claude/rules/, .mcp.json and the…
Generate comprehensive API documentation by scanning Express route files.
Advisor to a busy principal. Optimizes for the user's time, attention, and decision quality. One of the starter-kit council…