# What Is an Agentic Loop? How Claude and ChatGPT Agents Work Through a Job

> An agentic loop is the cycle an AI agent repeats until a job is done: gather context, pick a step, use a tool, check the result.

By Pat Simmons · November 16, 2026 · 9 min read

Canonical: https://www.aiformortals.co/blog/agentic-loop

An agentic loop is the cycle an AI agent repeats until a job is done. It looks at the goal and everything it has learned so far, decides the next step, uses a tool (a web search, a file edit, a command, a click), checks what came back, then goes round again. Developer Simon Willison's short version is that "An LLM agent runs tools in a loop to achieve a goal."

Anthropic describes the same cycle for its Claude Agent SDK as "gather context -> take action -> verify work -> repeat." A chatbot answers once and waits for you. An agent keeps looping until it finishes, hits a limit you set or stops to ask you, which is why it can carry a multi-step job and also why it uses more tokens and needs guardrails.

Last checked November 16, 2026: how the loop is described in Anthropic's engineering posts, the Claude Code docs and OpenAI's Agents SDK docs, all linked below.

## What is looping in AI?

Looping in AI means calling the model again and again on one task, each time handing it the results of its last step, until it decides the task is done. One call to a chatbot gives you one answer. A loop lets the model act, see what happened and adjust.

Anthropic's guide to building effective agents says agents "are typically just LLMs using tools based on environmental feedback in a loop." The environment is whatever the agent works in (your files, a browser, an inbox), and the feedback is what a tool sends back, such as search results, an error message or a passing test.

The idea goes back to research like ReAct, a 2022 paper by Shunyu Yao and colleagues that had a language model write out its reasoning and take actions in turns, for example looking something up through a simple Wikipedia API before answering. OpenAI describes ChatGPT agent in similar terms: it works on its own virtual computer, "fluidly shifting between reasoning and action."

## What is the perception part of an agentic loop?

Perception is the first step of the loop, where the agent takes in what it needs before deciding anything: your request, the files or pages it can open, and the result of its last action. Anthropic and the Claude Code docs call this step "gather context." A full turn of the loop has four steps:

- Look: gather context.

- Decide: pick the next step.

- Act: use a tool.

- Check: look at the result, then repeat or stop.

The Claude Code docs describe three phases (gather context, take action and verify results) and say they "blend together." The deciding happens inside the model at every phase: "Claude decides what each step requires based on what it learned from the previous step."

_The "agentic loop" section of Anthropic's Claude Code docs, with the diagram running from your prompt through gather context, take action and verify results, a "repeat" arrow, and a box for you to interrupt or steer. Red box added by AI for Mortals. Source: How Claude Code works._

Tools are how an agent perceives anything beyond your message. The docs say that without tools, Claude "can only respond with text," and that "each tool use returns information that feeds back into the loop, informing Claude's next decision."

The docs' own example is a request to "fix the failing tests." Claude might run the tests to see what fails, read the error, search for the files involved, read them, edit them and run the tests again to check the fix. Reading the error and the files is the perception part, and running the tests at the end is the check.

## Can you give me an example of an agentic AI?

Claude Code and OpenAI's Codex sorting an email inbox is one concrete example. In the demo shown in our guide to agentic AI vs generative AI, Pat Simmons opened both agents on the same folder and typed "triage my email inbox."

That folder held plain text instruction files: an agents.md file with the agent's job, a memory.md file with notes from earlier conversations, and skill files with step-by-step rules. Both agents read his Gmail, filtered out spam, trash, promotions and social mail, and listed the important messages with a reporter's interview request first. When he asked, they drafted the reply and saved it in Gmail.

For comparison, the same job as a chatbot meant pasting one email into ChatGPT, getting a draft back and copying each reply into Gmail by hand. The table maps the agent version onto the loop.

Loop stepWhat the agent doesIn the inbox demoWhat the docs call it

LookReads the request and whatever it can reachRead the instruction and memory files, then the Gmail inboxGather context (Anthropic, Claude Code)
DecideThe model picks the next stepSorted out spam, trash, promotions and social mailReasoning (ReAct); the model "produces its output" (OpenAI)
ActUses a toolUsed Gmail as a tool to read mail and, when asked, save draft repliesTake action (Anthropic, Claude Code); tool calls (OpenAI)
CheckLooks at the result and repeats or stopsListed the important messages, reporter first, and waited for Pat before draftingVerify work (Anthropic); verify results (Claude Code); final output ends the run (OpenAI)

## Agentic loop vs chatbot vs workflow

A chatbot answers once and waits, a workflow follows steps a person wrote in advance, and an agent runs a loop where the model picks its own next step. Anthropic defines workflows as "systems where LLMs and tools are orchestrated through predefined code paths," and agents as systems where LLMs "dynamically direct their own processes and tool usage."

A workflow can still call a model several times, but the order is fixed in code. In an agentic loop, the model decides whether to search again, edit a file or stop, based on what the last tool returned.

_Anthropic's diagram of an autonomous agent: the model call sends an action to the environment, gets feedback back, can check in with a human, and ends at Stop. Source: Anthropic's Building effective agents._

