Agent Loop
ELI5 - The Vibe Check
The agent loop is the heartbeat of any AI coding agent: think, act, look, repeat. It's less a single clever answer and more a Roomba that keeps bumping into a wall, checking its sensors, and adjusting course until the room is actually clean. The loop is what turns a chatbot into something that can finish a whole task unsupervised.
Real Talk
The agent loop is the control cycle an LLM agent runs: read the current context and tool results, decide on the next action (call a tool or produce a final answer), execute it, observe the outcome, and repeat until a stop condition is met (task complete, error, or turn limit). Every agent harness, from Claude Code to a hand-rolled script, is built around some variant of this loop.
Show Me The Code
while not task_done:
response = llm.generate(messages, tools=available_tools)
if response.tool_calls:
for call in response.tool_calls:
result = execute_tool(call)
messages.append(tool_result(call, result))
else:
task_done = True
final_answer = response.content
When You'll Hear This
"The agent looped for 40 turns before it finally got the tests passing." / "Don't hand-roll your own agent loop, use the SDK's."
Related Terms
Agentic Workflow
An agentic workflow is when you give an AI a goal and let it figure out the steps to get there — breaking down tasks, using tools, making decisions, and it...
AI Agent
An AI Agent is an AI system that can think, plan, and act on its own to accomplish a goal.
Function Calling
Function Calling is the OpenAI term for what Anthropic calls Tool Use — teaching the AI to call your code functions.
Tool Use
Tool use is when an AI can call external functions, APIs, or programs to do things it can't do alone.