AI for product managers How agents work
Lesson 2 of 9
Agentic loops.
What makes an AI assistant an agent: the loop it runs, how it stops, when it should ask a person, and when you shouldn’t build one at all.
By Nagesh Koritala, product manager October 2026
- About 15 minutes
- 7 parts
- 6 quick questions
- A worksheet
Before you start
A shopper types into a furniture store’s assistant: “I need a sofa that fits through a 30-inch door and gets here before I move on the 14th.” No single fact on any product page answers that. Before you read on: what does the assistant have to do, in what order, to give her a good answer? Write it in one sentence.
It stays on this device only. You’ll see it again at the end.
In this lesson, you’ll learn to
- Explain what makes an AI system an agent, and how it differs from a workflow
- Walk through the agent loop (plan, act, observe, check) on a real request
- Decide when a simpler design beats an agent
- Set stopping conditions: what counts as done, the step limit, and the budget
- Place human checkpoints where a mistake would cost the most
- Spot how loops fail, and ask the questions that catch it early
Key terms
- Agent
- A system where a model decides its own next steps and which tools to use, in a loop, until a task is done or it is stopped.
- Workflow
- A system where models and tools follow a path set in advance by code.
- Tool
- Something the model can ask your system to do, like search the catalog, with the result sent back. Lesson 3 covers tools.
- Turn
- One trip around the loop: the model asks for a tool call, the tool runs, and the result, called an observation, comes back. The last turn is the answer, with no tool call.
- Stopping condition
- A rule that ends the loop: the task is done, a step limit or budget is reached, or a person is needed.
- Human checkpoint
- A point where the agent pauses for a person to review, approve, or add information.
The idea
In lesson 1, the assistant answered in one pass: it read its context window and wrote an answer. That works for “How deep is the Harbor sofa?” It doesn’t work for “Find me a sofa that fits my door and arrives before I move.” That job takes several steps, and each depends on what the last one found.
This lesson is about the loop that handles jobs like that: what an agent does on each turn, how it knows when to stop, and where a person should step in. You’ll also see why the best agent is sometimes no agent at all. The example is the same made-up online furniture store and its shopping assistant.
The lesson, in seven parts
What an agent is, and what it isn’t.
“Agent” gets used for almost anything with AI in it. So start with a precise line. In their December 2024 guide, Anthropic engineers Erik Schluntz and Barry Zhang group all of these systems under “agentic systems”, then split them in two. Workflows are “systems where LLMs and tools are orchestrated through predefined code paths.” Agents are “systems where LLMs dynamically direct their own processes and tool usage, maintaining control over how they accomplish tasks.”
The difference is who picks the next step. In a workflow, your team wrote the path: check stock, then delivery, then answer. In an agent, the model looks at what it has so far and chooses. It might search again, or try something you didn’t plan for.
The same guide says agents are “typically just LLMs using tools based on environmental feedback in a loop.” A model, some tools, and a loop. What makes it useful, or risky, is how your team designs each one.
Same tools, different driver. In a workflow, your code sets the order. In an agent, the model picks each next step. Neither is better in general. A workflow is predictable: you can test every path, because you wrote every path. An agent is flexible: it can handle requests you didn’t predict, and it gives up some of that predictability. Part 3 helps you choose.
The loop, one turn at a time.
Here’s the loop in plain steps. The agent plans what to do next. It acts, usually by calling a tool. It observes what came back. Then it checks: on track, done, or time to change the plan? Then round again.
Sources name the steps differently. The ReAct paper (Yao and colleagues at Princeton University and Google Research, 2022) has a model write a reasoning step, take an action, and read an observation, over and over. Anthropic’s Agent SDK documentation describes a model that calls tools, receives the results, and repeats until the task is complete; each round trip is one turn, and the loop ends when the model replies with no tool call. The shape is the same: think, do, look, decide.
Watch it work on the shopper’s request at the made-up store:
Each result narrows the choice. The agent decides the next step from what it just saw, not from what it assumed. Turn What it plans What it does What it observes 1 Find sofas that match her request Searches the catalog 12 sofas in stock 2 Drop the ones that won’t fit her door Runs the doorway-size check 4 fit a 30-inch door. The Harbor doesn’t; the two-piece Harbor Modular does. 3 Drop the ones that arrive too late Runs the delivery date check 2 arrive before the 14th. One check returned an error, so it ran that check again (one more trip around the loop). 4 It has enough, so answer Writes the answer, no tool call Done: 2 options, each size and date from a tool result Made-up example. The store, the sofas, the counts, and the dates are invented for this lesson.
Look at turn 3. An error came back, and the agent tried again instead of guessing a date. Schluntz and Zhang say it’s crucial for agents to gain “ground truth” from the environment at each step, such as tool results, to assess their progress. In the ReAct paper, giving the model a simple Wikipedia search tool led to fewer made-up facts than having it reason step by step with no way to look things up.
When not to use an agent.
This decision comes first. Schluntz and Zhang recommend “finding the simplest solution possible, and only increasing complexity when needed. This might mean not building agentic systems at all.” The reason is a trade: agentic systems often trade latency and cost for better task performance. Every extra turn is another model call, another wait, and another chance to go wrong.
Workflows, they write, offer predictability and consistency for well-defined tasks. Agents fit open-ended problems where it’s hard or impossible to predict the number of steps. And for many applications, a single model call with retrieval and good examples is usually enough.
Here’s how that plays out across jobs at the made-up store:
The shopper’s job Steps known in advance? A good fit “How deep is the Harbor sofa?” Yes: one lookup One grounded model call (lesson 1) “Where’s my order?” Yes: find it, check status, answer A workflow “I want to return this chair.” Mostly: the same policy checks A workflow, with a person approving refunds “A sofa that fits my door and arrives by the 14th.” No: depends on what each check finds An agent, with a step limit and a checkpoint before buying Made-up examples.
Ask
- Can we write the steps down in advance? If yes, start with a workflow.
- Would one grounded answer do the job? Then skip the loop.
- What do we gain from flexibility, and is it worth the extra cost and wait?
Avoid
- “Agents are the future, so let’s build one.” (Start with the job, not the trend.)
- “It handled the demo request.” (A demo is one path. Agents take many.)
A good habit: build the simplest version first, test it on real requests, and add a loop only where it keeps failing. In Schluntz and Zhang’s words, add complexity “only when it demonstrably improves outcomes.”
How a loop stops.
A loop needs a way out. Schluntz and Zhang note that the task often ends on completion, but it’s common to add stopping conditions, such as a maximum number of iterations, to keep control. Anthropic’s Agent SDK offers a cap on turns and a cap on spend, and by default neither is set. Its documentation warns that without limits the loop “can run long on open-ended prompts,” and calls setting a budget “a good default for production agents.”
So there are four ways out, and each is a product decision:
Way out What you decide At the made-up store Done What counts as finished, in words you can test A sofa that fits a 30-inch door and arrives by the move date, or a clear “none do” Step limit The most turns a request may take After that, it stops and says what it found Budget The most one request may cost A cap per conversation, set with engineering and finance Needs a person When it must stop and ask Before buying anything, or when the door size is unclear Made-up example. Pick real limits by looking at how many turns successful requests actually take.
Don’t forget what the shopper sees when the loop stops early. “Something went wrong” throws away the work. A better stop says what it found and what’s left: “I found two sofas that fit your door, but couldn’t confirm their delivery dates yet. Try again, or talk to someone?” Write that message as carefully as the happy path, and ask engineers how often early stops happen.
Memory and feedback inside the loop.
How does the agent remember turn 1 by turn 3? Through the context window from lesson 1. Anthropic’s Agent SDK documentation says the context window doesn’t reset between turns: everything accumulates, including tool inputs and outputs. Near the limit, the SDK summarizes older history to free space.
You’ll feel two effects. Long runs cost more, because each turn carries everything before it (caching softens this, which lesson 8 covers). And they can get worse, because a crowded window is harder to use well (the “context rot” from lesson 1). So ask what each tool sends back. A delivery check that returns “arrives June 10” is kinder to the loop than one that returns a whole shipping record.
The other half is feedback. In a September 2025 article, Anthropic’s Thariq Shihipar describes the loop as gather context, take action, verify work, repeat, and says agents that check their own output “catch mistakes before they compound.” He calls clearly defined rules, with an explanation of which rule failed and why, “the best form of feedback.”
- A weak signal: “Error.” The agent has to guess what went wrong.
- A strong signal: “The Harbor’s diagonal depth is 34 inches; the door is 30. It won’t fit.” Now it knows why, and can look for a two-piece sofa.
Research goes further. In Reflexion (Shinn and colleagues at Northeastern University, MIT, and Princeton University, 2023), an agent writes a short reflection on what went wrong, keeps it in memory, and uses it on its next attempt, without retraining the model. The authors usually kept just one to three past reflections, to fit the context window.
Human checkpoints, and how much autonomy to give.
Schluntz and Zhang describe agents that pause for human feedback at checkpoints, or when they hit blockers. Where those pauses go is one of your biggest calls. Too few, and the agent does something costly no one approved. Too many, and the shopper clicks “OK” every few seconds. At that point, it’s a slower web form.
A useful frame: in a 2025 paper, K. J. Kevin Feng, David W. McDonald, and Amy X. Zhang at the University of Washington argue that an agent’s level of autonomy can be a deliberate design decision, separate from what it’s capable of. They describe five levels by the role the user plays:
A practical rule of thumb, not research: the more a mistake costs, and the harder it is to undo, the sooner the agent should stop and ask. Made-up store actions. Level The user’s role What that means 1 Operator The user leads; the agent helps when asked 2 Collaborator Both plan and do the work; the user can edit the agent’s plan 3 Consultant The agent leads; the user gives feedback and direction 4 Approver The agent asks only at blockers, such as signing off on consequential actions 5 Observer The agent decides everything; the user can watch logs and has an emergency off switch Summarized from Feng, McDonald, and Zhang, “Levels of Autonomy for AI Agents” (2025).
Engineering gives you the controls: Anthropic’s Agent SDK, for example, lets a team auto-approve some tools, block others, or require approval for everything. Your job is to say which actions sit where. At the made-up store, placing the order waits for the shopper’s yes, every time. After a good demo, it’s tempting to relax that. Don’t, until your evals and logs (lessons 5 and 7) show it’s safe.
How loops go wrong.
A single answer is wrong once. A loop can be wrong in a way that grows. Schluntz and Zhang name the two big costs: the autonomous nature of agents means higher costs, and the potential for compounding errors. They recommend extensive testing in sandboxed environments, with the appropriate guardrails.
Here are the failures to watch for, at the made-up store:
Failure What it looks like What helps Wandering or repeating The same search again and again, or a drift into coffee tables A step limit, a clear “done”, and turn-by-turn logs (lesson 7) Compounding errors Turn 2 misreads the door as 36 inches, and every later step builds on it Checks against rules at each step; clear tool errors Bad results in, bad plan out The search returns nothing useful, and it never recovers Better tools and data (lesson 3); a graceful stop Cost per run A hard request takes many more turns than an easy one A budget per request; cost tracked per run (lesson 8) Made-up examples. The failure types are general.
Two of these show up in the research. The ReAct authors report a frequent error where the model repeats its previous thoughts and actions and fails to jump out of the loop. They also found that searches returning nothing useful derailed the model and made it hard to recover. Plan for both before launch. Questions to ask your engineers:
- “What’s the most turns a successful request took in testing, and what’s our limit?”
- “Can I see a failed run, turn by turn?”
- “What does one run cost on an easy request, and on a hard one?”
- “Which actions can it take without the shopper’s yes?”
With AI: Use an AI assistant to stress-test your loop design. Paste in your worksheet and ask it to play a difficult shopper: vague, changing their mind, missing key facts. Note every place your design has no answer, and check any claim it makes about agents against the sources below.
Check your understanding
Answer each one in your head or on paper first. Then open the answer to check.
1What’s the difference between a workflow and an agent?
In a workflow, models and tools follow a path set in advance in code. In an agent, the model decides its own next steps and tools, based on what it has found so far.
2Name the four steps of the agent loop used in this lesson.
Plan the next step, act (usually by calling a tool), observe the result, and check whether it’s on track or done. Then repeat.
3Why does an agent need “ground truth” from the environment at each step?
So it picks the next step from real results, like a tool’s output or an error, not from assumptions. That lets it catch problems and change its plan.
4The store wants an assistant that answers “Where’s my order?” Agent or workflow? Why?
Usually a workflow. The steps are known in advance (find the order, check its status, answer), so a fixed path is more predictable, cheaper, and easier to test.
5What are the four ways a loop can end, and which should you design the message for most carefully?
Done, a step limit, a budget limit, or needing a person. The early stops need the most care: say what was found, what’s left, and what happens next.
6Where should a human checkpoint go at the furniture store?
Before actions that spend money or can’t be undone, like placing an order, and when a fact only the shopper knows is missing, like her door width.
Practice: design the loop for one agent feature
The made-up furniture store wants its assistant to help shoppers plan a living room: a sofa, a rug, and a coffee table that fit the room and arrive together. Using the worksheet below, write a short loop design that covers:
- Whether this job needs an agent, a workflow, or a single call, and why.
- The tools the agent can use, and what each one returns.
- What counts as done, in words you could test.
- The step limit, the budget, and what the shopper sees if it stops early.
- Which actions run freely, which run and then show the shopper, and which wait for a yes.
Show a model answer
Fit: an agent, because the steps depend on what each check finds (the sofa you pick changes which rugs work). Tools: catalog search (matching pieces with sizes and prices), room planner (whether a set fits the room), doorway-size check (fits or not, with the tightest measurement), and delivery date check (the earliest date for each piece), each returning an error with the reason when it can’t answer. Done: a sofa, rug, and table that fit the room and the door and arrive in the same week, or a clear note on what can’t be met. Limits: a step limit based on successful test runs, and a budget per conversation agreed with engineering. Early stop: “Here’s what I found, and the one piece I couldn’t match. Keep looking, or widen the delivery week?” Free: searching, checking sizes and dates. Act, then show: saving the room plan and the shortlist. Wait for a yes: adding to the cart (one tap), placing the order, booking delivery. Ask first: the room size or door width, if missing. (Made-up example.)
Back to where you started
You wrote
The short answer
An agent is a model working in a loop: it plans a step, uses a tool, looks at the real result, and decides what to do next, until the job is done or something stops it. A workflow follows a path your team wrote in advance. You decide whether a job needs an agent at all, what counts as done, when it must stop, and when it must ask a person.
Go back to your sentence. If you wrote a list of steps, like “find sofas, check which fit the door, check which arrive in time, then answer”, you described an agent’s loop. Now you know what makes it work: real results at each step, a clear “done”, limits that stop it, and a person asked at the moments that matter.
Common mistakes
New product managers on agent features often:
- Build an agent for a job a workflow or a single call would do better.
- Ship without a step limit or a budget, because the demo always finished.
- Leave “done” undefined, so the agent decides when it’s finished.
- Put the human checkpoint everywhere, or nowhere, instead of where a mistake costs the most.
- Write a great happy path and a useless “Something went wrong” when the loop stops early.
Try this today
Find an AI assistant that can use tools, such as one that searches the web, and run three small experiments:
- Give it a task with two conditions, like “a recipe under 30 minutes with no dairy.” Watch the steps it shows, and count them.
- Give it a task with a missing fact it can’t look up. Does it ask you, or guess?
- Pick a product that calls itself an agent. Note one action it takes without asking you, and one where it asks first. Would you move either?
Worksheet: agent loop design
AGENT LOOP DESIGN The shopper's job (in their words): Agent, workflow, or single call? Why: Tools it can use, and what each returns: - Tool: Returns: On error, says: - Tool: Returns: On error, says: Done means (testable): Stopping conditions: - Step limit: (based on:) - Budget per request: - Other stops: When it stops early, the shopper sees: Actions and autonomy: - Runs freely: - Acts, then shows the shopper: - Waits for a yes: Facts only the shopper knows (ask, don't guess): How we'll review runs (logs, turn by turn): Open questions for engineering:
Questions people ask
What is an AI agent?
A system where a language model decides its own next steps and which tools to use, in a loop, until a task is done or it is stopped. Anthropic’s guide describes agents as typically just LLMs using tools based on environmental feedback in a loop.
What is the difference between an AI agent and a workflow?
In a workflow, models and tools follow a path set in advance by code. In an agent, the model directs its own process and tool use. Workflows suit well-defined tasks; agents suit open-ended ones where you can’t predict the steps.
What is the ReAct pattern?
ReAct, from a 2022 paper by Shunyu Yao and colleagues, has a language model alternate reasoning steps with actions, such as searches, and read the observations that come back. Reasoning helps it plan; actions let it gather real information.
When should you not use an AI agent?
When the steps are known in advance, a workflow is usually more predictable and easier to test. When one grounded answer is enough, a single model call is cheaper and faster. Anthropic recommends starting with the simplest solution and adding complexity only when it improves results.
How do you stop an AI agent from running forever?
Set stopping conditions: a clear definition of done, a maximum number of turns, and a budget per run. Anthropic’s Agent SDK, for example, sets no turn or budget limit by default, and its documentation calls a budget a good default for production agents.
Sources and further reading
- Erik Schluntz and Barry Zhang, “Building effective agents”, Anthropic (December 2024) (opens in a new tab)
- Anthropic, How the agent loop works (Agent SDK documentation: turns, limits, context, permissions) (opens in a new tab)
- Thariq Shihipar, “Building agents with the Claude Agent SDK”, Anthropic (September 2025) (opens in a new tab)
- Yao and colleagues, “ReAct”, on interleaving reasoning and acting in language models (2022) (opens in a new tab)
- Shinn and colleagues, “Reflexion: Language Agents with Verbal Reinforcement Learning” (2023) (opens in a new tab)
- Feng, McDonald, and Zhang, “Levels of Autonomy for AI Agents” (2025) (opens in a new tab)