# How Do Agents Plan?

> How an AI agent writes a list of steps, checks each result and rewrites the list when something breaks, with the limits to name, explained for your AI interview.

**In short:** An agent plans by writing a list of steps, doing one, reading the result and changing the list when something goes wrong. Some agents write the whole plan first, and others plan step by step. The plan is only text, so code has to cap and check it.

AI and LLM interview question Q162, Agents and tool use. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-do-agents-plan

## Say it in 30 seconds

An agent plans by writing a list of steps for the task. Then it does one step, reads what came back, and changes the list if something went wrong. Some agents write the whole plan first, and others plan as they go. The catch is that a plan is just generated text, so it can miss a step or break. That is why I cap the steps in code and send risky steps to a person.

## Say it in 2 minutes

Planning in an agent means the model writes down the steps it expects to take before it takes them. The plan lives as text. Anthropic describes its agents as AI models, called LLMs (large language models), that dynamically direct their own processes and tool usage.

There are two common styles. Plan first writes the whole list up front and runs it in order. That is predictable but stiff. Plan as you go has the model choose one step, act, read the result and then choose the next. ReAct, a 2022 paper, mixes reasoning and acting this way.

When a step fails, a good agent reads the error and rewrites the rest of the list instead of pushing on. A sensible setup also caps the steps in code and sends risky actions, such as payments or sent mail, to a person. Anthropic's research system splits the work this way: a lead agent, the main agent that hands out the work, plans it and gives parts to sub-agents.

The honest limit is that a plan is generated text, so it can be wrong, and errors compound over many steps. Say that plainly in the interview, then name the three controls you would add.

## What does it mean for an agent to plan, in plain words?

A plan is a list of steps the agent means to take, written as text before or during the job. An AI agent is an AI app that uses tools, such as reading files or running tests, to finish a task. Planning is how it works out the next steps and what to do when one fails.

Picture a new claims handler at an insurance firm. She writes a checklist for each claim (check the policy, check for fraud flags, draft the letter), ticks items off, and adds a step when the policy number is missing. An AI claims agent does the same. The one change is that the model writes the list, so your code has to check it.

- **Plan:** A list of steps the agent intends to take, kept as text.
- **Replan:** Rewriting the rest of the list after a step gives a surprising result.
- **Stopping condition:** A rule in code that ends the loop, such as a maximum number of steps.
- **Sub-agent:** A smaller agent given one subtask by a lead agent.

## Should an agent plan first, or plan as it goes?

Real agents often mix both styles. Plan first suits fixed steps, like a set onboarding process. Plan as you go suits work where each result changes the next step, like fixing a failing build.

- **Plan first: Write the list, then run it.** Set at the start and run in order. Easy to review, but stiff when a step surprises it.
- **Plan as you go: Decide one step at a time.** The model picks the next move from the last result. It adapts well, but costs more, because the AI is asked again for each move, and it can wander off course.

*Diagram, Two ways to plan the same job: Two ways to plan the same job. Plan first writes every step up front. Plan as you go picks each step after the last result, which adapts but costs more.*
1. Write the full list first, then run it.
2. Decide one step at a time, from each result.
3. Once the list is set, surprises go unhandled.
4. Each result can change the next step.

ReAct, a 2022 paper, mixes reasoning and acting, so each result updates the plan. Its paper says reasoning traces "help the model induce, track, and update action plans as well as handle exceptions".

Plan-and-Solve, a 2023 prompting method, was built to address missing-step errors. Its paper says the method starts by "devising a plan to divide the entire task into smaller subtasks". Tree of Thoughts, also from 2023, goes further and considers "multiple different reasoning paths".

## How does an agent change its plan when a step fails?

A plan only helps if the agent reads what each step really returned. Anthropic says agents need real feedback at each step, such as tool results or code execution.

Here is a made-up case from CI, the server that runs the tests on every change.

1. **The plan is written:** A coding agent in CI is asked to move 40 services to version 3 of a payments library. Its plan: update the library, run the tests, then open one pull request per service (a proposed code change that a person reviews before it merges).
2. **The tests fail in six services:** Version 3 renamed a retry option, so six services break. The agent reads the real test output and does not push on.
3. **The plan changes:** The agent rewrites the rest of its list: fix the renamed option in the shared wrapper, then rerun the tests in those six services.
4. **A person approves the last step:** Opening pull requests hands the work to people for review, so the plan marks that step for a person. Code also stops the run after eight steps, whatever the model writes.

*Diagram, The loop during a job: The loop during a job. The model writes a step, the step runs, and the result is checked. A failed check sends the plan back for a fix.*
1. The model hands over the next step.
2. The output of that step is read.
3. When every step has passed, the job ends.
4. A failed check, or steps still left, goes back to the model.

Anthropic notes that agents commonly include stopping conditions, such as a maximum number of iterations. The code below shows the same idea in plain Python.

No real model is used, so the tests are pretend. The marked lines are the controls that matter.

