Skip to content

Agent Loop

Medium — good to knowAI & ML

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.