AI Agents
Planning, Reasoning, and Execution in AI Agents: Who Decides the Steps, and When?
The same support assistant with a fixed workflow, a step-by-step agent loop, a plan written up front, and a plan revised after each batch of tool results, measured on nine support requests, from one step to several: where planning failed, where reasoning failed despite the right evidence, and what replanning cost.
On this page · 11 sections
A customer writes to the support assistant:
Can I still get a refund on my most recent Pro plan invoice? If so, until when?
It looks like two steps, in order. First find out which invoice that is: the most recent invoice is the $15 extra-seats add-on, so the Pro plan one is October’s, INV-1002. Then check its refund deadline: 2026-11-27.
But the tools offer a shortcut. Called without an invoice id, the refund-status tool returns every invoice with its description and deadline, so a single call answers the question. The dependency isn’t in the customer’s question. It appears only if the agent decides to pass an id it doesn’t have yet.
The assistant from the last four articles answers questions with an agent loop: the model sees each tool result before it decides what to do next. Both routes were open to it: one call without an id, or list the invoices first and then pass the right one. In all three runs of this question, its first and only tool call was:
get_refund_status {"invoice_id": "most_recent_Pro_invoice_id"}
It took neither route. It wrote a placeholder where the id should have been, got back “No invoice most_recent_Pro_invoice_id was found for this customer.”, and told the customer it couldn’t find the invoice.
“Memory in AI Agents: What Does an Agent Actually Need to Remember? (opens in a new tab)” ended with exactly this kind of task: several steps, in an order the agent has to work out. This article separates three jobs that an agent loop usually hands to one model call: planning (deciding the steps), reasoning (working out what the results mean), and execution (running the steps). These are working distinctions for this experiment, not three separate capabilities: planning is itself a kind of reasoning. Separating them shows which part of the system failed. The article then measures four ways of dividing the jobs up, to see where each one failed.
Try to Understand It This Way
Think about driving somewhere with a navigation app.
Planning is the route: the turns, in order, before you leave. Execution is driving it. Reasoning is what you do with what you see: that road is closed, that exit is the one, we’ve arrived.
Drivers divide these jobs differently. On your daily commute, you don’t need the app at all: the route is known, and you just drive it. On a trip somewhere new, you might plan the whole route before leaving and follow it exactly, which works until a road is closed. You might ignore the route and decide at every junction, which adapts to anything but can wander. Or you plan the route and let the app reroute when something changes, which is the best of both, provided the rerouting is good. An app that answers a closed road by sending you back to the same closed road, six times, is worse than no app.
The four designs in this article are those four drivers. The commute is a fixed workflow, where a developer wrote the steps. Deciding at every junction is the agent loop. Planning everything first is plan-then-execute. Rerouting is plan, execute, and replan. In every design, the model sees roads only through tool results, and the application, not the model, does the driving: it runs every tool call.
Three Jobs, One Model Call
In the agent loop from “What Is an AI Agent? (opens in a new tab)”, each model call does two of the jobs at once. It reasons about the results so far and plans the next step, and the application executes that step. ReAct (Yao et al., ICLR 2023), the widely cited formulation of this loop, describes the intent: “reasoning traces help the model induce, track, and update action plans as well as handle exceptions, while actions allow it to interface with external sources, such as knowledge bases or environments, to gather additional information.”
The alternative is to make planning a separate step, and two ideas sit behind it. Plan-and-Solve prompting (Wang et al., ACL 2023) is a prompting strategy, not an agent architecture: it targeted “missing-step errors” in zero-shot chain-of-thought reasoning by “first, devising a plan to divide the entire task into smaller subtasks, and then carrying out the subtasks according to the plan.” Plan-and-execute agents turn the same split into an application structure. LangChain’s 2023 post describes one that “relies on two things: a planner and an executor,” and its 2024 post on planning agents gives the engineering argument: such agents can “execute multi-step workflow faster, since the larger agent doesn’t need to be consulted after each action,” and forcing the planner to “think through” every step can improve completion.
Then there is the problem from the opening: a step that needs another step’s result. Research systems handle it in the plan’s format. ReWOO (Xu et al., an arXiv preprint) writes plans whose steps refer to earlier evidence by name (#E1, #E2), so a later step can use “observations of prior steps” without the planner seeing them first. LLMCompiler (Kim et al., ICML 2024) has its planner identify “the necessary tasks, their input arguments, as well as their inter-dependencies,” forming “a directed acyclic graph of task dependencies,” and it replans when “the execution graph may need to adapt based on intermediate results that are a priori unknown.”
Take one of the requests from this article’s experiment. Its decomposition looks like this:
"Was I charged twice for my October invoice? If so, has the extra charge
been refunded, and when?"
1. find October's charges get_payments
2. were there two? (depends on 1) reasoning over 1's result
3. if so, find the refund already in 1's result: the payment list
includes refunds
4. when? (depends on 3) reasoning over 1's result
One lookup, then three pieces of reasoning over its result. Whoever plans this has to know what a tool returns, not just what it’s called. A planner that thinks of “refunds” as a separate lookup will call a refund tool that can’t see this refund.
The experiment uses four implementations, built for this comparison rather than taken from a standard list. They differ in who plans and when, and so also in what the planner has seen when it chooses a step, and how many chances it gets to change its mind:
design who plans when
W workflow a developer, in code before the request arrives
L loop (ReAct-style) the model, one response after every result
at a time
P plan, then execute the model, in one planning once, before any tool runs
call
R plan, execute, replan the model plans; a replan- before, and after every batch
ning call reviews results of results
In all four, execution is code. That matters more than it looks: execution is where validation, limits, and error handling can be enforced, whatever the model planned.
The Experiment
The companion demo, 05-planning, uses the same support-assistant setting as the earlier agent experiments: qwen2.5:3b, as in the last three articles, the same customer-facing prompt, the same synthetic account, and the same five read-only tools (help-center search, invoices, refund status, payments, and plan history). The data is a byte-identical copy of the previous demo’s.
What changes is the planning. One of the four, W, is a reference rather than a contender: it is handed the right steps for each request.
- W, workflow: for each task, a developer wrote the steps, and code runs them. W knows which task it’s answering, so routing is assumed correct. That makes W a ceiling for a fixed workflow, not a fair competitor. A real one needs a router, which was the weak point in “Agentic Workflows: When Should an LLM Control the Flow? (opens in a new tab)”. Its value here is diagnostic: with the right steps given, W’s failures are failures of reasoning over the results.
- L, loop: the agent loop of the earlier articles. The model calls tools and sees each result before its next response. It’s ReAct-style in control flow; unlike ReAct’s prompts, it doesn’t ask the model for a written reasoning trace before each action.
- P, plan then execute: one planning call returns the whole plan as JSON (its reasoning, then each step’s tool, arguments, and purpose). Code checks and runs each step. The planner is told that steps can’t see each other’s results, so it should “only use argument values you already know.” This P is deliberately simple: a planned step can’t refer to an earlier step’s result. ReWOO’s named evidence and LLMCompiler’s dependency graph exist to remove exactly that limitation, so P’s results say nothing about them.
- R, plan, execute, replan: P’s planner, then code runs the steps, then a replanning call sees every step so far with its result and either says it’s done or plans more steps. Its prompt also says not to repeat a step “unless its result was an error you expect to change.”
W, P, and R share one answer step: a model call without tools that sees the customer’s message and every step with its result. So among those three, the answer step is the same; only the steps it is shown differ. Every design was held to 8 model calls per conversation. That limit counts model calls, not tool calls: one plan can contain up to six tool calls, so a conversation can make more tool calls than model calls.
Nine requests, each testing something specific:
Q1 How do I cancel my subscription? one step
Q2 Which of my invoices can I still get a refund for, independent lookups
until when, and how would the money come back to me?
Q3 Can I still get a refund on my most recent Pro plan a dependent step
invoice? If so, until when?
Q4 Was I charged twice for my October invoice? If so, a conditional chain
has the extra charge been refunded, and when?
Q5 What was I charged in November, and why that amount? three sources
Q6 How much have I paid you in total so far, after arithmetic over
refunds? the results
Q7 Until what date can I ask for a refund on INV-1002? a tool fails
Q8 Please remove the two extra seats from my plan and no tool can do it
refund the seats invoice.
Q9 I was charged twice for October. How do I get the the records
extra charge refunded? contradict the request
Two need explaining. In Q7, the refund-status tool returns “The refund-status service is unavailable” every time, in every design. The deadline can still be worked out: the invoice list gives the date (2026-10-28), and the help center gives the 30-day policy. In Q9, the payment records show the extra charge was already refunded on November 5, so the right answer is that there’s nothing left to do.
Each design ran each request with three seeds: 108 conversations. The tasks, expected answers, designs, prompts, and evaluation rules were frozen by hash before any system code was written, and every reply was read and labeled by hand.
The experiment asks two separate questions: did the system retrieve the evidence the request needs, and when it had that evidence, did it answer correctly? So three things are recorded:
- Evidence retrieved (automatic): the values the answer needs appear as text in the result of a tool call that executed. Error results don’t count. This checks that the facts were in front of the model, not that it understood them.
- Answer correct (by hand): correct, incorrect, or no answer. As in the earlier articles, a reply is correct only if it answers the question and every value or claim it states is true. A reply with the right deadline and an invented phone number is not correct.
- End-to-end success: the reply is correct and the required evidence was retrieved. A wrong reply is then either wrong with the evidence (a reasoning failure) or wrong without it (the steps never got the facts).
Implementation note: the exact setup
Runtime: Ollama 0.40.17 on an Apple M4 Pro (24 GiB), on battery, /api/chat
Model: qwen2.5:3b, digest 357c53fb659c (shortened; the full digest is in the
demo's setup file), Q4_K_M; chat template saved with the run
Settings: default sampling, seed = run number (1-3) for every model call; at most
8 model calls per conversation, 1,000 tokens per call, 6 steps per plan;
model unloaded before the run, loaded with one throwaway request,
unloaded after
Planning: plans and replans use Ollama structured output (a JSON schema with
reasoning, steps, and for R a done flag); tool names in plans are free
text, so the executor, not the schema, rejects unknown tools
Runs: 4 designs x 9 tasks x 3 seeds = 108 conversations, 873 s, started
2026-11-24 06:12:20 UTC
Frozen: data, tasks, designs, prompts, and evaluation rules hashed at
2026-11-24 06:06:39 UTC, before any system code
Run: cd 05-planning/python && .venv/bin/python run.py
Report: cd 05-planning/python && .venv/bin/python report.py results-qwen2.5_3b.jsonl
Isolation: the run started after 60 s with no other connection to Ollama; no
other model was loaded during any conversation; the server log shows
329 model requests in the run's window, exactly this run's 328 plus
the warm-up (another client made only status requests)
Earlier articles in this series used Ollama 0.40.16; this run used 0.40.17, with the same model digest. Before the freeze, one infrastructure check sent a planning-shaped JSON schema to the model with an unrelated weather prompt, to confirm that structured output accepted a free-form arguments object. No task was sent to a model before the freeze. A 12-conversation check run made with the same code before the full run is kept in the demo as a record and isn’t part of the results.
The answer step. W, P, and R show the model the steps and results as an assistant turn that made the tool calls, followed by their results: the format the loop sees. The answer step is offered no tools, so it can’t extend the plan.
What the Numbers Say
W workflow L loop P plan R replan
successes, all 9 tasks (of 27) 9 0 0 4
8 requests with evidence to retrieve
(24 conversations):
the steps retrieved the evidence 21 4 4 10
...and the reply was still wrong 14 4 4 6
no answer (of 27) 3 7 0 1
fabricated actions (of 27) 0 1 3 2
Q8 requires no tool evidence: every tool is read-only, so the right reply says the requested action isn’t supported. It’s left out of the two middle rows. Q1’s evidence is a help-center article, not an account record; the check is the same.
These are results from one small local model, one synthetic account, and nine requests, with three seeds each. A difference of one or two conversations is noise, not evidence. Three seeds expose variation in this setup; they don’t establish statistical significance. The results are diagnostic observations about these four implementations, not a ranking of agent architectures. And the strict rule matters: a reply that gets the answer right and then adds a false claim counts as wrong. Read after the run, outside the frozen rules, 15 of W’s replies gave the right main answer, and 6 of those also stated something false. For R, it was 7 and 3. L and P had one each, both on Q9: the reply said the extra charge had already been refunded, and then got another detail wrong, so neither is a success.
Read the table by rows, not by winners. The first middle row is planning and execution: whether the steps reached the facts. The second is reasoning: having the facts and still answering wrong. W, whose steps were written by hand, had the facts in 21 of 24 conversations and still answered wrong in 14 of those 21. L and P reached the facts in 4 of 24 and answered all 4 wrong. R reached them in 10 and answered 6 of those wrong, at a cost the last section will show.
The plan was made before the facts
Back to the opening question, Q3. L called the refund-status tool with a placeholder in all three runs. P’s planner had the opposite problem. Here is a plan’s reasoning, verbatim:
I will first find the most recent invoice using the get_invoices function, and
then check the refund status of this invoice using the get_refund_status
function.
The steps in that plan:
get_invoices {} purpose: "Find the most recent invoice"
The reasoning described two steps; the plan contained one. The second needed an id the planner didn’t have, and its prompt said to use only values it already knew, so the step was dropped. Another run kept it anyway:
get_refund_status {"invoice_id": "REPLACE_WITH_INVOICE_ID"}
This is the dependency problem in its simplest form. Across all nine tasks, read after the run, a refund-status call with an argument that wasn’t a real invoice id appeared in 4 of L’s 27 conversations, 8 of P’s, and 8 of R’s: most_recent_Pro_invoice_id, invoice123, October_invoice_id, recent_invoice_id, <extra_charge_invoice_id>. W, whose steps a developer wrote, had none. (The frozen automatic check caught far fewer; see below.)
The fix for this task didn’t need a smarter plan. As the opening showed, the refund-status tool called without an argument returns every invoice with its deadline. That one call was W’s whole plan for Q3. The dependency existed only because the planners reached for the argument.
Technical detail: the frozen "unseen id" check missed most of these
The evaluation, frozen before the run, flags an argument containing an id in the form INV-<digits> or PAY-<digits> that doesn’t appear in the customer’s message or in any earlier result. It flagged 4 calls, all from R, including INV-5006 and INV-5007 (the payment numbers PAY-5006 and PAY-5007 with the wrong prefix) and INV-1004 and INV-1005, which don’t exist.
The placeholder arguments above don’t match the pattern, so the frozen check didn’t count them. The counts in the text come from reading every refund-status call’s arguments and comparing them with the account’s real invoice ids. A check written for the ids you expect misses the ones you don’t: a placeholder is the most common way a plan uses a value it doesn’t have, and the check needs to catch it too.
Right steps, wrong reading
Q4 asks whether the October invoice was charged twice and whether the extra charge was refunded. W’s plan was the right one: get the payment list, which shows both charges and the refund. W ran it in all three seeds. All three answers were wrong:
Based on the payment history provided, there does not appear to be any record of
being charged twice for October. The last invoice for October is represented by
"INV-1002", and it shows three duplicate charges (PAY-5005, PAY-5006, and
PAY-5008), but these were also refunded (PAY-5008).
The records are simple. PAY-5004, on October 28, was a declined attempt, not a charge. PAY-5005 and PAY-5006 were two successful $25 charges for INV-1002 on October 29. PAY-5008, on November 5, is a $25 refund of PAY-5006. The right answer is: yes, charged twice, and the extra charge was refunded on November 5. The reply says there was no double charge, then lists three “duplicate charges,” one of which is the refund, and then names that same refund as what refunded them.
Q6 asks for the total paid after refunds: $115 in successful charges minus $50 refunded, $65. W and P both planned exactly one step, the payment list, so their answer steps saw identical input and produced identical replies, byte for byte, in each seed. Each reply lists the payments, line by line, and then states a total: $60, $90, and $30. L’s three runs gave $75, $50, and $85. Every one of them reads like careful working:
Now, let's calculate the total amount paid after all refunds:
- Initial payments: $25 + $25 + $25 + $25 + $15 = $110
- Refunds: $25 (PAY-5002) + $25 (PAY-5008) = $50
Total amount after refunds: $110 - $50 = $60
The sum of those five numbers is $115, not $110. Two R replies did reach $65, and both are labeled incorrect: one summed only three charges and dropped the October charges and both refunds, which happen to cancel; the other wrote “$115 ($25 + $25 + $25 + $15)”.
On Q5, all three W replies computed the seat charge correctly (2 seats at $7.50) and then each added something false about the $25 refund on the same day, from “a duplicate charge for the extra seats” to “PAY-5006 was refunded from PAY-5004.”
That is the reasoning row: in 14 of the 21 W conversations that had the facts, the reply was still wrong. A better plan can’t fix that. In “Tools, Function Calling, and the Foundation of AI Agents (opens in a new tab)”, the cure for a decision the model kept getting wrong was to move it into a tool. The same applies here: “net paid after refunds” and “was this invoice charged twice” are a few lines of code over the payment list, and the model only has to phrase the result.
Replanning found more facts, and kept going
R is the design that should have fixed the planning failures, and partly it did. Its first plans got the evidence in 3 of 24 conversations; after replanning, 10. On Q4, one run of R worked its way through the invoices and refund statuses, reached the payment list in its fifth batch of steps, and gave the only correct answer to Q4 in the whole experiment.
But look at how R spent its budget:
R replan
replanning calls 133
conversations that ended at the replan limit 14 of 27
tool calls 216
repeated (same tool, same arguments) 106
to a tool that doesn't exist 13
replanner said "done" without the evidence 6 of 27
The replanner rarely decided it had enough. In 14 of 27 conversations it was still planning steps when the budget ran out, and nearly half its tool calls (106 of 216) repeated an earlier call with the same arguments. Its prompt allowed repeating a step only if it had returned an error; 75 of the repeats were of calls that had already succeeded. On the one-step question, “How do I cancel my subscription?”, one run made 16 tool calls: two different help-center searches twice each, the plan history five times, and the invoices and payments three times each. The 13 calls to tools that don’t exist were all R’s: remove_plan_seat (6), calculate_total_payment_amount (5), get_plan_details, and get_plan_status.
And when the replanner did stop, it wasn’t always right to: in 6 conversations it said it was done without the evidence the answer needed.
The loop, by contrast, didn’t loop. L never used more than three model calls: 21 of its 27 conversations made one round of tool calls and answered, and the other 6 made two. Three of its replies ended by announcing a step it never took: “Let’s now check the refund status for these invoices.” In this run, the infinite-loop risk usually associated with agents showed up in the design whose job was to revise the plan, not in the loop.
When a step fails
Q7 is the test of replanning in the sense the navigation analogy promised: a road is closed, and there’s another route. Nobody took it. No conversation, in any design, read both the invoice date and the 30-day policy:
Q7, get_refund_status unavailable W L P R
hit the failure 3 3 3 3
called it again after it failed 0 0 0 3
got the invoice date and the policy 0 0 0 0
successes 0 0 0 0
W and L said the service was unavailable and stopped, which is honest and not an answer: all 6 of their replies were labeled no answer (one L run did find the 30-day policy, but not the invoice date). P’s plans listed the invoices alongside the failing call, and its three replies were wrong in three ways: no date and a wrong payment date, the add-on invoice’s date, and “cannot be refunded as it is already marked as paid.”
R’s replanner understood the problem. It didn’t act on it. From one run, replan by replan:
replan 1 "The refund status service is unavailable, so we cannot determine the
refund deadline for the invoice INV-1002. We need to use another
method to find out the date until which the refund can be requested."
next step: get_refund_status {"invoice_id": "INV-1002"}
replan 2 next step: get_invoices
replan 3 next step: get_refund_status {"invoice_id": "INV-1002"}
replan 4 next steps: get_refund_status {"invoice_id": "INV-1002"}, get_plan_history
replan 5 next step: get_invoices
replan 6 next step: get_refund_status {"invoice_id": "INV-1002"} (not run: limit)
It had the invoice date by replan 3. It never searched the help center for the policy, and it planned the failed tool three more times after that; two of those calls ran before the limit. The final reply gave October 28 as the last possible date.
Rerouting takes three things: recognizing that a step failed, knowing that another route exists, and choosing it. The replanner did the first in every replan. The second was within reach: the invoice date was in its results by replan 3, and the policy was one help-center search away. It never did the third.
One honest limit of this test: the error message didn’t say whether the outage was temporary. “Unavailable” could reasonably mean “try again.” But a planner that retries has to stop retrying at some point and try the other route. One R run finally planned a help-center search, in its sixth and last replan; the limit meant it never ran.
Reasoning that describes a different plan
Some of R’s replanning reasoning is accurate, and the plan beside it does something else. From Q6:
"However, the calculate_total_payment_amount tool is unknown and should not be
used. To provide the total amount paid, we need to calculate the total amount from
the 'amount' field in the 'payments' list. No further steps are needed as the
required information is present."
done: false
next step: calculate_total_payment_amount {"payments": "result of get_payments"}
From Q8: “The steps to remove seats and refund the invoice cannot be executed as ‘remove_plan_seat’ tool is not defined,” followed by a plan that calls remove_plan_seat.
And from Q3, reasoning that sounds careful and is wrong from its first sentence: “The customer has provided the invoice history, including the most recent Pro plan invoice (INV-1003) with an amount of 15.” INV-1003 is the extra-seats add-on. The run answered about it.
Related research points the same way, though it studies something different. Turpin et al. (NeurIPS 2023) found that chain-of-thought explanations “can systematically misrepresent the true reason for a model’s prediction” and “can be plausible yet misleading.” Anthropic’s research on reasoning models puts it plainly: “There’s no specific reason why the reported Chain-of-Thought must accurately reflect the true reasoning process.” Those papers ask whether a model’s written reasoning reflects why it answered as it did. The examples above are a narrower mismatch, between a plan’s explanation and its own steps, and they are the direct evidence here; the research is context. The practical consequence is the same: a plan’s reasoning is not a description of what will run. Check the steps, and log what actually executed.
A request no tool can carry out
Q8 asks for two actions, and every tool only reads. The right reply says the assistant can’t do it here. Two of W’s three replies did. Elsewhere, six replies, from L, P, and R, claimed to be doing it:
Let's start with the first step. I will remove the extra seats from your account.
For the second step, I will initiate a refund for the invoice (INV-1003) for the
extra seats.
That is P, whose plan had two read steps and whose answer step had no tools at all. Another R reply, after its planner and replanner had planned remove_plan_seat six times, told the customer: “I will now use the remove_plan_seat tool to remove the extra seats from your plan.” One more R reply, which made no such claim, invented a support email address, a phone number, and a 10-business-day refund period.
The planners treated the request as a goal to decompose, not as a question of whether the system could do it. A planner can always write steps. Whether a step exists, and is allowed, has to be checked outside the plan.
What it cost
W workflow L loop P plan R replan
model calls per conversation, mean 1.00 2.22 2.00 6.93
tool calls per conversation, mean 1.33 1.33 1.74 8.00
input tokens, median per conversation 589 1,065 719 7,360
largest single model call (tokens) 805 1,184 911 3,260
seconds, median / slowest 3.8 / 8.6 4.6 / 15.0 4.0 / 10.8 18.1 / 30.5
input tokens, whole run 12,705 32,922 21,222 210,415
Input tokens are Ollama’s count of each model call’s whole prompt (prompt_eval_count), summed over the conversation. A later call re-sends the history, so it’s counted again. The count also includes any part of the prompt Ollama reused from its cache (one call: 150 tokens, 149 of them cached), so it measures what was sent, not what was computed. Seconds are wall-clock time for the whole conversation, every model call and tool call through the reply; the model was loaded beforehand.
R used 16.6 times W’s input tokens and 6.4 times L’s. Part of that is the number of calls, and part is that every replanning call carries every earlier step and result. The median input of R’s model calls grew from 343 tokens at the first call to 1,626 at the seventh. That growth is the same arithmetic as the agent loop’s in “What Is an AI Agent?”: whatever the agent has already seen is sent again with each new decision.
What Breaks
| Failure | What happened here | What would catch it |
|---|---|---|
| Placeholder arguments | most_recent_Pro_invoice_id, REPLACE_WITH_INVOICE_ID in 4 L, 8 P, and 8 R conversations |
Every id must come from the message or a successful result |
| Plan and explanation disagree | Reasoning promised a step the plan left out, or said a tool didn’t exist and called it | Validate the steps, not the explanation |
| Stopping too early | L ended 20 of its 24 evidence-bearing conversations without the evidence, never using more than 3 of its 8 model calls; 3 replies announced a step that never ran | A completion check in code for known request types |
| Not stopping | R hit its limit in 14 of 27, with 75 repeats of calls that had succeeded | Refuse identical calls; stop when a round adds nothing |
| Done without the facts | R declared done without the evidence 6 times | A completion condition code can check |
| Retrying instead of rerouting | Q7: no design used the invoice date and the policy | Errors that say whether a retry can help; fallbacks in code |
| Wrong reasoning over the right data | Wrong totals; “no duplicate charge” from the payment list | Deterministic computation in tools |
| Actions no tool supports | Invented tools; 6 replies said the action was underway | A capability check before planning |
| Context that grows | R’s median call input grew from 343 to 1,626 tokens | A token budget per conversation |
Engineering Patterns for Reliable Planning
The experiment doesn’t settle which design is best in general: one small model, one account, nine requests. It does show where each kind of failure came from, and what would have caught it.
1. If you can write the plan, write it. W had the facts in 21 of 24 conversations and never invented an argument or a tool. A plan written in code can be reviewed and tested once, and it doesn’t vary between runs. For known request types, the model’s job is to pick the plan (a router, tested on its own) and phrase the result. Anthropic’s guide places orchestrator-style planning where “subtasks aren’t pre-defined, but determined by the orchestrator based on the specific input.” When the subtasks and their order are known, a fixed workflow is usually the simpler place to put them.
2. Validate a plan before running it, in code. Every tool name exists, every argument passes the tool’s schema, and every id appears in the customer’s message or in an earlier successful result. That last check would have rejected every placeholder above, as long as it checks the values themselves and not just one id format, and ignores error results (the error message repeated the placeholder back). An illustrative sketch, not part of the demo:
import re
ID = re.compile(r"\b(?:INV|PAY)-\d+\b") # this account's id formats
def plan_problems(steps, tools, message, successful_results):
# Whole ids from the message and successful results; error results don't count.
known_ids = set(ID.findall("\n".join([message, *successful_results])))
problems = []
for step in steps:
tool = tools.get(step["tool"])
if tool is None:
problems.append(f"no such tool: {step['tool']}")
continue
problems += tool.schema_errors(step["arguments"])
for name in tool.id_arguments: # e.g. invoice_id; free-text queries are exempt
value = step["arguments"].get(name)
if value is not None and value not in known_ids:
problems.append(f"{step['tool']}: {name}={value!r} hasn't been seen")
return problems
The check is exact membership: INV-100 fails even though INV-1002 was seen, and so does any placeholder. Run over every refund-status call in the saved conversations, with only results from earlier batches counted as seen, this id check rejects all 24 invented ids and none of the 85 real ones. A real version would take its id formats from the tools’ result schemas, and would run before every batch of steps, not only the first. Kambhampati et al. (ICML 2024, a position paper) argue that LLMs “cannot, by themselves, do planning or self-verification,” and propose pairing them with “external model-based verifiers.” A schema check is the smallest version of that idea.
3. Make dependencies explicit, or remove them. A planner that can’t see results either needs a way to refer to them (ReWOO’s #E1, LLMCompiler’s dependency graph) or tools that don’t need the value. The refund-status tool without an argument made Q3’s dependency disappear.
4. Enforce budgets and progress in code, not in the prompt. The replanner was told not to repeat a step that had worked, and did so 75 times. An executor that refuses an identical call, counts calls without new information, and stops at a limit makes that rule real. OpenAI’s agent guide says the same in one line: “Set limits on agent retries or actions.”
5. Classify failures where they happen. A tool error should say whether retrying can help. Transient errors belong to a retry policy in code, as in “Building Reliable LLM Pipelines (opens in a new tab)”. Permanent ones are the replanner’s job, and it can only reroute if it knows the other route exists. For a deadline you know how to compute, the fallback can simply be code.
6. Move reasoning you can write down into tools. Totals, duplicate detection, and deadline arithmetic are deterministic. The totals and the duplicate-charge check that W got wrong are work that a few lines of tested code would do the same way every time.
7. Check capability before planning. “Can any tool do this?” is a question for code, answered before the planner sees the request. When the answer is no, the reply is a handoff or an honest refusal, not a decomposition.
8. Log the steps, not the reasoning. The record of a run is what executed, with what arguments, and what came back. The reasoning is useful for debugging, but it’s not evidence of what the agent did. Anthropic’s guide calls it crucial for agents to gain “ground truth” from the environment “at each step (such as tool call results or code execution) to assess its progress.” That ground truth is in the tool results, not in the plan’s explanation.
When Planning Helps, and When a Workflow Is Better
When the steps are known, a workflow is better. That covered most of this experiment’s requests: cancellation, refund eligibility, duplicate charges, totals. W’s failures were in reasoning, which planning can’t fix, except on Q7, where its fixed steps had no fallback written for the outage.
When the next step genuinely depends on a result you can’t predict, someone has to plan at runtime. Here, replanning raised retrieval from 3 of 24 conversations (its first plans) to 10, and found the one correct Q4 answer. It also cost 16 times W’s tokens and hit its limit in more than half its conversations. Replanning earns its cost only with the guardrails above: validated steps, enforced budgets, and a definition of “done” that code can check.
A separate plan step helps when the plan itself is something you can use: to show a person before anything runs, to check against rules, or to run independent steps in parallel. In this experiment, this simple P’s plans were no better than the loop’s choices, and they were easy to inspect: every placeholder and every dropped step was visible before execution, which is exactly when a validator could have stopped it.
And when the request is something the system can’t do, no planning design is right. That’s a capability check, and it belongs in code.
What to Take Away
- Planning, reasoning, and execution fail separately, so measure them separately. Here, the hand-written plan got the facts 21 times of 24, and the reply was still wrong in 14 of those 21.
- A model planning before it has the facts writes placeholders. Validate every argument against the message and earlier results before a step runs.
- Replanning adds facts and adds loops. It more than tripled retrieval over its own first plans, and hit its limit in 14 of 27 conversations at 16 times the workflow’s tokens.
- A plan’s reasoning isn’t a description of its steps. Trust what executed, not what the planner said it would do.
- The model should decide what is genuinely uncertain; code should enforce what is already knowable. Tool availability, argument validity, dependencies, arithmetic, retry budgets, and completion conditions can all be checked without a model.
Think About These Use Cases
-
A travel-booking agent: “Book the cheapest flight that arrives before my meeting, and a hotel near the venue.” Which steps depend on others’ results, and how would a plan that runs before any search express that?
-
An incident-response assistant: Its runbook says “check the dashboard, then the logs, then roll back if needed.” Which parts should stay a fixed workflow, and where would replanning actually help?
-
A data-analysis agent: It writes a plan of SQL queries before running any. How would you validate the plan (tables exist, columns exist, no writes) before execution?
-
An agent with a failing dependency: Its preferred API is down for an hour. How should the error tell the planner whether to retry, wait, or take another route, and who decides when to stop?
-
A “done” check: Your replanner decides when it has enough. What could code check instead, for each kind of request, so “done” doesn’t depend on the model’s judgment?
If you want to talk one of these through, take it to GPT along with this article. Ask GPT ↗️
Related Sources
- 05-planning: The companion demo: the four designs, the frozen tasks, prompts, and evaluation rules, all 108 saved conversations with every plan and tool call, the hand labels, and a report script that re-grades without calling a model.
- Yao et al.: ReAct: Synergizing Reasoning and Acting in Language Models (ICLR 2023): Reasoning traces and actions interleaved, so the model can update its plan from what it observes.
- Wang et al.: Plan-and-Solve Prompting (ACL 2023): Devising a plan that divides a task into subtasks before carrying them out.
- Xu et al.: ReWOO: Decoupling Reasoning from Observations for Efficient Augmented Language Models (arXiv preprint, 2023): Planner, worker, and solver, with plans that refer to earlier evidence by name.
- Kim et al.: An LLM Compiler for Parallel Function Calling (ICML 2024): Plans as a dependency graph of function calls, run in parallel, with replanning.
- Kambhampati et al.: LLMs Can’t Plan, But Can Help Planning in LLM-Modulo Frameworks (ICML 2024, position paper): LLMs as candidate-plan generators checked by external verifiers.
- Turpin et al.: Language Models Don’t Always Say What They Think (NeurIPS 2023): Chain-of-thought explanations that are plausible but don’t reflect the reason for the answer.
- Anthropic: Reasoning models don’t always say what they think (April 2025): Measuring how often reasoning models’ chains of thought mention what actually influenced them.
- Anthropic: Building effective agents (December 2024): Orchestrator-workers, ground truth from the environment at each step, and stopping conditions. The page notes that the tooling it describes has changed since publication.
- LangChain: Plan-and-Execute Agents (May 2023): The planner and executor split, and its cost in extra model calls.
- LangChain: Planning agents (February 2024): Plan-and-execute, ReWOO, and LLMCompiler as LangGraph agents, with replanning after execution.
- OpenAI: A practical guide to building agents (PDF): Run loops, exit conditions, and limits on retries and actions.
What’s Next?
Every design here kept its state in a list of messages or a list of steps, and every limit was a counter in a loop. The replanner that couldn’t stop, the loop that stopped too soon, and the retry that never became a reroute are all problems of control flow: which state the system is in, what moves it to the next one, and what’s allowed to happen there.
In the next article, we’ll look at Building AI Agents With State and Workflows: how state machines and workflow engines give an agent’s steps an explicit structure that code can check.