Chapter 2 · Planning and Reflection¶
2.1 Task Decomposition ★★¶
Why decompose ★★¶
"Planning" in an agent means working out, before or while acting, which steps will get it to the goal. It involves two basic abilities: decomposition, breaking a large goal into a sequence of subgoals, and reflection and refinement, adjusting the plan based on what happens (Weng 2023). This section covers decomposition first.
Why decompose? Because LLMs are good at solving "one small step", but when asked to produce a complete answer to a complex task in one go, they easily skip steps or go wrong halfway. Decomposition brings several benefits: each subtask becomes easy enough for the model to do reliably; each step's result can be checked on its own, so errors are easy to locate; different subtasks can use different tools or models, and independent ones can run in parallel; and an explicit list of subgoals lets the agent know how far it has got.
Decomposition has costs too. First, the decomposition itself can be wrong: a necessary step is missing, the order is reversed, or the task is misunderstood from the start, and then no amount of good execution helps. Second, granularity is hard to get right: too coarse and each step is still too hard; too fine and the number of LLM calls and the context length balloon, and the hand-offs between steps break more easily. Third, many tasks lack information at the start, so they can't be fully broken down in advance and have to be decomposed along the way, which leads to the question in Section 2.3 of "plan first" versus "plan as you go".
Interview questions
- ★★ Why do agents need task decomposition, and what are its risks?
Ways to decompose ★★¶
Ordered by how "explicit" the decomposition is, the common approaches form a spectrum:
- Implicit decomposition: Chain-of-Thought. "Let's think step by step" has the model decompose and solve as it goes, within a single generation (see LLM Basic Chapter 7). It's the simplest, but decomposing and solving are mixed together, so the plan can't be checked separately and is hard to adjust midway.
- Two-stage decomposition: Least-to-Most prompting (Zhou et al. 2022). Stage one only decomposes: the model breaks the original problem into a sequence of subproblems from easy to hard. Stage two solves them in order, appending each subproblem's answer to the context for the next one. Its key advantage is that it generalizes to problems harder than the examples: with CoT, the model tends to reason for as many steps as the examples show, whereas least-to-most turns a hard problem into a chain of easy ones, each within the model's ability, so short examples are enough to solve long problems.
- Explicit plans: have the model first write a numbered plan or to-do list, then execute it step by step. The plan is a separate artifact that can be inspected, edited and updated during execution (see 2.3).
- Decomposition with dependencies: HuggingGPT (Shen et al. 2023) uses ChatGPT as a controller. It first parses the user's request into subtasks and marks the dependencies between them (e.g. "first detect the objects in the image, then generate a description from the result"), then picks a suitable expert model for each subtask, and finally combines the results. Here the plan is a directed acyclic graph (DAG), and subtasks that don't depend on each other can run in parallel.
- Recursive decomposition on demand: ADaPT (Prasad et al. 2023) offers a very practical answer to the granularity problem: first let the executor try the task directly, and call the planner to break it down further only if execution fails, then repeat this recursively for each subtask. Simple tasks are then never over-split, while hard tasks are automatically broken down to a granularity the executor can handle.
Interview questions
- ★ How does Least-to-Most prompting differ from CoT, and why does it generalize to harder problems?
- ★ How do you choose the granularity of decomposition?
Using external planners ★¶
Another route is to let the LLM only "translate" and hand the actual planning to a classical planner. LLM+P (Liu et al. 2023) works like this: the LLM translates a problem described in natural language into PDDL (a formal language describing the initial state, the goal and the rules for actions), a classical planner (such as Fast Downward) finds a plan that is guaranteed correct and even optimal, and the LLM translates the plan back into natural language. The benefit is that correctness comes from mature search algorithms rather than the LLM's own reasoning. The limitations are just as clear: an expert has to write the domain's PDDL description in advance (which actions exist, with what preconditions and effects), it only works in domains that can be formalized, and most open-ended agent tasks (writing code, doing research) are very hard to express in PDDL. This idea of "the LLM generates, an external system guarantees correctness" is generalized further in the LLM-Modulo framework in Section 2.7.
Interview questions
- ★ How does LLM+P work, and what are its limitations?
2.2 Tree of Thoughts ★★¶
Motivation ★★¶
input x
/ | \
z1 (a) z1 (b) z1 (c) ← generate k candidate thoughts
sure impossible maybe ← evaluate each state
/ \ |
z2 (a1) z2 (a2) z2 (c1) ← expand only promising states
... ... ... ← backtrack when a branch dies
When an LLM generates text, it makes decisions left to right, one token at a time, and never goes back to revise a decision once made. CoT just writes more intermediate steps along this road; in essence it still follows a single path. The trouble is that in many tasks, once the first few steps are wrong, the rest can't possibly be right. Yao et al. (2023) found on Game of 24 (combine four numbers with +, −, ×, ÷ to get 24) that about 60% of CoT samples had already gone wrong at the first step.
Self-consistency (CoT-SC) samples several reasoning chains independently and votes on the final answer. It beats a single CoT chain but still has two problems: within each chain there's still no chance to go back, and it only compares final answers without ever evaluating intermediate steps, so a chain that went wrong at step one has to run to the end before anyone knows. It also needs answers that can be voted on, which doesn't work for open-ended outputs like writing.
When people solve such problems, they try out several possible first steps in their head, judge which looks most promising, continue along the promising one, and back up to try another when it leads nowhere; this is exactly heuristic tree search from classical AI. Tree of Thoughts (ToT, Yao et al. 2023) brings this idea to LLMs: reasoning is treated as search over a tree, where each node is a state (the partial solution so far) and each edge is a "thought", a coherent intermediate step such as one equation or one writing plan. The LLM does two jobs at once: generating candidate thoughts and evaluating how promising each state is.
Interview questions
- ★★ What problems of CoT and CoT-SC does ToT address?
The four components ★★¶
ToT is a general framework; to apply it to a specific task you have to answer four questions. A state \(s\) is the input \(x\) plus the sequence of thoughts so far, \(z_1, \dots, z_i\).
1. How to split thoughts (thought decomposition). A thought should be the right size: "small" enough that the LLM can generate diverse, promising candidates, yet "large" enough that the LLM can judge whether it's any good. One token is too small to evaluate; a whole essay is too large, with candidates that differ too much and cost too much to generate. In the paper, a thought in Game of 24 is one intermediate equation (three steps reach the answer), in creative writing it is a writing plan, and in crosswords it is the word filled into one clue.
2. How to generate candidates (thought generator). There are two strategies. Sample draws \(k\) times independently from the same prompt, which suits a large thought space (e.g. a writing plan), where independent samples are naturally diverse. Propose uses one prompt that has the model list \(k\) different candidates at once, which suits a constrained thought space (e.g. one equation or one word); there, independent samples easily come out as duplicates, and listing them together avoids that.
3. How to evaluate states (state evaluator). This is the heart of ToT: here the LLM acts as the search heuristic. Again there are two ways. Value scores each state on its own: in Game of 24, for example, the model does a little lookahead reasoning on the remaining numbers ("5, 5 and 14 are all too big to make 24") and gives one of three verdicts, sure / maybe / impossible, sampled a few times and aggregated into a score. Vote puts a set of states \(S\) side by side and has the model pick the most promising one, \(s^*\); the chosen state gets 1 point, and votes are repeated and counted (\(\mathbb{1}[\cdot]\) is the indicator function). Vote suits cases where scoring alone is hard but comparing is easy, such as judging which passage is more coherent. The heuristic doesn't have to be perfectly accurate; as long as it roughly ranks good states first, search benefits.
4. Which search algorithm. BFS keeps only the \(b\) highest-scoring states at each level (in the formula, \(S'_t\) is the set of all candidate states expanded at level \(t\), and \(b\) is the beam width). It suits tasks of limited depth where the first steps can already be judged, such as Game of 24 (3 steps) and creative writing (2 steps). DFS always follows the most promising state downward until it finds a solution or the evaluator judges the current state hopeless; it then prunes that subtree and backs up to the parent to try the next candidate. DFS suits deeper searches such as crosswords: as soon as the model judges that some remaining clue can no longer be filled, it backtracks.
Interview questions
- ★★ Explain the four components of Tree of Thoughts.
- ★ When does each thought-generation strategy, sample or propose, fit?
- ★ What tasks suit BFS and DFS in ToT?
Results and costs ★★¶
| Method (GPT-4, Game of 24) | Success rate |
|---|---|
| IO prompting | 7.3% |
| CoT | 4.0% |
| CoT-SC (k = 100) | 9.0% |
| CoT, best of 100 | 49% |
| ToT (b = 1) | 45% |
| ToT (b = 5) | 74% |
These numbers say a lot. CoT-SC sampled 100 chains and still succeeded only 9% of the time: if most chains go wrong at the first step, no amount of sampling or voting helps. ToT, even with \(b = 1\) (keeping only the single best state per level, i.e. "greedy with evaluation"), reaches 45%, which shows that what really matters is evaluating intermediate states. Widening the beam to 5 brings success to 74%. Crosswords tell a similar story: ToT gets 60% of words right, CoT only 15.6%.
The price is cost. Every node needs one generation and several evaluations, so ToT costs about 0.74 USD per Game of 24 problem, more than the roughly 0.47 USD for 100 CoT samples. Each task also needs its own thought split and its own prompts for generation and evaluation, so moving to a new task isn't easy. ToT therefore fits tasks that meet a few conditions: intermediate states can be evaluated; a mistake in the first few steps is unrecoverable; and the model is decent at generating candidates but not confident of getting it right in one pass. For tasks CoT already solves reliably, ToT is just waste.
Two more points. First, ToT's evaluator is the generator itself, so if the model can't spot its own errors, search doesn't help (see 2.7). Second, ToT searches "in its head" without interacting with an external environment; putting similar search into a real environment and evaluating with real feedback is LATS in Section 2.6. Today's reasoning models (such as o1 and DeepSeek-R1) have learned through RL to try, verify and back up on their own within one long CoT (see LLM Basic Chapter 7), so many reasoning tasks no longer need explicit ToT; but where a reliable external evaluator exists, explicit search is still very useful.
Interview questions
- ★★ Why does CoT-SC with 100 samples still fail on Game of 24 while ToT works?
- ★ What does ToT cost, and which tasks are worth it?
- ★ Is ToT still useful now that we have reasoning models?
Graph of Thoughts ★¶
Graph of Thoughts (GoT, Besta et al. 2023) generalizes the tree to an arbitrary directed graph: thoughts are nodes and edges are dependencies. A tree can only branch, never merge; a graph adds two operations. Aggregation merges several thoughts into one, e.g. combining partial solutions into a complete one; refinement lets a thought point to itself, forming a loop that improves it repeatedly. This makes divide-and-conquer possible. Take sorting: split a long list into chunks, sort each, then merge them pairwise, just like merge sort, where each merge is an aggregation. The paper reports that on sorting, GoT improves quality by 62% over ToT while cutting cost by more than 31%. The catch is that the graph structure (how many chunks, how to merge) has to be designed by hand for each task, so it's more a programming framework for orchestrating LLM calls than a method that discovers solutions on its own.
Interview questions
- ★ What does Graph of Thoughts add over ToT?
2.3 Plan-and-Execute vs Interleaved Planning ★★¶
Interleaved planning ★★¶
ReAct from Chapter 1 is the classic example of interleaved planning: it never writes out a complete plan, but decides the next step only after taking a step and seeing the new observation, so planning and execution are woven together. Its biggest strength is adaptivity: every decision is based on the latest information, and when something unexpected happens (a search returns nothing, a page's layout has changed), it can adjust immediately.
But its weaknesses get amplified on long tasks. First, it's myopic: each step considers only what's in front of it, with no overall arrangement of the whole task, so it easily gets lost in details, forgets the overall goal, or even makes decisions that conflict with later steps. Second, every step needs a call to the big model, carrying an ever-longer full history, so cost and latency rise quickly with the number of steps (see 1.6 in Chapter 1). Third, with no explicit plan, it's hard for a human to check what the agent intends to do before it does it.
Interview questions
- ★ What problems does ReAct-style interleaved planning run into on long tasks?
Plan-and-execute ★★¶
Plan-and-execute separates planning from execution: a planner first writes the complete multi-step plan \(P\) in one go (\(x\) is the task, \(p_i\) is step \(i\)); then an executor carries out the steps one by one, producing results \(o_i\). The executor can be a smaller, cheaper model, a small ReAct agent responsible for a single step, or plain code. A replanner is usually added as well: after each step, or when a step fails, the original plan and the results so far go back to the planner, which produces a revised plan \(P'\).
The idea goes back to Plan-and-Solve prompting (Wang et al. 2023). The authors found that a common error in zero-shot CoT is skipping steps, so they changed the prompt to "first understand the problem and devise a plan to solve it, then carry out the plan step by step", which clearly reduced such errors. The reason is that writing a plan first forces the model to go through the whole task before starting.
The strengths of plan-and-execute line up exactly with the weaknesses of interleaved planning: it has a global view, thinking the whole task through before acting; it makes fewer calls to the big model, since planning happens once (or a few times) and execution can go to cheaper models; the plan is explicit, so a human can review and edit it before execution; and independent steps in the plan can run in parallel. Its weaknesses: the plan is made before seeing any observation, so it may rest on wrong assumptions; without replanning, execution is rigid and one surprise sinks everything; and replanning frequently adds the cost back.
Interview questions
- ★ Why does Plan-and-Solve reduce zero-shot CoT errors?
- ★ When is replanning needed, and what goes wrong if you replan too often?
Comparison and choice ★★¶
| Interleaved (ReAct-style) | Plan-and-execute | |
|---|---|---|
| When planning happens | One step at a time, after each observation | Up front, plus optional replanning |
| Global view | Weak; can drift on long tasks | Strong; the whole task is laid out first |
| Adaptivity | High | Low unless replanning is added |
| Big-model calls | One per step, with a growing history | Few; steps can use cheaper executors |
| Parallelism | Sequential | Independent steps can run in parallel |
| Inspectability | The plan is implicit | An explicit plan humans can review |
| Fits | Exploratory tasks in uncertain environments | Tasks whose structure is predictable in advance |
In real systems the line between the two is increasingly blurred, and the most common form is a hybrid: the agent first writes a rough plan (e.g. a to-do list), then executes the current item ReAct-style, updating the list whenever an item is finished or something unexpected happens. This keeps a global view while preserving adaptivity, and the list itself also does the "recitation" job from 1.6 in Chapter 1, keeping the overall goal at the end of the context. The key question when choosing is: how much of the task's structure can be foreseen at the start? If the structure is clear (e.g. "compare three products along these five dimensions"), lean toward planning first; if it depends heavily on exploration (e.g. "find the cause of this bug"), lean toward interleaving.
Interview questions
- ★★ What are the pros and cons of plan-and-execute versus ReAct-style interleaved planning, and what tasks suit each?
ReWOO: Reasoning Without Observation ★¶
Plan: Find the director of Oldboy (2003).
#E1 = Search[Oldboy (2003 film)]
Plan: Find the nationality of the director found in #E1.
#E2 = LLM[What is the nationality of the director mentioned in: #E1]
Solver: question + plan + #E1 + #E2 → "South Korea"
ReWOO (Xu et al. 2023, Reasoning WithOut Observation) is an extreme version of plan-and-execute aimed at saving tokens. Its starting point: ReAct resends the full prompt and history to the model at every step, so a lot of tokens are processed again and again. ReWOO splits the process into three roles. The Planner writes the whole plan in one go, with placeholder variables (#E1, #E2) standing for later steps' references to earlier results; the Worker executes the tool calls in order and fills the real results into the variables; the Solver takes the plan and all the evidence and produces the final answer. Apart from any LLM the Worker may call as a tool, the main model is called only once for the Planner and once for the Solver, and the ever-growing history no longer has to be resent at every step. The paper reports about 5× better token efficiency on HotpotQA along with a 4% accuracy gain, and the planner can be distilled into a 7B model.
The price is giving up adaptivity entirely: the plan is fixed before any observation is seen, so if the search for #E1 returns something unexpected (say, a different film with the same name), later steps have no chance to adjust. (LLMCompiler (Kim et al. 2023) goes in the same direction, representing the plan as a DAG of tasks and running independent tool calls in parallel to cut latency further.)
Interview questions
- ★ How does ReWOO save tokens, and what does it cost?
2.4 Reflection: Self-Refine and Reflexion ★★¶
Planning is thinking things through before acting; reflection is looking back after acting: evaluating one's own output or trajectory, finding problems, and doing better next time. By scope, reflection comes in two kinds: repeatedly revising within a single output (Self-Refine), and accumulating lessons across multiple attempts at the same task (Reflexion). Neither updates the model's weights; all improvement happens in the context.
Self-Refine ★★¶
Self-Refine (Madaan et al. 2023) mimics how people write, "draft → critique it yourself → revise", with all three roles played by the same model \(\mathcal{M}\) using different few-shot prompts. As in the formula: the generation prompt \(p_{\text{gen}}\) produces a first draft \(y_0\) from the input \(x\); the feedback prompt \(p_{\text{fb}}\) has the model comment on the current version \(y_t\), giving feedback \(fb_t\); and the refine prompt \(p_{\text{refine}}\), together with all previous versions and feedback, produces a new version \(y_{t+1}\) (\(\|\) denotes concatenation). The loop runs until the feedback says "no more issues" or a maximum number of rounds is reached. All previous versions and feedback are kept so the model knows which problems have already been pointed out and doesn't revert to an earlier mistake.
A key finding is that feedback quality decides the outcome: specific, actionable feedback ("the argument in paragraph two lacks an example; add this figure") works much better than generic feedback ("this could be better"), and generic feedback still beats none. Across 7 tasks including dialogue responses, code optimization and math reasoning, using GPT-3.5 and GPT-4, Self-Refine improves on single-pass generation by about 20 percentage points on average.
But the gains are very uneven across tasks. They're large on style, readability and constraint satisfaction, because the model can spot these quality problems itself; they're small on math reasoning, because the model often can't find its own reasoning errors and the feedback keeps saying "looks fine". Weaker models also can't produce useful feedback, so Self-Refine gives them almost nothing. This shows that Self-Refine's ceiling is set by the model's ability to find problems, a point expanded on in Section 2.5.
Interview questions
- ★★ How does Self-Refine work, and what kind of feedback helps most?
- ★ Why does Self-Refine help so little on math reasoning?
Reflexion ★★¶
Self-Refine improves a single output; Reflexion (Shinn et al. 2023) improves an agent's repeated attempts at the same task. It has three modules. The Actor is the agent doing the task (ReAct or CoT, for example) and produces a trajectory \(\tau_k\) (\(k\) is the attempt number). The Evaluator \(M_e\) scores the trajectory, giving \(r_k\); it can be exact match, hand-written rules, unit tests or an LLM judge. The Self-Reflection model \(M_{sr}\), when an attempt fails, reads the trajectory, the score and the existing memory, and writes a verbal reflection \(sr_k\): what went wrong and what to do next time. The reflection is added to long-term memory \(\mathrm{mem}\), which keeps only the latest \(\Omega\) entries (usually 1 to 3, so the context doesn't overflow). On the next attempt, the Actor redoes the task with these reflections in hand.
The authors call this "verbal reinforcement", and an analogy with RL helps. In RL, a scalar reward updates the policy's weights through gradients; in Reflexion, the scalar reward is "translated" into a natural-language lesson stored in memory, and the policy changes its behavior by reading that text, with the weights untouched. The verbal reflection also tackles credit assignment: a "failure" signal by itself doesn't say which step went wrong, whereas a reflection can say directly "in step 3 I took the wrong item; next time check the countertop first", carrying far more information than a bare 0/1 signal. An ablation supports this: on HotpotQA, adding reflections gave 8 points more than keeping only the previous trajectory (episodic memory), showing that "drawing a lesson" is more useful than "remembering what happened".
Details and results: on ALFWorld, the Evaluator is a simple heuristic: if the agent repeats the same action with the same result more than 3 times in a row, or takes more than 30 steps in one environment, the attempt is judged a failure and reflection is triggered. Reflexion eventually completes 130 of 134 tasks, 22 points above ReAct alone, whose performance stops improving after a few retries. On HotpotQA it improves by about 20%. For programming, Reflexion has the model generate its own unit tests (filtering out syntactically invalid ones) and uses the test results as feedback, reaching 91% pass@1 on HumanEval, versus the 80% reported for GPT-4 at the time.
Reflexion has four main limitations. First, it depends on the Evaluator's quality: if the self-generated tests are wrong, wrong code gets marked as passing. Second, it can get stuck in a local optimum, circling within the same kind of idea. Third, on WebShop, which needs a lot of exploration, it brought almost no improvement. Fourth, it needs repeated attempts at the same task, which is fine for running tests or solving benchmark problems, but in the real world many actions can't be undone, and there is no "try again".
Interview questions
- ★★ Explain Reflexion. How is it similar to and different from RL?
- ★ What does Reflexion's memory store, and why are reflections more useful than just keeping failed trajectories?
- ★ What are Reflexion's limitations, and where can't it be used?
Comparison ★¶
| Self-Refine | Reflexion | LATS (see 2.6) | |
|---|---|---|---|
| What is improved | One output, within a single attempt | Behavior across repeated trials of a task | A search tree over many trajectories |
| Feedback source | The same LLM critiques its own output | Environment, tests or heuristics, turned into verbal lessons | Environment reward + LM value + reflections |
| Memory | History of drafts and feedback | Episodic memory of 1–3 reflections | Tree statistics + stored reflections |
| Needs re-attempts? | No | Yes, whole-task retries | Yes, must revert to earlier states |
| Weight updates | None | None | None |
These three methods can be seen as progressively stronger versions along the same direction: Self-Refine only revises itself within one output; Reflexion adds external evaluation and memory across attempts; LATS further adds systematic tree search. The further along, the more feedback can be used and the better the results, but the demands on the environment (being able to retry, being able to revert) and the compute cost rise too. (Another variant worth mentioning is CRITIC (Gou et al. 2023): before revising, it calls tools such as a search engine or code interpreter to verify the output and uses the tool results as feedback, which is exactly the "external feedback instead of self-assessment" idea of the next section.)
Interview questions
- ★ How do Self-Refine, Reflexion and LATS differ?
2.5 Reflection Needs Reliable Feedback ★★¶
All the methods in the previous section share one assumption: the feedback must be reliable. What reflection can do is turn a "something is wrong here" signal into a revision; if the signal itself is wrong, reflection will turn right answers into wrong ones or overlook real errors. So the ceiling of any reflection method is set by the quality of its feedback, not by how well the reflection prompt is written.
Looking back at Reflexion's successes, they all have reliable external signals: HumanEval has executable tests, and ALFWorld has the environment's task-completion signal. On HotpotQA, its Evaluator uses exact match against the gold answer, which is possible in a benchmark but unavailable in real deployment. Using the gold answer to decide "should we try again" amounts to telling the agent "you got this one wrong", which makes results look better than they really are. This is a very common pitfall when evaluating reflection methods (why this oracle setting systematically overestimates the gains is covered in 2.2 of Self-Improving Chapter 2).
An agent has one natural advantage over plain question answering: it acts in an environment, and the environment keeps giving feedback. When designing a reflection loop, consider these signals in order of reliability, from high to low:
- The environment's state and success signals: whether the tests pass, whether the target page was reached, whether the order status really changed. When available, use them first to decide "should we reflect, should we retry".
- Tool execution results: error messages, compiler errors, search results. They bring new information the model didn't have, which makes them the best basis for reflection.
- A trained verifier or an LLM judge: suitable for tasks with no objective signal, but noisy, and the harder you search, the more likely it gets exploited (see 2.7).
- Self-critique by the same model: the cheapest, but the least reliable for reasoning errors, since a mistake made while generating will mostly go unnoticed while checking.
- Humans: the most reliable, but slow and expensive; save them for critical and irreversible steps.
A few design principles follow. First, reflection should be triggered by a concrete signal, rather than asking the model to "check again" at every step. Second, a reflection should cite specific evidence (which error, which failing test), not a vague "something may be wrong". Third, watch out for errors in the feedback itself: self-generated tests may be wrong, LLM judges may be biased, and noisy feedback can turn a correct answer into a wrong one. Fourth, cap the number of retries: reflecting again and again without new information just spins in place. A systematic comparison of feedback sources, and the debate over whether LLMs can improve their reasoning through self-correction alone, without external feedback, are in Self-Improving Chapter 2 and aren't repeated here.
Interview questions
- ★★ Why does the effectiveness of reflection depend on the quality of the feedback?
- ★ Where can an agent get feedback from, and which sources are most reliable?
- ★ What pitfall should you watch for when evaluating reflection methods?
2.6 Search-Based Planning: MCTS and LATS ★★¶
How MCTS works ★★¶
The BFS and DFS used by ToT are fairly "rigid" searches: BFS keeps a fixed number of states per level, and DFS stubbornly follows one path to the end. Monte Carlo Tree Search (MCTS) is more flexible: based on the results so far, it puts more computation into the more promising branches while still keeping some exploration. AlphaGo played Go with MCTS plus a policy network and a value network. MCTS repeats four steps:
- Selection: start at the root and, at each level, pick a child by its UCT score until reaching a leaf that isn't fully expanded yet.
- Expansion: generate several new children (possible next steps) under that leaf.
- Simulation (rollout): from a new node, keep going down to a terminal state and get a real outcome (win or loss, right or wrong).
- Backpropagation: pass this outcome back up the path to the root, updating the visit count and average value of each node along the way.
The UCT formula balances exploitation and exploration: \(V(s)\) is node \(s\)'s current average value, and the higher it is, the more worth following; in the second term, \(N(s)\) is the number of visits to \(s\), \(N(p)\) is the number of visits to its parent, and \(w\) is a weight controlling how much to explore. The fewer times a node has been visited, the larger the second term, and the more likely it is to be picked for a try. This keeps the search from locking onto one good-looking path too early.
Compared with ToT, MCTS has two key differences. First, it allocates compute adaptively: good branches are explored deeper again and again, while bad ones are dropped quickly. Second, its value estimates come from real terminal outcomes (by simulating to the end), not just heuristic guesses, so the estimates get more accurate as the number of searches grows.
Interview questions
- ★★ What are the four steps of MCTS, and what does each term in the UCT formula mean?
- ★ What advantages does MCTS have over ToT's BFS/DFS?
Applying MCTS to LLMs ★¶
Applying MCTS to LLMs means redefining each element. The state is the prompt plus the reasoning or interaction trajectory so far; an action is the next reasoning step or tool call, with several candidates sampled from the LLM (the LLM effectively provides the policy prior); the value can come from the LLM's self-evaluation, a trained reward model or a real outcome from the environment; and the state transition is simply appending the new step in pure reasoning, or actually taking a step in the environment for an agent.
An early example is RAP (Hao et al. 2023, Reasoning via Planning). It has the LLM play two roles at once: the reasoning agent, and a world model that predicts what the state becomes after an action (e.g. in Blocksworld, where every block sits after one is moved). MCTS simulations can then run in the LLM's "imagination" without a real environment.
But applying MCTS to LLMs has several difficulties. First, the action space is unbounded natural language, so only a few candidates can be sampled each time and good actions may be missed. Second, the LLM's value estimates are very noisy. Third, every expansion and evaluation calls the LLM, which is expensive. Fourth, in a real environment, "simulating to the end" has real side effects, unless there's a sufficiently accurate world model or the environment can be reverted at any time.
Interview questions
- ★ When applying MCTS to LLMs, what are the states, actions and values, and what are the difficulties?
LATS ★★¶
LATS (Language Agent Tree Search, Zhou et al. 2023) puts MCTS into a real environment, searching over ReAct-style trajectories and unifying reasoning, acting and planning. It builds six operations on top of MCTS:
- Selection: go from the root to a leaf by UCT.
- Expansion: have the LLM sample \(n\) actions in the current state; the environment executes each and returns an observation, giving \(n\) children.
- Evaluation: score each new node with the formula above. \(\mathrm{LM}(s)\) is the score the LLM gives the trajectory after seeing the environment's feedback; \(\mathrm{SC}(s)\) is a self-consistency score, i.e. how often this action appears across samples, where more often means the model is more confident; \(\lambda\) weights the two.
- Simulation: keep going down from the selected node, preferring high-value nodes, until reaching a terminal state and getting objective feedback (e.g. whether the tests pass or the answer is correct).
- Backpropagation: pass the terminal reward back along the path, updating each node's value and visit count.
- Reflection: if the terminal state is a failure, have the LLM write a reflection analyzing what went wrong, and store it as context for later searches. This brings Reflexion's idea into the search.
So LATS can be understood as a combination of several methods: ReAct provides actions and observations, ToT provides the search framework of "evaluating states with the LM", Reflexion provides verbal reflections, and MCTS provides the exploration–exploitation balance and the mechanism for updating values with real outcomes. In results, LATS with GPT-4 reaches 92.7% pass@1 on HumanEval, and with GPT-3.5 it gets an average score of 75.9 on WebShop, comparable to methods that require finetuning.
The key prerequisite of LATS is that the environment can be reverted to an earlier state: it needs to restart from any node in the tree and try a different action. That's possible in environments like HumanEval, WebShop and QA retrieval (reload the page, rerun the code); but in the real world, once an email is sent, an order placed or a file deleted, there's no going back. The other cost is compute: it's much more expensive than ReAct and Reflexion. LATS therefore fits offline, resettable environments best, such as coding in a sandbox that can be restarted freely, or generating high-quality training trajectories.
| Method | Search | Uses environment feedback | Evaluation | Backtracking |
|---|---|---|---|---|
| CoT / ReAct | None (single path) | ReAct: yes | None | No |
| CoT-SC | Independent samples + vote | No | Majority vote on answers | No |
| ToT | BFS / DFS | No (reasoning in the head) | LM self-evaluation | Yes |
| RAP | MCTS | Simulated by an LLM world model | LM-based rewards | Yes |
| Reflexion | Sequential whole-task retries | Yes | External evaluator + verbal reflection | Restarts the whole task |
| LATS | MCTS | Yes | LM value + self-consistency + env reward + reflection | Yes; needs a revertible environment |
Interview questions
- ★★ How does LATS combine ReAct, ToT and Reflexion?
- ★ What does LATS require of the environment, and why is it hard to use directly in the real world?
- ★ Compare how CoT-SC, ToT, Reflexion and LATS search.
2.7 Limits of LLM Planning ★★¶
Long horizons and error compounding ★★¶
As mentioned in Chapter 1, if each step is independently right with probability \(p_i\), the chance of getting all \(n\) steps right is the product of all the \(p_i\), roughly \(p^n\), which falls exponentially with the number of steps. With 99% reliability per step, for example, only about 37% is left after 100 steps. This model is inaccurate in both directions: it's too pessimistic, because a good agent can notice and fix errors, so one wrong step doesn't mean total failure; and it's too optimistic, because real errors are often correlated, and one wrong assumption affects many later steps at once. But it makes a key point: success on long-horizon tasks requires not only that each step be reliable enough, but even more the ability to detect and recover from errors.
Beyond error compounding, long-horizon tasks have a few extra difficulties: the context keeps growing, causing context rot and goal drift (see 1.6 in Chapter 1); when a task fails, it's hard to tell which step caused it, i.e. credit assignment is hard; and many early decisions only show their consequences much later, which the model can hardly foresee when deciding. (A METR study (Kwa et al. 2025) measures this ability as "how long a task takes a human expert, for tasks agents can complete with 50% success", and finds that this length has been doubling roughly every 7 months: progress is fast, but reliably completing long tasks is still some way off.)
Interview questions
- ★★ Why are long-horizon tasks especially hard for agents?
Evidence on planning ability ★★¶
| Model (zero-shot, PlanBench) | Blocksworld | Mystery Blocksworld |
|---|---|---|
| GPT-4 | 34.6% | 0.16% |
| LLaMA 3.1 405B (best LLM tested) | 62.6% | 0.8% |
| o1-preview | 97.8% | 52.8% |
Can LLMs actually plan? Valmeekam and colleagues tested this systematically with PlanBench (Valmeekam et al. 2022). Blocksworld is a classic planning problem: there are a few stacks of blocks on a table, and you have to rearrange them into a goal configuration through a sequence of "pick up, put down, stack" actions. Mystery Blocksworld is a clever control: the problem structure is exactly the same, but the names of actions and objects are replaced with meaningless words. If a model is really reasoning from the rules, renaming shouldn't matter; if it's mainly matching patterns seen in training data, renaming will break it.
The results are telling (see the table): ordinary LLMs still get part of Blocksworld right but almost completely collapse on Mystery Blocksworld, which shows they're largely pattern-matching rather than really planning. The reasoning model o1-preview made a huge leap, nearly perfect on Blocksworld and 52.8% on Mystery Blocksworld (Valmeekam et al. 2024). But it also has clear limits: on longer problems needing 20 to 40 steps, success drops to about 24%; it offers no guarantee of correctness and sometimes confidently produces wrong plans; and its reasoning is far more expensive.
Real-world planning is harder still. TravelPlanner (Xie et al. 2024) asks an agent to use tools to search flights, hotels and restaurants across about 4 million records and build a travel plan that satisfies multiple constraints such as budget, timing and preferences. GPT-4's final pass rate is only 0.6%. The main reasons for failure: being unable to stay focused on the task, choosing the wrong tools, and being unable to keep track of several constraints at once.
Interview questions
- ★★ Can LLMs really plan? What is the evidence?
- ★ What is Mystery Blocksworld, and what does it test?
Weak self-evaluation ★¶
Many methods in this chapter rely on the LLM for evaluation: ToT uses it to score states, Self-Refine to give feedback, LATS to estimate values, and agents to judge whether a task is done. If the model can't tell its own errors apart, these methods lose much of their power. Worse, search amplifies the evaluator's bias: search is essentially optimization against the evaluator's scores, so the more and the harder you search, the more likely you are to find answers that "the evaluator thinks are great but are actually wrong", the same principle as reward hacking in RL.
There is direct evidence for planning too. Valmeekam et al. (2023) compared two "generate → check → revise" loops on Blocksworld: in one, GPT-4 checked its own plans; in the other, the reliable external validator VAL did the checking. Self-checking did clearly worse, mainly because the LLM verifier produced many false positives, often judging wrong plans to be correct, so wrong plans were returned as final answers. So reliable external feedback (see 2.5) is crucial for both planning and reflection. More on self-correction is in Self-Improving Chapter 2.
Interview questions
- ★ Why does search amplify the bias of self-evaluation?
Mitigations ★★¶
To address these limitations, there are currently several main kinds of mitigation:
- LLM-Modulo (Kambhampati et al. 2024): the authors' position is that "LLMs can't plan on their own, but they can help planning". In the framework, the LLM proposes candidate plans, and a set of external sound verifiers (model-based plan validators, constraint checkers, and humans when needed) check them and feed specific problems back to the LLM, looping "generate → test → critique" and outputting only plans that pass verification. One example the paper cites: on Blocksworld, with the external validator VAL checking the LLM's plans and feeding back the specific errors, accuracy rises to 82% within 15 rounds of back-prompting. In essence, it hands "correctness" to systems that can guarantee it and leaves "creativity and common sense" to the LLM.
- Hand the formal parts to specialized tools: what can be written in PDDL goes to a classical planner (LLM+P), what can be written as code goes to code execution, and what can be written as constraints goes to a solver.
- Short plans, frequent revision: decompose hierarchically, plan only the next few steps at a time, and replan based on the results, rather than planning a long sequence in one go.
- Track state explicitly: record progress and constraints in to-do lists and notes files (see 1.6 in Chapter 1) to reduce goal drift and forgotten constraints.
- Training: training models directly with RL on long-horizon agent tasks (see Chapter 6) and test-time scaling in reasoning models (see LLM Basic Chapter 7) keep improving the model's own planning ability.
- Human checkpoints: have a person confirm the plan before critical or irreversible steps.
Interview questions
- ★★ How can the weaknesses of LLM planning be mitigated?
- ★ What is LLM-Modulo, and what is its core idea?