Loading…
Loading…
An agentic loop is the cycle that turns a language model into an agent. Instead of answering in one shot, the model runs a repeating loop: it gathers context, reasons about what to do next, takes an action (usually a tool call), observes the result, and feeds that result back in — iterating until the goal is met or a stop condition fires. That feedback loop is the whole difference between a chatbot and an agent.
Repeat until the goal is met — or a stop condition fires.
Definitions
A single-shot call answers once: prompt in, answer out, no feedback. Useful, but it can't recover from a wrong assumption because it never sees a result.
A workflow wraps the model in code you wrote: predefined steps, with the LLM filling in pieces along a fixed path. Predictable, but only as flexible as the path you hardcoded.
An agent runs a loop where the model itself decides the next action based on what it just observed. As Anthropic puts it, agents are “just LLMs using tools based on environmental feedback in a loop.” That feedback loop — gaining ground truth from the environment at each step — is what makes an agent able to handle tasks you couldn't script in advance.
Step by step
Every agent — from a coding assistant to a voice agent — runs some version of this five-step cycle.
Assemble what the model needs to decide its next move — the goal, the conversation so far, retrieved documents, prior tool results, and the current state of the world — into the context window. Deciding what to include (and what to leave out) is the practice now called context engineering.
The model thinks about the current state and chooses a single next action. In a well-built agent it does not call the tool itself — it returns a structured tool call describing what it wants to do.
The harness (the code around the model) validates that tool call against a schema, checks permissions, and executes it — running code, querying an API, editing a file, sending a message. The harness is the gate; the model never touches systems directly.
The result of the action — a tool output, an error, a changed file, a test result — is captured and fed back into the context as ground truth. This observation is what keeps the agent grounded in reality rather than its own assumptions.
With the new observation in hand, the loop runs again. It keeps iterating until the task is done — or until a stop condition trips: a max-iteration cap, a token budget, a timeout, a repeated-action detector, or a human-in-the-loop approval gate.
The harness, not the model, runs the loop. A production agent never lets the model call tools directly — the model returns a structured tool call, and the surrounding code validates the schema, checks permissions, executes it, and injects the result back. That outer code is the harness, and engineering it well is most of the job. See how the Claude Agent SDK runs this loop ↗
In practice
Three real agent types, one iteration trace each. Notice the loop only stops when the goal is met — or a safeguard hands off to a human.
Goal met — tests pass, so the loop halts on its own.
Goal met — or escalate to a human rep if the lead is off-ICP or high-value.
Goal met — but hand off to a human if the customer asks for a refund above the auto-approve threshold.
Named patterns
Most “agent architectures” are variations on the base loop. These are the patterns you'll see named again and again — and the ones worth knowing before you build.
Worth noting: prompt chaining, routing, and parallelization are often listed alongside these, but they're workflow patterns — orchestrated by code, not driven by the model's own loop. The line between a workflow and an agent is exactly who decides the next step.
Loop control
Each iteration costs tokens, time, and money — and a loop with no brakes is a runaway bill. The hard problems in agent engineering are about controlling the loop:
For concrete stop-condition knobs — max turns, budget caps, context compaction — see the Claude Agent SDK agent-loop docs; for a practical take on designing and sandboxing loops, Simon Willison's Designing agentic loops is the reference.
Agent types built on these loops
The patterns above aren't academic — they're what these production agents run on.
All agent typesContext-aware suggestions, reviews, and refactoring in your IDE—no setup scripts.
View full guide →salesResearch leads, personalize outreach, and book meetings—deploy in minutes, no code required.
View full guide →supportDeflect tickets, answer from your knowledge base, and escalate when needed—no code required.
View full guide →data analysisWrite SQL, visualize trends, and answer business questions via chat—no code required.
View full guide →operationsAutomate internal IT tickets, employee onboarding, and system monitoring.
View full guide →Sources & further reading
The definitions and patterns on this page trace back to these.
FAQ
An agentic loop is the repeating cycle an AI agent runs to complete a task: gather context, reason about the next action, act (usually by calling a tool), observe the result, and repeat until the goal is met or a stop condition fires. It is the core mechanism that separates an agent — which iterates and adapts to feedback — from a single-shot model that answers once.
In a workflow, a human writes the steps in code and the LLM fills in pieces along a predefined path. In an agent loop, the model itself decides what to do next at each turn based on what it observes — it directs its own tool use. Workflows are more predictable; agent loops are more flexible. Most production systems combine both: workflows for the well-understood parts, agent loops where the path can't be hardcoded.
Production agents use several guardrails at once: a max-iteration cap (often 10–25 steps), a token budget per run, a wall-clock timeout, repeated-action detection (the agent is stuck doing the same thing), and a human-in-the-loop gate for irreversible or high-cost actions. A well-built agent usually halts on its own when the task is done; these are the safety nets for when it doesn't.
ReAct (Reasoning + Acting) is the most common agent loop pattern: the model alternates between a reasoning step (thinking through the problem) and an acting step (calling a tool), feeding each observation back into the next thought. The Thought → Action → Observation cycle keeps the agent grounded in real tool results and is the default shape of most tool-using agents today.
Context engineering is the practice of deciding what to put in the model's context window at each turn of the loop — instructions, retrieved evidence, prior results, and state — so the model has what it needs without drowning in noise (a failure mode called context rot). Harness engineering is the broader discipline of building the code around the model: validating tool calls, enforcing permissions and budgets, managing memory, and controlling when the loop stops. As models have gotten stronger, the harness and its context have become where most agent reliability is won or lost.
Agentic AI is the umbrella term for systems that plan, use tools, and act autonomously. An agentic loop is the atomic mechanism inside such a system — the observe-reason-act-observe cycle of a single agent. An agentic workflow is the outer orchestration that coordinates one or more agents, tools, and humans toward a larger outcome. Loop is the engine; workflow is the assembly line; agentic AI is the category.
Next
Knowing the loop is one thing; shipping a reliable one is another. Tell us your use case and we'll scope the right agent — loop control, tools, and guardrails included.