Explainer

Agentic AI Explained: How AI Agents Work

Agentic AI is an LLM wrapped in a loop with tools. How the five-stage cycle works, where it runs in production, and why only 2% of firms deploy it at scale.

By Ricardo de Jong 10 min read 10:28 video

Watch the explainer

Here is a seven-billion-dollar question. What separates a chatbot from an AI agent? One while loop. You take a language model, wrap it in a loop, hand it some tools, and it stops merely answering questions. It starts reading your codebase, running your tests, fixing bugs, and opening pull requests while you finish your coffee.

The numbers around this are loud. The agentic AI market hit roughly $7.6 billion in 2025 and is projected near $52 billion by 2030. Yet only about 2% of organizations have deployed it at scale. This article explains what makes a system “agentic,” how the loop works under the hood, where it already runs in production, and when you should not use it at all.

What is agentic AI?

Agentic AI is software that puts a language model inside a loop with tools, so it can pursue a goal over multiple steps instead of answering once. The model reasons about what to do, your code runs the action it picks, the result feeds back in, and the cycle repeats until the job is finished. Lilian Weng’s widely cited 2023 formula sums it up: an agent is an LLM plus memory, planning, and tool use.

The word that matters is “agentic,” and it describes a property, not a product. A system is agentic when it directs its own process: it picks the next tool based on what just happened, holds state across steps, and chooses when to stop. A plain model call does none of that. Everything in this article is about that one difference and the engineering it demands.

Agentic AI vs generative AI: the real difference

Generative AI runs an open loop. You send a prompt, it returns text, and the execution thread ends there. It is stateless and one-shot. It does not watch what happened or decide what to do next, which is fine for drafting an email and useless for fixing a failing build.

Agentic AI runs a closed loop instead. It reasons, acts, observes the outcome, and feeds that observation back as new context. The underlying model can be identical. What changes is the scaffolding around it: the loop, the tools, and the code that executes them. That is the jump from a system that talks to a system that does.

Generative AI Open loop
PROMPT MODEL REPLY

Stateless · one shot · the thread ends

Agentic AI Closed loop
REASON ACT OBSERVE

Stateful · iterative · decides when it's done

Fig. 1 Generative AI is an open loop: prompt in, text out, done. Agentic AI closes the loop so the system acts, observes, and keeps going until the goal is met. Same model, different scaffolding.
DimensionGenerative AIAgentic AI
Control flowOpen loop, one passClosed loop, repeats
ExecutionOne input, one outputReason → act → observe → repeat
StateStateless between turnsHolds state across steps
Tool useMaybe one call, if anySelects and sequences tools
TerminationReturns after one replyDecides when it is done
When it failsWrong answer, you retryErrors compound across steps
Good forDrafting, summarizing, Q&AMulti-step, branching work

Why do AI agents exist?

Agents exist because real work branches. Picture the job a developer actually does. A bug report comes in, you read the issue, you grep the codebase for the relevant files, you read them, form a theory, make an edit, and run the tests. If they fail, you read the error, adjust, and try again. That workflow is multi-step, it forks based on what you find, and you cannot script it fully in advance because each step depends on the last.

A single model call cannot handle that shape. Prompt in, response out, finished. It never sees whether the tests passed, so it cannot decide what to do next. What the work needs is a system that can set a goal, take an action, look at the result, and choose to continue or stop. That closed loop is the reason agents were built, and it maps almost exactly onto how a human debugs.

How does the agentic loop work?

The core engine is a while loop around a model call, and it runs in five stages that repeat until the task is done. The model touches only two of them. Everything else is ordinary code you write, which is the part most explanations skip.

1 code
Perceive

Gather the goal, history, and prior tool results into one message array.

2 LLM
Reason

The LLM reads the context and works out what is missing.

3 LLM
Plan

It outputs a tool call as JSON, a question, or a "done" signal.

4 code
Act

Your code validates the JSON and runs the tool. The model never executes.

5 code
Observe

Capture the result, append it to the array, and loop back.

LLM proposes (the brain) your code executes (the body)
Fig. 2 The five-stage agentic loop. The model only reasons and plans (yellow). Your orchestration code perceives, executes the tool, and observes (outlined). It loops until the model returns no tool call or a guardrail trips.

Walk through one turn. Perceive gathers the goal, the history, and any prior tool results into a single message array. Reason is the model reading that context and working out what is missing. Plan is the model’s output: a structured tool call as JSON, a request for more information, or a “done” signal. Act hands control back to deterministic code, which validates the JSON against a schema and runs the actual tool, whether that is an API call, a database query, or a shell command. Observe captures the result, appends it to the array, and the loop goes again.

That separation is the whole game. The model proposes; your code disposes. The LLM is the brain that reasons and selects tools, and never executes anything or holds the state variable itself. The orchestration layer is the body: it owns the loop, the tool execution, the retries, and the logging. Keep that line clear and the rest of agent engineering gets a lot simpler.

