# LATS: how UCT and an LM value function choose which agent branch to expand next

Language Agent Tree Search runs Monte Carlo tree search over an agent's actions. Twelve child actions of one HotpotQA node show how the value, built from an LM score, self-consistency and rewards, meets the UCT exploration bonus, and why the search picks child 5 instead of the best-valued child 1.

<div data-sim="specx" data-spec="{&#34;head&#34;:&#34;LATS: how UCT picks which branch of an agent&#39;s search tree to expand next&#34;,&#34;sub&#34;:&#34;Twelve child actions of one node in a Language Agent Tree Search tree for a HotpotQA question, each with an LM score, a self-consistency score, visits and backpropagated rewards. Set the exploration weight and lambda, then add rollouts to the chosen branch and see when UCT moves on.&#34;,&#34;params&#34;:[{&#34;id&#34;:&#34;w&#34;,&#34;label&#34;:&#34;Exploration weight (w)&#34;,&#34;min&#34;:0,&#34;max&#34;:3,&#34;step&#34;:0.05,&#34;value&#34;:1,&#34;note&#34;:&#34;LATS uses w = 1 by default&#34;},{&#34;id&#34;:&#34;lam&#34;,&#34;label&#34;:&#34;Weight of the LM score (lambda)&#34;,&#34;min&#34;:0,&#34;max&#34;:1,&#34;step&#34;:0.05,&#34;value&#34;:0.5,&#34;note&#34;:&#34;0.5 for HotpotQA and Game of 24, 0.8 for programming and WebShop&#34;},{&#34;id&#34;:&#34;rew&#34;,&#34;label&#34;:&#34;Reward the chosen branch keeps returning&#34;,&#34;min&#34;:0,&#34;max&#34;:1,&#34;step&#34;:0.05,&#34;value&#34;:0,&#34;note&#34;:&#34;0 = every new rollout through it ends with a wrong answer&#34;}],&#34;data&#34;:{&#34;columns&#34;:[&#34;child&#34;,&#34;lm&#34;,&#34;sc&#34;,&#34;visits&#34;,&#34;rsum&#34;],&#34;rows&#34;:[[1,0.9,0.8,12,8],[2,0.8,0.6,9,5],[3,0.8,0.6,7,4],[4,0.7,0.4,6,3],[5,0.7,0.6,5,3],[6,0.6,0.4,4,1],[7,0.6,0.2,4,1],[8,0.5,0.4,3,0],[9,0.4,0.2,3,0],[10,0.5,0.2,2,0],[11,0.3,0.2,2,0],[12,0.2,0,2,0]],&#34;note&#34;:&#34;Illustrative node in the style of LATS on HotpotQA (Zhou et al., 2024): lm = LM value score scaled to 0-1, sc = share of sampled actions agreeing with this one, visits = N(s), rsum = rewards from rollouts after the first visit. The paper samples n = 5 children; 12 are shown here.&#34;},&#34;pre&#34;:[{&#34;id&#34;:&#34;np&#34;,&#34;label&#34;:&#34;Parent visits N(p)&#34;,&#34;expr&#34;:&#34;sum(visits)&#34;,&#34;fmt&#34;:&#34;i&#34;,&#34;tex&#34;:&#34;N(p) = \\sum_s N(s)&#34;}],&#34;row&#34;:[{&#34;id&#34;:&#34;v0&#34;,&#34;label&#34;:&#34;evaluation value&#34;,&#34;expr&#34;:&#34;lam*lm + (1 - lam)*sc&#34;,&#34;tex&#34;:&#34;V_0(s) = \\lambda\\,\\mathrm{LM}(s) + (1-\\lambda)\\,\\mathrm{SC}(s)&#34;},{&#34;id&#34;:&#34;val&#34;,&#34;label&#34;:&#34;value after backpropagation&#34;,&#34;expr&#34;:&#34;(v0 + rsum)/visits&#34;,&#34;tex&#34;:&#34;V(s) = \\frac{V_0(s) + \\sum r}{N(s)}&#34;},{&#34;id&#34;:&#34;bonus&#34;,&#34;label&#34;:&#34;exploration bonus&#34;,&#34;expr&#34;:&#34;w*sqrt(ln(np)/visits)&#34;,&#34;tex&#34;:&#34;B(s) = w\\sqrt{\\ln N(p) / N(s)}&#34;},{&#34;id&#34;:&#34;uct&#34;,&#34;label&#34;:&#34;UCT score&#34;,&#34;expr&#34;:&#34;val + bonus&#34;,&#34;tex&#34;:&#34;\\mathrm{UCT}(s) = V(s) + w\\sqrt{\\frac{\\ln N(p)}{N(s)}}&#34;},{&#34;id&#34;:&#34;tb&#34;,&#34;label&#34;:&#34;UCT with tie-break&#34;,&#34;expr&#34;:&#34;uct - 0.000001*child&#34;,&#34;hide&#34;:true}],&#34;derived&#34;:[{&#34;id&#34;:&#34;top&#34;,&#34;label&#34;:&#34;Highest UCT score&#34;,&#34;expr&#34;:&#34;amax(uct)&#34;},{&#34;id&#34;:&#34;top_tb&#34;,&#34;label&#34;:&#34;Highest UCT with tie-break&#34;,&#34;expr&#34;:&#34;amax(tb)&#34;,&#34;hide&#34;:true},{&#34;id&#34;:&#34;vmax&#34;,&#34;label&#34;:&#34;Highest value V(s)&#34;,&#34;expr&#34;:&#34;amax(val)&#34;},{&#34;id&#34;:&#34;bmean&#34;,&#34;label&#34;:&#34;Mean exploration bonus&#34;,&#34;expr&#34;:&#34;mean(bonus)&#34;}],&#34;row2&#34;:[{&#34;id&#34;:&#34;sel&#34;,&#34;label&#34;:&#34;selected next&#34;,&#34;expr&#34;:&#34;ge(tb, top_tb)&#34;,&#34;fmt&#34;:&#34;i&#34;},{&#34;id&#34;:&#34;vlead&#34;,&#34;label&#34;:&#34;value leader&#34;,&#34;expr&#34;:&#34;ge(val, vmax)&#34;,&#34;fmt&#34;:&#34;i&#34;,&#34;hide&#34;:true},{&#34;id&#34;:&#34;oth&#34;,&#34;label&#34;:&#34;rival UCT after x rollouts&#34;,&#34;expr&#34;:&#34;ifelse(sel, -9, val + w*sqrt(ln(np + x)/visits))&#34;,&#34;hide&#34;:true},{&#34;id&#34;:&#34;s_child&#34;,&#34;label&#34;:&#34;selected child id&#34;,&#34;expr&#34;:&#34;sel*child&#34;,&#34;hide&#34;:true},{&#34;id&#34;:&#34;s_val&#34;,&#34;label&#34;:&#34;selected value&#34;,&#34;expr&#34;:&#34;sel*val&#34;,&#34;hide&#34;:true},{&#34;id&#34;:&#34;s_n&#34;,&#34;label&#34;:&#34;selected visits&#34;,&#34;expr&#34;:&#34;sel*visits&#34;,&#34;hide&#34;:true},{&#34;id&#34;:&#34;g_child&#34;,&#34;label&#34;:&#34;value leader id&#34;,&#34;expr&#34;:&#34;vlead*child&#34;,&#34;hide&#34;:true}],&#34;post&#34;:[{&#34;id&#34;:&#34;chosen&#34;,&#34;label&#34;:&#34;Child UCT selects&#34;,&#34;expr&#34;:&#34;amax(s_child)&#34;,&#34;fmt&#34;:&#34;i&#34;},{&#34;id&#34;:&#34;greedy&#34;,&#34;label&#34;:&#34;Child with the highest value&#34;,&#34;expr&#34;:&#34;amax(g_child)&#34;,&#34;fmt&#34;:&#34;i&#34;},{&#34;id&#34;:&#34;chosen_val&#34;,&#34;label&#34;:&#34;Value of the selected child&#34;,&#34;expr&#34;:&#34;amax(s_val)&#34;},{&#34;id&#34;:&#34;chosen_n&#34;,&#34;label&#34;:&#34;Visits of the selected child&#34;,&#34;expr&#34;:&#34;amax(s_n)&#34;,&#34;fmt&#34;:&#34;i&#34;},{&#34;id&#34;:&#34;chosen_bonus&#34;,&#34;label&#34;:&#34;Its exploration bonus&#34;,&#34;expr&#34;:&#34;w*sqrt(ln(np)/chosen_n)&#34;},{&#34;id&#34;:&#34;self_x&#34;,&#34;label&#34;:&#34;Selected child&#39;s UCT after x more rollouts&#34;,&#34;expr&#34;:&#34;(chosen_val*chosen_n + x*rew)/(chosen_n + x) + w*sqrt(ln(np + x)/(chosen_n + x))&#34;,&#34;tex&#34;:&#34;\\mathrm{UCT}_x(s^*) = \\frac{V(s^*)N(s^*) + x\\,r}{N(s^*)+x} + w\\sqrt{\\frac{\\ln(N(p)+x)}{N(s^*)+x}}&#34;},{&#34;id&#34;:&#34;rival_x&#34;,&#34;label&#34;:&#34;Best rival UCT after x rollouts&#34;,&#34;expr&#34;:&#34;amax(oth)&#34;},{&#34;id&#34;:&#34;margin&#34;,&#34;label&#34;:&#34;Lead of the selected child&#34;,&#34;expr&#34;:&#34;self_x - rival_x&#34;,&#34;tex&#34;:&#34;\\Delta(x) = \\mathrm{UCT}_x(s^*) - \\max_{s\\ne s^*}\\mathrm{UCT}_x(s)&#34;}],&#34;iterate&#34;:{&#34;state&#34;:[{&#34;id&#34;:&#34;x&#34;,&#34;label&#34;:&#34;Extra rollouts through the selected child&#34;,&#34;init&#34;:&#34;0&#34;}],&#34;update&#34;:[{&#34;id&#34;:&#34;x&#34;,&#34;expr&#34;:&#34;x + 1&#34;}],&#34;max&#34;:20,&#34;per&#34;:1,&#34;track&#34;:&#34;margin&#34;},&#34;chart&#34;:{&#34;title&#34;:&#34;UCT score against visits: value plus a shrinking exploration bonus&#34;,&#34;x&#34;:{&#34;var&#34;:&#34;t&#34;,&#34;label&#34;:&#34;Visits to a child, N(s)&#34;,&#34;from&#34;:1,&#34;to&#34;:12},&#34;y&#34;:{&#34;from&#34;:0,&#34;to&#34;:2.4},&#34;series&#34;:[{&#34;label&#34;:&#34;Bonus alone&#34;,&#34;expr&#34;:&#34;w*sqrt(ln(np)/t)&#34;,&#34;dash&#34;:true},{&#34;label&#34;:&#34;UCT of a child valued like the selected one&#34;,&#34;expr&#34;:&#34;chosen_val + w*sqrt(ln(np)/t)&#34;},{&#34;label&#34;:&#34;UCT of a child valued 0.2&#34;,&#34;expr&#34;:&#34;0.2 + w*sqrt(ln(np)/t)&#34;,&#34;dash&#34;:true}],&#34;fit&#34;:{&#34;x&#34;:&#34;visits&#34;,&#34;y&#34;:&#34;uct&#34;,&#34;label&#34;:&#34;Children: UCT score&#34;},&#34;mark&#34;:&#34;chosen_n&#34;},&#34;level&#34;:&#34;advanced&#34;,&#34;bars&#34;:{&#34;title&#34;:&#34;UCT score of each child&#34;,&#34;y&#34;:&#34;uct&#34;,&#34;label&#34;:&#34;child&#34;},&#34;steps&#34;:[{&#34;title&#34;:&#34;Select&#34;,&#34;text&#34;:&#34;Starting at the root, LATS walks down the tree picking the child with the highest UCT. This node has been visited {np} times through its children.&#34;,&#34;show&#34;:[&#34;np&#34;]},{&#34;title&#34;:&#34;Evaluate&#34;,&#34;text&#34;:&#34;Each new child is scored by the LM and by self-consistency, mixed with lambda = {lam}: V0 = lambda times LM plus (1 minus lambda) times SC.&#34;},{&#34;title&#34;:&#34;Backpropagate&#34;,&#34;text&#34;:&#34;Every rollout&#39;s reward is averaged into the values on its path, so a child&#39;s value is its evaluation plus its rewards divided by its visits. The best value here belongs to child {greedy}.&#34;,&#34;show&#34;:[&#34;greedy&#34;]},{&#34;title&#34;:&#34;Add the exploration bonus&#34;,&#34;text&#34;:&#34;UCT adds w times the square root of ln N(p) over N(s). With w = {w} the mean bonus is {bmean}. The highest UCT, {top}, belongs to child {chosen}: value {chosen_val} after {chosen_n} visits plus a bonus of {chosen_bonus}.&#34;,&#34;show&#34;:[&#34;top&#34;,&#34;chosen&#34;,&#34;chosen_val&#34;,&#34;chosen_bonus&#34;]},{&#34;title&#34;:&#34;Expand, simulate, reflect&#34;,&#34;text&#34;:&#34;LATS expands the selected child, samples n actions, runs the trajectory to a terminal state and, if it fails, writes a reflection that goes into later prompts.&#34;},{&#34;title&#34;:&#34;Move on from a branch&#34;,&#34;text&#34;:&#34;Run the algorithm to add rollouts through child {chosen} while the other children wait. After {x} more rollouts returning {rew}, its UCT is {self_x} against {rival_x} for the best rival, a lead of {margin}; once the lead is negative, UCT selects another child.&#34;,&#34;show&#34;:[&#34;self_x&#34;,&#34;rival_x&#34;,&#34;margin&#34;]}]}"><p>Interactive simulation. It needs JavaScript; the text below explains what it shows.</p></div>

