Özer Cem KELAHMETKELAHMET
AI Simulations · Agents

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.

Download Markdown

Interactive simulation. It needs JavaScript; the text below explains what it shows.

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. 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, and the exploration bonus solves the same problem as the bandits in the gradient bandit simulation. The LATS article covers the full loop with code.

Sources

Last updated Nov 25, 2026
Type to search.
    ↑↓ navigate↵ open