```python
# A simplified upgrade agent. No real model: the plan is a list we wrote, and the tests are pretend.
MAX_STEPS = 8  # code stops the loop, whatever the model writes
RISKY = "open pull requests"
plan = ["update library", "run tests", RISKY]
fixed = False
steps_taken = 0

def run(step):
    # Pretend the tests fail until the agent adds a fix for the renamed option.
    if step == "run tests" and not fixed:
        return "FAILED: renamed retry option"
    return "ok"

while plan and steps_taken < MAX_STEPS:
    step = plan.pop(0)
    steps_taken += 1
    if step == RISKY:
        print("WAITING: a person must approve:", step)
        break
    result = run(step)
    print(step, "->", result)
    if result != "ok":
        fixed = True  # replan: add a fix, then run the tests again
        plan = ["fix renamed option", "run tests"] + plan
print("steps used:", steps_taken)
```

Output:

```text
update library -> ok
run tests -> FAILED: renamed retry option
fix renamed option -> ok
run tests -> ok
WAITING: a person must approve: open pull requests
steps used: 5
```

## What can go wrong with an agent's plan?

A plan is generated text. The model can skip a step, pick a tool that does not exist, or stop early and say it has finished. Errors also compound: one wrong step leaves every later step planned from a false picture.

> "The autonomous nature of agents means higher costs, and the potential for compounding errors." (Anthropic)
>
> "LLM agents are not yet great at coordinating and delegating to other agents in real time." (Anthropic, June 2025)
>
> "Prioritize transparency by explicitly showing the agent's planning steps." (Anthropic)

So add three controls. Show the plan to the user so they can see it. Cap the steps in code. Send any risky step, like a payment or a sent email, to a person first.

> **Tip:** In the interview, say the model proposes the plan and the code decides what runs. A plan is a suggestion, and the code is the boss.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plan is a list of steps the model writes, kept as text.
- [ ] Two styles: plan first, or plan as you go, and when each fits.
- [ ] Replanning: the agent reads each result and rewrites the rest.
- [ ] Splitting big work into subtasks, with sub-agents when needed.
- [ ] Limits: generated text, compounding errors, no guaranteed plan.
- [ ] Controls in code: a step cap, a visible plan, approval for risky steps.

**Common traps**

- Trap: "The model plans, so it will always finish the job." Better: A plan is a guess that can be wrong. Code caps the steps and checks each result.
- Trap: "Chain of thought is the same thing as planning." Better: Chain of thought is reasoning on the page. A plan is steps the agent acts on, then revises.
- Trap: "A longer prompt with the steps is enough." Better: A written plan helps, but only code can enforce the stops and the approvals.

## Can you spot the planning problem?

**Spot the risk:** An agent wrote this plan for a bank's card-dispute bot. Which step should not run without a person?

A. 1. Read the dispute and the card's transaction history.
B. 2. Check the merchant's name against the dispute reason.
C. 3. Draft the reply for the customer to read.
D. 4. Send a refund of 412 pounds to the card on file.

**Answer:** D. A refund moves money out of the bank, so a person must approve it and code should block it until they do. The first three steps only read or write text.

**Quick check:** An agent's plan keeps looping on a missing document, with no end in sight. What is the best fix?

A. A longer system prompt that says stop looping
B. Code caps the steps and hands the case to a person after a repeat
C. A bigger model
D. Turning up the model's randomness setting

**Answer:** B. A prompt is only a request. Code can enforce the cap and hand the case to a person, so the loop ends whatever the model does.

## Can you answer these from memory?

**Flash cards**

- **What is a plan, for an agent?** A list of steps the agent intends to take, kept as text and revised as results come in.
- **Plan first vs plan as you go?** Plan first writes all steps up front. Plan as you go picks each step after the last result.
- **What is replanning?** Rewriting the rest of the list after a step gives a surprising result.
- **What is ReAct?** A 2022 paper: mix reasoning and acting, so each result updates the plan.
- **Why cap the steps in code?** So a confused agent stops, whatever the model writes. A prompt alone cannot promise that.
- **Biggest limit of a plan?** It is generated text, so errors compound. Keep a person before risky steps.

## Likely follow-up questions

- Q158 Workflow vs agent? https://designervenkat.online/interview/ai/workflow-vs-agent
- Q160 What is the agent loop? https://designervenkat.online/interview/ai/what-is-the-agent-loop
- Q161 What is ReAct for agents? https://designervenkat.online/interview/ai/what-is-react-for-agents
- Q163 Short-term vs long-term agent memory? https://designervenkat.online/interview/ai/short-term-vs-long-term-agent-memory
- Q169 When is a multi-agent system worth it? https://designervenkat.online/interview/ai/when-is-a-multi-agent-system-worth-it
- Q173 How do you stop endless agent loops? https://designervenkat.online/interview/ai/how-do-you-stop-endless-agent-loops

## Learn it in depth

- [ReAct](https://designervenkat.online/learn/ai-engineering/react)