## What you are looking at

Each row is one child of a node in a Language Agent Tree Search (LATS) tree for a HotpotQA question: an action the agent could take next, such as a search for one of the two entities in the question, a lookup on the page it has open, or a final answer. Every child carries four numbers. lm is the language model's own rating of the state, scaled to 0 to 1. sc is the self-consistency score, the share of sampled actions that agree with this one. visits is N(s), how many search iterations have passed through the child, and rsum is the total reward of those iterations after the first, 1 for a correct final answer and 0 for a wrong one.

The children have 59 visits between them, so the parent count is N(p) = 59. The paper samples n = 5 children per expansion; this node shows 12 so that the selection has more to choose between.

The bars show each child's UCT score and the chart shows how that score is built. The dashed curve is the exploration bonus alone, falling as a child is visited more. The solid curve is a child with the selected child's value, 0.73, and the lower dashed curve a child valued 0.2. The dots are the twelve children at their visit counts, and the vertical line marks the selected child's 5 visits.

## The algorithm

LATS (Zhou et al., ICML 2024) combines a ReAct-style agent with Monte Carlo tree search. Each iteration runs six operations:

1. **Selection**: from the root, follow the child with the highest UCT score until reaching a leaf.
2. **Expansion**: sample n actions from the LM, run them in the environment and add the results as children.
3. **Evaluation**: give each new child a value from the LM score and the self-consistency score.
4. **Simulation**: keep expanding the most promising nodes until a terminal state.
5. **Backpropagation**: update visit counts and values along the path with the outcome reward.
6. **Reflection**: after a failed trajectory, the LM writes a self-reflection that is stored and added to later prompts.