Anthropic suggests agents for "open-ended problems where it's difficult or impossible to predict the required number of steps." It recommends "finding the simplest solution possible, and only increasing complexity when needed," since agentic systems "often trade latency and cost for better task performance." For many applications, it says, a single well-prepared call to the model "is usually enough."

## When does an agentic loop stop?

An agentic loop stops when the model decides the job is done, when it hits a limit you set, or when it pauses for a person. Anthropic says a task "often terminates upon completion," and that it's "also common to include stopping conditions (such as a maximum number of iterations) to maintain control." Agents can also "pause for human feedback at checkpoints or when encountering blockers."

OpenAI's Agents SDK docs spell the loop out step by step. The runner calls the model; if the reply counts as a final output, "the loop ends"; if the model asks for tools, the tools run, their results are added and the loop runs again. A setting called max_turns caps how many times it can go round, and going past it raises an error.

_"The agent loop" in OpenAI's Agents SDK docs: call the model, end on a final output, run any tool calls and loop again, and stop with an error past max_turns. Red box added by AI for Mortals. Source: OpenAI Agents SDK, Running agents._

OpenAI counts a final output as text of the expected type with no tool calls. You can also stop a loop yourself: in Claude Code, pressing Esc stops Claude immediately, and ChatGPT agent lets you interrupt, take over the browser or stop a task at any point.

Every extra turn is another call to the model, so longer loops use more tokens. AIFM logged this when three Claude models did the same five from-scratch builds in Claude Code: Fable 5 used 119.7 million input tokens and Fable 5.1 used 84.5 million, at API-equivalent costs of $297.01 and $159.93. Most of that gap came from Fable 5.1 finishing the same work in fewer turns; see what agentic builds really cost in tokens and time.

## What can go wrong, and how to keep a loop safe

A loop can repeat a mistake, build on it or carry out a harmful instruction, so the main protections are limits on what the agent can touch and a person approving risky steps. Anthropic says agents' autonomy "means higher costs, and the potential for compounding errors," and recommends testing in sandboxed environments (walled-off setups where a mistake can't reach your real accounts or files) with guardrails.

Coding agents usually ask before running commands. Willison's post on designing agentic loops covers what happens when you switch that off and approve everything by default, which he calls "YOLO mode." He lists three risks:

- Shell commands that delete or mangle things you care about

- Theft of files, code or secrets the agent can see

- Your computer used to attack someone else

Theft can come through prompt injection, where instructions planted in something the agent reads, such as a web page, try to make it do something you didn't ask for.

His fixes are to run the agent in a sandbox, run it on someone else's computer (a cloud machine) so the damage stays there, and give it only tightly scoped credentials. Where a credential can spend money, he advises setting a tight budget limit. The same idea applies to letting an agent act with your money.

The tools build in their own brakes. Claude Code snapshots a file before editing it so you can rewind, though its checkpoints don't cover actions on outside systems such as databases or deployments, which its permission modes control instead. OpenAI says ChatGPT agent "requests permission before taking actions of consequence."

## What is loop engineering?

Loop engineering means designing the whole loop an agent runs in: its goal, its tools, how it checks its work and when it must stop. Willison calls the skill "designing agentic loops" and says "the art of using them well is to carefully design the tools and loop for them to use."

His test for when a loop is worth building is a job with clear success criteria that needs a lot of trial and error. His examples include debugging a failing test, speeding up a slow database query and upgrading software packages, and the common thread is automated tests the agent can run to check itself.

Anthropic's advice centers on the check step. Its Claude Agent SDK post says agents that can check their own output "catch mistakes before they compound," and suggests three ways to give them that: clear rules with error messages (such as a code linter, which flags mistakes in code), screenshots the model can look at, or a second model acting as judge. Setting the goal and checking the result is also the human side of what agentic engineering means.

## Questions people ask about agentic loops

Is an agent loop the same as an agentic loop?

Yes. Anthropic's Agent SDK post uses both "agent loop" and "agentic loop" for the same cycle, the Claude Code docs call it "the agentic loop," and OpenAI's docs call it "the agent loop."

Is observe, think, act the same thing?

Yes, it's another name for the same cycle. Observe matches gather context, think is the model deciding, and act is the tool call; the result of each action becomes the next observation.

Does the loop remember earlier steps?

Within one task, yes. Each tool result is added to what the model sees before the next turn (OpenAI's docs say the results are appended and the loop runs again), so earlier steps stay in view. A new Claude Code session starts with a fresh context window, and instructions that should carry over live in files such as CLAUDE.md.

## Sources

- Simon Willison: I think "agent" may finally have a widely enough agreed upon definition to be useful jargon now (Sep 18, 2025)

- Simon Willison: Designing agentic loops (Sep 30, 2025)

- Anthropic: Building effective agents (Dec 19, 2024)

- Anthropic: Building agents with the Claude Agent SDK (Sep 29, 2025)

- Claude Code docs: How Claude Code works

- OpenAI Agents SDK docs: Running agents

- OpenAI: Introducing ChatGPT agent

- Yao et al.: ReAct: Synergizing Reasoning and Acting in Language Models (arXiv)