Knowing when to quit is its own problem, so in production you layer several stops. The model can signal completion by returning a reply with no tool calls. You set a hard cap on iterations so it cannot spin forever. You enforce a token budget, because agents burn far more tokens than a chat. The strongest stop is a goal check: the tests must pass, the linter must be clean. Verification is what keeps an agent honest.

How agents think: ReAct and reasoning patterns

The thinking pattern under almost every agent is ReAct, short for Reason plus Act, introduced by Yao and colleagues in 2022. The agent writes a thought about what it sees, takes an action such as a tool call, observes the result, and uses that to shape the next thought. It is a loop inside the loop, and every major framework ships it as the default.

ReAct is the floor, not the ceiling. Plan-and-Execute has a strong model draft the full plan once, then a cheaper, faster model grind through each step, which can cut latency sharply. Reflexion has the agent write a short self-critique after a failure and feed it into the next attempt; that approach reached 91% on a standard code-generation benchmark. Different shapes, same spirit: structure the reasoning so the model is not winging every step.

Where is agentic AI used in production?

This is not a research demo. Agentic loops ship real revenue today, and the clearest examples are in coding and customer support. Each one is the same loop with different tools bolted on.

Claude Code ~21 tool calls / task

Anthropic’s terminal agent runs one deliberately simple loop, no multi-agent setup. Reportedly ~$2B annualized revenue.

GitHub Copilot issue → draft PR

Assign it a GitHub issue and it analyzes, implements, reviews its own code, and opens a pull request in a sandbox.

Cursor 8 agents in parallel

Each agent works in its own isolated workspace. Hit $100M ARR faster than any software product on record.

Klarna 2.3M chats in month one

Its support assistant did the work of about 700 human agents, then Klarna later rehired for quality.

Fig. 3 Four agentic systems in production. Claude Code keeps the loop deliberately simple; Cursor runs many in parallel; Copilot turns an issue into a pull request; Klarna pointed the loop at support chat.

Claude Code is Anthropic’s terminal coding agent, and it is pointedly boring under the hood: one simple loop, no multi-agent theatrics, averaging about 21 tool calls per task. GitHub Copilot grew from autocomplete into a full agent you can assign a GitHub issue, after which it analyzes the problem, writes a fix, reviews its own code, and opens a draft pull request inside a sandbox. Cursor took the opposite tack and runs up to eight agents in parallel, each in an isolated workspace, and reached $100 million in annual revenue faster than any software product on record. On the support side, Klarna’s assistant handled 2.3 million conversations in its first month, the equivalent of about 700 human agents, though the company later rehired staff after deciding the quality had slipped. That last detail matters: agentic does not automatically mean better.

If you want to build one yourself, the framework choices split by how much control you want. LangGraph models the workflow as an explicit state graph where you define every node and edge. CrewAI is higher level, giving agents roles, goals, and backstories, and it is the quickest way to a prototype. OpenAI’s Agents SDK keeps it minimal with four primitives. They share one thing: every major framework now speaks MCP, the Model Context Protocol. MCP standardizes how tools are discovered and connected; the model still uses function calling to decide which tool to fire. MCP is the plumbing, function calling is the decision.

The trade-offs: error, cost, and security

Now the honest part. The biggest constraint is error compounding. If your agent is 95% accurate at each step, ten steps leaves you near 60% overall, and twenty steps drops you to about 36%. That is just multiplication. Toby Ord’s 2025 analysis of METR’s data put a frontier coding model’s “half-life” at roughly 59 minutes: 50% success at one hour, 25% at two.

Cost is the next wall. Agentic loops run 5 to 30 times the tokens of a single chat reply, and on coding tasks up to 70% of those tokens can be wasted reading files that turn out to be irrelevant. Then there is security, which is the part people underrate. Prompt injection remains unsolved, with research finding 94% of tested state-of-the-art agents vulnerable. The EchoLeak flaw in Microsoft 365 Copilot (CVE-2025-32711) showed a zero-click attack that exfiltrated data with no user action at all, and OWASP now publishes a Top 10 list specifically for agentic applications.

Error compounding 36%

at 95% accuracy per step, success after 20 steps. Reliability multiplies down fast as the chain grows.

Cost 5–30×

more tokens than a single chatbot reply, and up to 70% of them can be wasted reading irrelevant files.

Security 94%

of state-of-the-art agents tested were vulnerable to prompt injection, the top unsolved risk in the field.

Fig. 4 The three sharp edges of an agentic loop: reliability multiplies down across steps, token cost runs many times a single reply, and prompt injection stays unsolved. Plan for all three before you ship.

When should you skip the agent?

Most of the time, honestly. If your problem can be written as a fixed series of steps, use a workflow. If one model call with structured output solves it, do that. An agentic loop is the most powerful option and also the most expensive, the slowest, and the one with the most ways to fail. Reach for it last, not first.