The evaluation value mixes two signals with a weight λ, which the paper sets to 0.5 for HotpotQA and Game of 24 and 0.8 for programming and WebShop:

$$V_0(s) = \lambda\,\mathrm{LM}(s) + (1-\lambda)\,\mathrm{SC}(s)$$

Backpropagation then averages the rewards into the value. The simulation counts the evaluation as the first visit, V(s) = (V₀(s) + Σr) / N(s). Selection adds an exploration bonus that is large for children visited rarely compared with their parent:

$$\mathrm{UCT}(s) = V(s) + w\sqrt{\frac{\ln N(p)}{N(s)}}$$

The paper uses w = 1. The bonus is what makes this a search rather than a greedy walk: with w = 0 the agent always follows the best value so far and never learns that a rarely tried action was better.

Worked example. Child 5 has lm = 0.7 and sc = 0.6, so V₀ = 0.5 × 0.7 + 0.5 × 0.6 = 0.65. Its 4 later rollouts returned 3 correct answers, so V = (0.65 + 3) / 5 = 0.730. The bonus is √(ln 59 / 5) = √(4.078 / 5) = 0.903, and UCT = 1.633. Child 1 has the best value, (0.85 + 8) / 12 = 0.7375, but after 12 visits its bonus is only √(4.078 / 12) = 0.583, so its UCT is 1.320. Child 10 has a poor value, 0.175, but only 2 visits, so its bonus is 1.428 and its UCT 1.603. UCT selects child 5, with a lead of 0.030 over child 10.