A simple ladder helps. Start at the bottom with a single model call and climb only when the rung below genuinely cannot do the job. The principle, drawn straight from Anthropic’s guidance on building effective agents, is to build as agentic as needed, not as agentic as possible.

L4
Agentic loop

Open-ended, dynamic tool use. Most cost, most failure modes.

only if needed
L3
Fixed workflow

Predefined steps with branches. Predictable and debuggable.

L2
Structured output

One call that returns clean JSON your code acts on.

L1
Single LLM call

A prompt and a reply. Cheapest, fastest, easiest to trust.

start here
Fig. 5 The complexity ladder. Reach for the cheapest tool that works and climb only when forced. Most tasks live at levels 1 to 3, not at the open-ended agentic loop on top.

The bottom line: a loop you can reason about

Strip away the frameworks and agentic AI is a while loop around a model, with tools and memory. The cleanest way to hold it in your head is as a small operating system. The LLM is the CPU. The context window is RAM. Your tools are system calls. And the orchestration code you write is the operating system tying it together.

Orchestration code = the operating system
LLM CPU

Evaluates state, decides the next step.

Context window RAM

Working memory for the current task.

Tools System calls

How it touches files, APIs, the shell.

Fig. 6 The mental model that outlasts any framework: an agent is a tiny operating system. The model computes, the context window remembers, tools reach the outside world, and your code is the OS around all three.

That model carries through every SDK and architecture decision you will face. The loop itself is simple. The hard part is everything around it: managing context, controlling cost, handling failure, and keeping the whole thing secure. The honest view from researchers is that the future may not be more agents but better individual models that need less scaffolding. The loop stays. The machinery around it gets smaller.

Watch the explainer

For the animated version, with the loop, the patterns, and the trade-offs drawn out on screen, watch the full breakdown on YouTube.

Frequently asked questions

What is agentic AI in simple terms?

Agentic AI is a language model wrapped in a loop with tools. Instead of answering once and stopping, it reasons about a goal, takes an action like running code or calling an API, observes the result, and decides whether to keep going. That closed loop is the whole idea.

What is the difference between agentic AI and generative AI?

Generative AI is an open loop: one prompt in, one response out, then the thread ends. Agentic AI is a closed loop that keeps acting and observing until a goal is met. The model is the same; agentic systems add the loop, the tools, and the code that runs them.

Are AI agents and agentic AI the same thing?

Roughly, yes. An AI agent is the running system: the model, the loop, and its tools. Agentic AI is the broader category and the property of being agentic, meaning the software directs its own steps rather than following a fixed script. People use the terms interchangeably in practice.

How does an AI agent actually work?

It runs a five-stage loop: perceive the current state, reason about what is missing, plan the next move, act by running a tool, then observe the result and repeat. The model only reasons and plans. Your code executes the tools and controls when the loop stops.

What are examples of agentic AI?

Coding agents like Claude Code, GitHub Copilot, and Cursor read files, run tests, and open pull requests on their own. Klarna’s support assistant handled 2.3 million chats in its first month. Perplexity runs agentic search, planning and executing dozens of queries before answering.

When should you not use an AI agent?

When the task fits a fixed series of steps. If a single model call with structured output or a deterministic workflow solves it, an agentic loop just adds cost, latency, and new failure modes. The guideline is to build as agentic as needed, not as agentic as possible.

Sources

  1. Anthropic · "Building Effective Agents" (Dec 2024) · retrieved 2026-06-08
  2. Lilian Weng · "LLM Powered Autonomous Agents" (Jun 2023) · retrieved 2026-06-08
  3. Yao et al. · "ReAct: Synergizing Reasoning and Acting in Language Models" (arXiv 2210.03629) · retrieved 2026-06-08
  4. Shinn et al. · "Reflexion: Language Agents with Verbal Reinforcement Learning" (arXiv 2303.11366) · retrieved 2026-06-08
  5. Toby Ord · "Is there a Half-Life for the Success Rates of AI Agents?" (May 2025) · retrieved 2026-06-08
  6. OpenAI · "Klarna’s AI assistant does the work of 700 full-time agents" · retrieved 2026-06-08
  7. The Hacker News · EchoLeak zero-click flaw in Microsoft 365 Copilot (CVE-2025-32711) · retrieved 2026-06-08
  8. OWASP Gen AI Security Project · "Top 10 for Agentic Applications" (Dec 2025) · retrieved 2026-06-08
  9. MarketsandMarkets · "AI Agents Market worth $52.62 billion by 2030" · retrieved 2026-06-08
  10. Contrary Research · Cursor / Anysphere business breakdown · retrieved 2026-06-08
</>

Ricardo de Jong

Creator of Devsplainers

Ricardo de Jong makes Devsplainers, turning complex developer and AI topics into short animated videos and written companions. Each article is built from the same research and script behind the video. No hype, no jargon walls.

The newsletter

Liked this? Get the Take-Outs.

One email every Tuesday: a spicy take on a trending dev topic, video out-takes, and the tool of the week. Free.

Subscribe
<devsplainers>