The iteration then adds rollouts through child 5 while the other children wait, to show how long it keeps the selection. One failed rollout gives child 5 a value of 0.73 × 5 / 6 = 0.608 and a bonus of √(ln 60 / 6) = 0.826, a UCT of 1.434, while child 10's bonus grows to √(ln 60 / 2) = 1.431 and its UCT to 1.606. The lead is now −0.171, so the next iteration selects child 10.

## Things to try

- Set w to 0. The search becomes greedy and picks child 1, the value leader at 0.7375, every time.
- Raise w to 1.5 or 2. The bonus dominates and the search picks child 10, which has one of the lowest values, 0.175, but only 2 visits.
- Set the reward to 1 and run. Even a correct answer through child 5 does not keep the selection: after one rollout its lead is −0.005, because the rarely visited children's bonuses keep growing with ln N(p).
- Move λ to 1, so the value uses only the LM score. Child 10 moves to the top, because its LM score of 0.5 is no longer pulled down by a self-consistency score of 0.2.
- Change one child's visits to 1 and watch its bar jump: a child tried once gets a bonus of √(ln N(p)), about 2 here.

## How it works in real systems

On HotpotQA with GPT-3.5, LATS reached an exact match of 0.63, against 0.32 for ReAct, 0.51 for Reflexion and 0.54 for RAP, using up to k = 50 trajectories. The paper reports 92.7% pass@1 on HumanEval with GPT-4 and an average score of 75.9 on WebShop with GPT-3.5. The HotpotQA setting uses oracle feedback: the environment says whether a submitted answer is correct, which is what makes the reward in backpropagation reliable. Without such a check, the value function and self-consistency score carry the whole search.

The price is calls: every iteration samples n actions, evaluates them and runs a trajectory, so LATS costs many times a single [ReAct run](/ai-simulations/react-tool-calling). It suits tasks where actions can be retried or rolled back, such as code with unit tests or web navigation in a sandbox, and fits poorly where an action has side effects. The reflection step is the same idea as [Reflexion](/ai-simulations/reflexion-retries-written-lessons), and the exploration bonus solves the same problem as the bandits in the [gradient bandit simulation](/ai-simulations/gradient-bandit-policy-gradient-baseline). The [LATS article](/articles/lats-language-agent-tree-search-mcts) covers the full loop with code.

## Sources

- [Zhou et al., Language Agent Tree Search Unifies Reasoning, Acting and Planning in Language Models (arXiv 2310.04406)](https://arxiv.org/abs/2310.04406)
- [LATS paper, full text with the UCT formula, value function, settings and results](https://arxiv.org/pdf/2310.04406)
- [Yao et al., Tree of Thoughts (arXiv 2305.10601)](https://arxiv.org/pdf/2305.10601)
- [Wang et al., Self-Consistency Improves Chain of Thought Reasoning (arXiv 2203.11171)](https://arxiv.org/pdf/2203.11171)
