Tree Search for Language Model Agents

A web agent that clicks its first idea fails most tasks. Let it search, look ahead and back up, and GPT-4o rises from 18.9% to 26.4% on VisualWebArena.

Pick a search budget, then press Run one task. Watch the agent grow a tree of pages, score them, and walk to the best one. Then we build, piece by piece, how the paper does it: the branches, the judge, the search loop and the replay.

You need a feel for how a chat model answers a prompt and the idea of a tree (a start, with branches that split again). We build the rest from zero.

Paper: Jing Yu Koh, Stephen McAleer, Daniel Fried and Ruslan Salakhutdinov at Carnegie Mellon University, “Tree Search for Language Model Agents”, arXiv 2407.01476 (Transactions on Machine Learning Research, 2025). A reading for the Multimodal Interaction lecture of MIT MMAI, Multimodal AI (Spring 2026). Every idea is re-taught here in our own words and devices.

Search before you click

The tasks, the tree and the scores are a toy we made: three clicks to the goal, three candidate clicks per page, noisy scores, seeded so a task repeats. The paper’s own numbers are GPT-4o on 200 VisualWebArena tasks (Figure 2): 24.5% with no search, 32.0% at c = 5, 37.0% at c = 20.

Chapter 0

One Wrong Click Ends the Task

See why an agent that commits to its first idea at every step fails, and what looking ahead could change

You ask an assistant: “Find me the cheapest red Toyota car below $2000.” (This is the example task in the paper.) The assistant opens a classifieds website. It sees a page full of boxes and links. It must pick one click.

In our imagined run, it clicks “Vehicles”. That looks sensible. On the next page it types “Toyota” into a search box. That also looks sensible. Then it sorts by price in the wrong direction, does not notice, and reports a car that costs $1,950 but is blue. The task fails. No single click looked foolish, yet the whole run went wrong.

What a web agent is

A language model (LM) is a program that reads text and writes the next piece of text. Think of a very well read assistant who answers whatever you put in front of them. An agent wraps that assistant in a loop. Each turn the loop shows the model what is on the screen, the model writes one action such as “click the box numbered 33”, and the program carries the action out in a real browser.

What the model sees each turn is the observation: a screenshot, a list of the page’s buttons and links, and the task in plain words. The full list of observations and actions from start to finish is the trajectory. A task counts as solved only if the last page meets the goal. A checker program, called the reward function, says yes (1) or no (0).

The paper asks how good these agents are today. It reports that people solve 78% of the tasks on WebArena and 89% on VisualWebArena. Agents built on the latest models, by contrast, “typically” score below 20%. The gap is large, and the paper names one reason.

Mistakes pile up

A standard agent looks only at the current page and picks one action. It does not try the action out first. It cannot undo a bad click, because it has no plan for coming back. Each step is a coin flip weighted by how good the model is, and one wrong flip can ruin everything after it. The paper calls this compounding error.

The arithmetic is simple. Say each click is right with chance p, and the clicks are independent. Then all n clicks are right with chance p multiplied by itself n times.

P(success)
The chance that the agent finishes the task with every click right. A toy model: it ignores clicks that are wrong but harmless.
p
The chance that one click is the right one, between 0 and 1. For example, 0.8 means four right clicks in five.
n
The number of clicks the task needs. The exponent tells you how many times p is multiplied by itself.

Work one case. With p = 0.8 and n = 5, the chance is 0.8 × 0.8 × 0.8 × 0.8 × 0.8 = 0.32768, about 32.8%. Raise n to 10 and the chance falls to 0.810 = 0.1074, about 10.7%. A very good per-click score still gives a poor task score. Move the sliders and watch the bars fall.

Watch the chance decay

Each bar is the chance that an agent with no search gets the first k clicks all right. The teal bar is the length of your task. Drag both sliders.

80%
6

Illustrative: the formula pn is a simplification, not a number from the paper. The paper only says that error compounds with each step and that agents are far below people (78% on WebArena, 89% on VisualWebArena).

Real tasks are kinder than the toy in one way: some wrong clicks are harmless. They are also harsher in another: the agent often cannot notice that it went wrong. The shape of the problem stays the same. Long tasks punish a first-guess agent.

The idea: look before you commit

Think of a maze with a pencil. You do not walk down the first corridor and hope. You walk a little way, mark the dead end, back up, and try the next turn. This habit is called search: build a map of the places you might reach, try them, and drop the bad ones.

Search has a long record in AI. The chess program Deep Blue beat the world champion in 1997 with massive parallel tree search. AlphaGo used a search called Monte Carlo tree search to reach superhuman play at Go. In those games the rules say exactly who has won. A website has no such score. Nothing tells the agent that its page is “7 points ahead”.

The paper fills the gap with three parts. First, the LM itself proposes several plausible clicks at each page, which become the branches of a tree (a start page, with arrows to the pages each click leads to, and so on). Second, a second LM call acts as a judge and gives each page a score between 0 and 1. Third, a best-first search always explores the page with the best score next, and backs up when a branch goes bad.

The claim, as a trade. Tree search lifts a GPT-4o web agent from 18.9% to 26.4% on VisualWebArena, and from 15.0% to 19.2% on WebArena, because it tries several clicks, scores the pages they reach, and backs up from bad ones. The price is more model calls at answer time.

These two gains are relative: 26.4 is 39.7% more than 18.9, and 19.2 is 28.0% more than 15.0. In plain points the gains are 7.5 and 4.2. We say “relative” whenever we quote the paper’s percentages of improvement. The method needs no retraining of the model. It runs only when the agent answers, so the paper calls it an inference-time method: it spends extra compute at answer time instead of at training time.

The road

The page you just played with, at the top, is a toy of this method. Each chapter below explains one part of it.

  1. The web as a game: states, actions, observations and the agent’s prompt.
  2. Branches: twenty samples from the model become the five best clicks.
  3. The value function: the judge that gives each page a score from 0 to 1.
  4. Best-first search: the frontier, the pop, the stop rules.
  5. Backtracking: reset the site and replay the clicks.
  6. Depth, branching and budget: the three knobs, and what they cost.
  7. The tables: what the results show.
  8. Ablations and limits: what mattered, and where search fails.
  9. The field guide: the numbers, a checklist and the core code.
An agent gets each click right 90% of the time and the task needs 10 clicks. What is the chance it finishes with no mistake, under the toy model?

Chapter 1

The Web as a Game the Agent Plays

Define the states, actions and observations of a web task, and see what the agent reads at each step

Imagine you are blindfolded. A friend sits beside you and reads the page aloud: “Box 31 is a picture of a fax machine. Link 32 is its name. Button 33 says Add to Cart.” You say “press 33”, and your friend presses it. You can act well, as long as the reading is good.

A language model agent is in the same position. It never touches the mouse. It receives a description of the page, and it answers with a short text command. This chapter sets out exactly what the agent receives and what it may answer. Search, in later chapters, is built on these parts.

Four parts of a web task

The paper writes a web task as an environment with four parts, E = (S, A, Ω, T). Each part has a plain meaning.

st+1
The state after step t. Step 0 is the start, for example the homepage.
T
The transition function: the website itself. It is a function from (state, action) to the next state. It does not change between runs.
st, at
The state the agent is in, and the action it chose there. The agent also receives the observation ot+1 of the new state.

Two more pieces complete the task. The instruction I is the goal in plain words. The reward R scores a finished run as 1 (solved) or 0 (not solved). The agent never sees R while it works. It sees only I and the observations.

The determinism of T is a quiet but vital fact. If you replay the same clicks from the same start, you reach the same page. Chapter 5 uses this to undo mistakes.

The twelve actions

GroupActions the agent may writeWhat they do
On the pageclick [elem], hover [elem], type [elem] [text], press [key_comb], scroll [up|down]Act on one element, or move the view
Tabsnew_tab, tab_focus [index], tab_closeOpen, switch to, or close a browser tab
Moving aroundgoto [url], go_back, go_forwardOpen an address, or use the browser arrows
Finishingstop [answer]End the task, with an answer if one is asked for

From Table 1 of the paper. The elem is a number that the observation attaches to each element on the page.

The two benchmarks

The paper tests on two benchmarks (shared exams for agents). WebArena has 812 tasks on five self-hosted sites that copy real ones: shopping, Reddit, a content system, GitLab and maps. VisualWebArena has 910 new tasks on three sites (classifieds, Reddit, shopping). Its tasks need pictures: “find the post that shows this exact item”. Each task comes with its own checker. People solve 78% of WebArena and 89% of VisualWebArena.

Three ways to show the page

Models differ in what they can read, so the paper uses three observation styles. A screenshot is a picture of the page. The Set-of-Marks (SoM) trick draws a box and a number on every clickable element, so the model can say “33” instead of describing a pixel position. The accessibility tree is the page as a plain list of elements, one per line, each with an ID, a type and its text. It is the same list a screen reader uses.

Try each style on one real example from the paper’s prompts. The task is “What is the price of HP Inkjet Fax Machine?”

See what the agent sees

Choose an observation style. The picture on the left is the page. The box on the right is what the model is given in its prompt. Then press Show the reply.

The page, its element lines and the agent’s reply are copied from the paper’s prompt figures (Figures 8 to 10). The element numbers in the tree styles differ from the marked ones, as they do in the paper. The caption line is illustrative: the paper uses BLIP-2 captions, and we did not run it.

What goes into one call, and what comes out

On each turn the program builds one prompt. It holds a system message (the standing rules and the action list), a few worked examples, and then the live facts: the objective, the observation, the current URL, the open tabs and the previous action. In the paper’s setup the screenshot viewport is 1280 by 2048 pixels, and the text part is cut to 3,840 tokens. A token is a small piece of text, roughly three quarters of a word. The multimodal prompt carries 3 worked examples. The WebArena prompt carries 2.

The model replies in text. The system message forces a format: first a short chain of reasoning (“Let’s think step-by-step”), then the fixed phrase “In summary, the next action I will perform is”, then one action between triple backticks. A small parser reads the text inside the backticks and sends it to the browser. One call yields one action.

That reply is only one sample. The same prompt, run again, can give a different action, because the model draws its words from a probability list. The paper does not fight this randomness. It uses it. Chapter 2 shows how.

Why can Llama-3-70B-Instruct not use the marked screenshot style in the paper?

Chapter 2

Branches: Many Plausible Next Clicks

Sample twenty actions from the model, count them, and keep the most popular as the branches of a tree

You stand at a fork and cannot decide. So you ask twenty friends, one at a time, “Which button now?” Most say 35. Some say 34. A few say 33. One says “scroll down”. You now know more than any single friend told you: the popular answers, and the rare ones worth a look.

The paper does exactly this with the model. It asks the same question twenty times and keeps the answers that come up most. Those answers become the branches of the search tree: the clicks the agent will try out.

Why the model gives different answers

A language model does not hold one answer. At each word it produces a probability for every possible next word, and then a rule draws one. Chapter 1 showed that its reply is a chain of reasoning followed by an action, so the draws build the whole reply word by word. Run the same prompt twice and the draws may differ.

Two settings shape the draw. Temperature T stretches or squeezes the list of probabilities: at T = 1 the model’s own probabilities are used unchanged, below 1 the favourites win more often, and above 1 the rare words get a bigger share. Nucleus sampling, also called top-p, first drops the unlikely tail. It sorts the words from most to least likely, keeps the shortest list whose probabilities add up to at least p, and draws only from that list.

Here is a worked case. Five actions have probabilities 0.50, 0.25, 0.15, 0.06 and 0.04. With p = 0.95, the first three add up to 0.90, which is below 0.95. Adding the fourth gives 0.96, which is enough. So the list keeps four actions and drops the fifth. The four are then rescaled to add up to 1: the first becomes 0.50 / 0.96 = 0.52.

The paper uses temperature 1.0 and top-p 0.95 for all action sampling. This keeps real variety while cutting the wild, near-impossible choices.

Twenty draws, then a vote

At each step of search the agent prompts the model with chain-of-thought reasoning and asks for 20 outputs. A chain of thought is a short written reasoning before the answer, which usually helps the model decide. Each output ends in one action. The program parses the 20 actions and counts how often each one appears.

count(a)
How many of the 20 draws chose the action a. Counts add up to 20.
∑j=120
Add over the 20 draws, from the first (j = 1) to the last (j = 20).
1[aj = a]
The indicator: 1 if draw number j was action a, and 0 if it was not. Summing indicators counts matches.
top-b
Keep the b actions with the largest counts. The paper sets the branching factor b to 5.

Take a worked example. Suppose the 20 draws give: click [35] nine times, click [34] five times, click [33] three times, type [5] twice and scroll once. The counts add up to 9 + 5 + 3 + 2 + 1 = 20. With b = 3 the branches are click [35], click [34] and click [33], in that order. The first branch is also the action a single draw would most often give.

This links back to Chapter 0. A no-search agent makes one draw. If the right action holds a 50% share, that agent is right half the time. A search agent keeps the right action in play whenever it appears often enough to make the top b. That is a much weaker demand.

Notice what the vote ignores. Two replies may reason in different words and still end in the same action. The program counts only the final action, so both replies add to one tally. The reasoning is only there to help the model reach a good action.

In code, the whole branching step is one request that asks for many replies. The data flow is short: one prompt goes in (a screenshot and up to 3,840 tokens of text), twenty replies come out, and a counter turns them into a ranked list of actions.

pythonreplies = lm.generate(prompt, n=20, temperature=1.0, top_p=0.95)   # 20 strings
actions = [parse_action(r) for r in replies]                    # e.g. "click [35]"
counts  = Counter(actions)                                          # {"click [35]": 9, "click [34]": 5, ...}
branches = [a for a, _ in counts.most_common(b)]                     # b = 5 in the paper

Draw twenty, keep the top b

The task is “add this item to the compare list”. The right action is click [35]. Set how much of the model’s probability it holds and how many branches you keep, then press Draw 20.

15%
5

Illustrative: eight made-up actions whose probabilities we chose, with the right action holding the share you set and the other seven holding fixed shares of the rest. The paper’s values are 20 draws, b = 5, temperature 1.0 and top-p 0.95. The draws here use temperature 1.0 and skip the top-p cut.

When the right click never shows up

Symptom. The search runs its full budget and still ends on a wrong page. Measurement. Look at the branches at each page: is the right action among them? An action with a 5% share appears in 20 draws with chance 1 − 0.9520 = 64%. At a 2% share the chance is 1 − 0.9820 = 33%. A rare right action is often missing, and a missing branch cannot be searched. Fix. Raise b so that thin counts survive, or improve the prompt so the right action holds a bigger share.

Search can only choose among the branches it is given. It makes good use of a decent proposal list. It cannot invent a click the model never thought of.

Twenty draws give: click A 8 times, click B 6 times, click C 4 times, click D 2 times. With b = 3, which are the branches?

Chapter 3

The Value Function: A Judge for Pages

Score any page between 0 and 1 by asking a second model and averaging twenty opinions

You are hiking with a friend who has a map and you do not. At each junction you walk a few steps down one path. Your friend looks at where you are and says one of three things: “We have arrived”, “Not there yet, but this is the right way”, or “Wrong turn”. With only those three answers you could still choose the next path well.

Search needs exactly this friend. To decide which page to explore next, it must be able to say how promising a page is. In chess the program counts pieces. A website has no piece count. So the paper asks a second language model call to play the friend.

The value function

A value function is a rule that turns a situation into a number that says how good it is. Here the situation is a page that the agent has reached. The number is the estimated chance that the task ends in success from there, a score from 0 to 1.

vt
The score of the page the agent is on at step t. Near 1 means the goal looks reached. Near 0 means the agent looks lost.
fv
The value function. In the paper it is a multimodal language model that is prompted, not trained.
I
The instruction: the task in plain words, such as “Find the cheapest red Toyota under $2000”.
{o1, …, ot}
All the observations so far, in the paper’s setup the last d screenshots, where d is the search depth. The judge sees the path, not only the final page.

Why use the observations and not the true state? The state of the website may hold private facts, such as database rows, that the agent cannot read. The judge must work from what the agent can see.

What the judge is shown, and what it says

The judge is a call to a multimodal model (GPT-4o in the main runs). Its prompt holds the task, the last d screenshots of the trajectory (d is the search depth), the actions taken so far, the agent’s last reply and the current URL. The system message sorts tasks into three kinds and says what success means for each. For a question, the reply must be a stop action with the correct answer. For a navigation task, the final screenshot and URL must show the right page. For a change to a site, the agent must really commit it: a review that is typed but never posted counts as a failure.

The judge writes its reasoning, then fills in two fixed lines: Status (success or failure) and On the right track (yes or no). The program turns these into a number.

The judge saysScoreMeaning
Status: success1The goal looks reached
Status: failure, on the right track: yes0.5Not done, but heading the right way
Status: failure, on the right track: no0A wrong turn
Reply in a broken format0Counted as failure

Three levels are still coarse. One call can flip between 0, 0.5 and 1 from run to run. The search compares scores of many pages, so a coarse and noisy score would send it the wrong way.

Twenty opinions beat one

The paper borrows self-consistency: ask the same question many times with randomness on, and combine the answers. Here it samples 20 reasoning paths from the judge (temperature 1.0, top-p 1.0) and takes the average score. Averaging is the same trick you used in Chapter 2, now used to smooth a score.

v
The final score handed to the search.
1/n
One divided by the number of opinions. The paper uses n = 20.
∑ sj
Add up the scores of the n separate reasoning paths.
sj
The score from path number j: 0, 0.5 or 1, as in the table above.

Work an example. Of 20 opinions on one page, 12 say “wrong turn” (0), 5 say “right track” (0.5) and 3 say “success” (1). The sum is 12 × 0 + 5 × 0.5 + 3 × 1 = 5.5, and the mean is 5.5 / 20 = 0.275. A side effect is useful: with n = 20 the mean can take 41 different values, from 0 to 1 in steps of 0.025. That fine ladder lets the search rank pages that one call could not tell apart.

Poll the judge

Two pages: one is on the right track, one is a wrong turn. Choose how many opinions the judge averages, then press Ask 40 times. Each dot is one score the search would have received.

Illustrative: we made the judge’s opinions random. For the on-track page it says 0, 0.5, 1 with chances 25%, 40%, 35%. For the wrong page the chances are 65%, 25%, 10%. The ranking rate counts 400 random pairs; a tie counts half. The paper’s numbers are in the read-out: GPT-4o agent success on 200 VisualWebArena tasks (Table 4).

What the ablation shows

Table 4 of the paper swaps the judge and measures how often the final agent succeeds, on a 200-task subset of VisualWebArena. With no search the agent scores 24.5%. A weaker open judge, LLaVA-1.6-34B with 20 opinions, lifts it to 30.0%. GPT-4o with a single opinion gives 28.5%, with 5 opinions 32.5%, with 20 opinions 37.0%. A perfect judge, the benchmark’s own 0 or 1 reward, would give 43.5%. So the judge matters a great deal, and the paper’s own judge leaves 6.5 points of room.

Failure mode. The symptom: search burns its budget on pages that look fine but are not. The measurement: compare the judge’s scores with the true reward on known runs. The fix: average more opinions, show the judge more screenshots, or use a stronger model. The paper also notes that this judge is built for the web and leans on screenshots. A different domain, such as code, would need its own judge, for example one that reads execution traces.

Ten of the judge’s 20 opinions on a page are 0, six are 0.5 and four are 1. What score does the search receive?

Chapter 4

Best-First Search on the Real Web

Run the loop: pop the best page, score it, branch from it, and repeat until the budget or the threshold stops you

You are hunting for a lost key in a big house. You write each place you could look on a sticky note, and you rank the notes by hope: “coat pocket” high, “attic” low. You always take the highest note off the pile and go look. If the place is a dead end, you take the next highest note, even if it is in another room. When you find the key you stop. When you run out of patience you take the most promising place you found.

That is the whole search. The pile of notes is called the frontier. This chapter turns the story into the algorithm.

Three ways to explore a tree

A tree can be explored in different orders. Breadth-first search checks every page one click away, then every page two clicks away, and so on. It is fair but slow when pages have many links. Depth-first search follows one path to its end before it tries another. It is quick but can waste time on a bad path. Best-first search asks at every moment: which waiting page looks most promising? That page goes next.

Best-first needs a way to keep waiting pages sorted. A priority queue does this. It is a list that always hands you the item with the highest priority. Taking the top item off is called a pop. The paper uses a max priority queue, where a larger score means a higher priority. It says its search is “loosely inspired by” A* search, a classic algorithm that also uses a score to choose what to explore.

The loop, one step at a time

The search has four settings. The depth d is how many clicks deep the tree may go. The branching factor b is how many clicks to try from each page. The budget c is the most pages the search may score. The threshold θ is the score at which the search is sure enough to stop. The paper sets d = 5, b = 5, c = 20, and the threshold is not given as a number in the text. Our toy uses θ = 0.9.

Here is one pass of the loop, starting from the page the agent is on now.

  1. Pop. Take the waiting page with the highest priority off the frontier.
  2. Go there. Reach that page in the live site (Chapter 5 shows how).
  3. Score. Ask the judge for the page’s score v. Add one to the counter s.
  4. Keep the best. If v is higher than the best score so far, remember this page as the best.
  5. Check the stops. If v is at least θ, stop: the goal looks reached. If s has reached c, stop: the budget is spent.
  6. Branch. Otherwise, if the page is fewer than d clicks deep, draw b actions (Chapter 2), carry each out, and put each new page on the frontier.
vp
The score of the page just popped, p. A child page spi joins the frontier F with this score as its priority.
θ
The termination threshold. A score at or above it means the goal is likely found.
s
The search counter: how many pages have been scored so far.
c
The search budget: the most pages that may be scored. In the paper, c = 20.

One detail surprises many readers. A new child page joins the frontier with its parent’s score, not its own. It has not been judged yet. The paper does it this way because judging a child at once would force many extra resets of the site, which is slow. So a child is scored only when it is popped. The parent’s score is a guess that the child is about as good.

When the loop ends, the agent empties the frontier, resets the counter, walks to the best page found, and takes the clicks that lead there. Then it searches again from its new position. The paper runs this at each step of execution, and caps a whole run at 5 actions.

Work the toy tree below by hand first. The start page scores 0.10. It has three children. The first is scored 0.35, so its three children join the frontier at priority 0.35. The first of those scores only 0.20, a dead end. The frontier now holds two pages at 0.35, three at 0.20 and two at 0.10. The search pops a 0.35 page, the sibling of the dead end, and skips the whole 0.20 group. Step through it yourself.

Step the search

Press Step to run one pass of the loop. The tree shows scored pages in purple with their scores. The row below shows the frontier, best priority first. Try both budgets.

Illustrative: the tree and its scores are ours, chosen to show a dead end and a backtrack. The rules are the paper’s: a max priority queue, children enter with the parent’s score, stop at the threshold or at the budget, then go to the best page found. Ties pop in the order they joined. The toy threshold is 0.9, and the tree is 3 clicks deep with 3 branches.

Where the paper and the pseudo-code differ

A careful reader meets small mismatches. The text starts the best score at 0 and updates it when a score is strictly higher. Algorithm 1 starts it at minus infinity and updates on “higher or equal”. The text also starts with an empty frontier, yet Algorithm 1 pops from it at once, so the start page must be on it. Our reading, used in the toy: put the start page on the frontier, and let a tie move the best page to the newer one. For a re-implementation, choose these two rules and say so in your write-up.

Failure mode. The symptom: the agent stops early on a wrong page. The measurement: log every score that reached θ and check it against the true reward. The fix: a stricter judge prompt, more opinions per score, or a higher θ. The mirror symptom is a budget spent on dead ends, which a better judge or a smaller b helps.

The frontier holds pages with priorities 0.20, 0.35, 0.10 and 0.35 (the 0.35 pages joined in that order: the first 0.35 first). What does the search do next?

Chapter 5

Backtracking by Replaying

Reset the site and replay the saved clicks, because the back button forgets

You are filling in a long form on your phone. You type your address, scroll down to the next section, and tap a link by mistake. You press the back arrow. The form comes back, but the address box is empty and the page jumped to the top. The browser gave you the page, not your work.

A search agent has this problem at every step. It scored a page, and now it wants to try the sibling branch. To do that it must stand on the parent page again, exactly as it was. If the return is not exact, the next branch is tried in a different world, and the score means nothing.

Why the back button is not enough

The environment offers a go_back action. It looks like the obvious undo. The paper warns that it is not: it may discard important information on the page, such as the scroll position and the text already typed into boxes. The agent’s next move may depend on exactly those things. A search that backtracks with go_back would sometimes explore a page that is not the one it meant.

Reset and replay

The paper uses a blunter tool. For every waiting page on the frontier, the program stores the recipe that leads there: the list of actions from the start. To visit a page, it follows three steps.

  1. Reset. Put the environment back in its initial state, for example the homepage with a clean session.
  2. Replay. Carry out the stored actions one by one, in order.
  3. Arrive. The environment now stands on the target page, and the program reads its observation.

This works because of the property from Chapter 1. The transition function T is deterministic: the same state and the same action always give the same next state. Replay the same recipe from the same start and you land on the same page, with the same typed text and the same scroll position. That is a far more complete reset than a back button can give.

pythondef go_to(env, actions):
    env.reset()                      # initial state: homepage, clean session
    for a in actions:                # replay the recipe, one action at a time
        env.step(a)
    return env.observe()             # screenshot + element list of the page we reached

# each frontier entry is (priority, recipe), where recipe is e.g. ["click [35]", "type [5] guitar"]

Count the cost. A page that sits k clicks from the start needs one reset and k actions to visit. Take the toy search of Chapter 4. It popped five pages, at depths 0, 1, 2, 2 and 3. Replay therefore carried out 0 + 1 + 2 + 2 + 3 = 8 actions after the resets. With the paper’s settings (depth 5, budget 20), the worst case is 20 visits of 5 actions each, 100 actions in all. Each action is a real browser step, so this is slow. The paper says plainly that its reset method does “add significant overhead in terms of time”.

Here is a recipe in full. Page “010” in the toy tree of Chapter 4 is the third click on the path 0, then 1, then 0. In a real site, its recipe could read ["click [35]", "click [12]", "click [7]"]. To visit it, the program resets, then runs those three strings in order. Nothing in this replay asks the language model a question. The actions are already chosen, so a replay costs browser time but no model calls.

Replay also runs when the search expands a page. The program draws b actions from the model, then carries each one out once to see which page it leads to. After each one it resets again, so that the next child starts from a clean parent page. So a single expansion with b = 5 means five short trips from the start, one for each child. The paper notes that this raises the fidelity of the reset, at a heavy cost in time.

Try both ways of going back in the device below. It uses a three-step errand: type a search, scroll, click a result. Then it returns to the page before the click.

Go back to the parent page

Press Do the errand to type, scroll and click. Then pick a way to return and press Go back. Compare the page you return to with the page the search needs.

Illustrative: a made-up three-field page. The behaviour is the paper’s claim in Section 5.4: go_back may discard the scroll offset and typed text, while replaying the saved actions from a reset restores them. The action counts are exact for this errand.

When replay itself goes wrong

Symptom. After a replay, the page differs from the one that was scored, so the score and the branches no longer match. Measurement. The paper does not report one. A cheap check, our suggestion, is to compare the address and a hash of the element list before and after each replay. Fix. Drop the branch if the check fails, and avoid sites where the same clicks give different pages, for example pages with random content.

Replay also does not repair destructive actions, such as placing an order. Reset can clear a test copy of a site, as the paper’s benchmark does. It cannot un-send a real order. Chapter 8 returns to this limit.

Last, notice what is stored: only action recipes, never copies of the whole site. The frontier stays small and simple. The price is time spent re-walking the same early clicks again and again.

The search pops a page that is 4 clicks from the start. How many environment actions does the paper’s backtracking carry out to reach it, after the reset?

Chapter 6

Depth, Branching and Budget

Turn the three size knobs of the tree and read what each one costs and buys

You have an hour to find a prize in a maze of rooms. You can decide three things. How many doors to try in each room (width). How many rooms deep to go before you turn back (depth). And how many rooms you will look into in total before the hour ends (budget). A wide, deep search with a small budget is thin everywhere. A narrow, shallow search with a big budget repeats itself.

The paper's search has these same three knobs. This chapter shows what each one controls, what the paper measured, and what each one costs.

How big is the tree?

The branching factor b is the number of clicks tried from each page. The depth d is the most clicks from the start that the tree may reach. The budget c is the most pages the search may score. The first two set the largest tree that could exist. The third says how much of it you may look at.

N(b, d)
The number of pages in a full tree: the start page plus every page you could reach.
∑k=0d
Add up one term for each level of the tree, from level 0 (the start) to level d.
b
The branching factor. Each page has b children, so level k has b multiplied by itself k times.
k
The level, that is, the number of clicks from the start.

Work the paper’s setting, b = 5 and d = 5. Level 0 has 1 page, level 1 has 5, level 2 has 25, level 3 has 125, level 4 has 625 and level 5 has 3,125. The total is 1 + 5 + 25 + 125 + 625 + 3,125 = 3,906 pages. The budget c = 20 allows the judge to score 20 of them, about 0.5%. Best-first search is what makes that 0.5% a smart choice and not a random one.

What the paper measured

The ablations use a 200-task subset of VisualWebArena and the GPT-4o agent. The baseline, with no search, solves 24.5%.

First, the budget c. With d = b = 5, a budget of 5 raises success to 32.0%, a relative gain of 30.6%. A budget of 20 gives 37.0%, a gain of 51.0%. Figure 2 plots c = 0, 5, 10, 15 and 20, and shows success generally rising. The text prints numbers only for 5 and 20.

Second, depth and branching, at c = 20 (Table 3). Growing the tree on either axis helps, and both are needed for the best result.

Depth dBranching bSuccess rateGain over no search
0 (no search)124.5%0%
1326.0%+6%
1532.0%+31%
2331.5%+29%
2535.0%+43%
3535.5%+45%
5537.0%+51%

Table 3 of the paper: GPT-4o agent, 200 VisualWebArena tasks, budget c = 20.

Look for patterns. Going from b = 3 to b = 5 at depth 1 adds 6 points (26.0 to 32.0). That fits Chapter 2: a wider list is more likely to hold the right click. Going deeper at b = 5 adds smaller steps: 32.0, 35.0, 35.5, 37.0. Notice also that depth 1 with b = 5 and a budget of 5 (Figure 2) both give 32.0%, though the paper does not claim they are the same thing.

Size the tree

Choose a shape from Table 3 and slide the budget. The top bars show the paper’s success rates for each shape. The bottom bars show the budget. Teal marks your choice.

20

Success rates are Table 3 (shapes, at c = 20) and Section 5.1 (budgets, at d = b = 5). Budgets 10 and 15 appear in Figure 2 only, with no printed number, so the bar is hollow. The page counts use the formula in this chapter; the call count is the paper’s own upper bound.

How to choose the knobs

The paper does not give a recipe, but its evidence points the way. Pick the depth from the length of the tasks you care about. A depth of 5 reaches the middle of the VisualWebArena tasks, those that need 4 to 9 human actions, and the paper links that to its biggest gain (Chapter 7). Pick the branching factor from how often the right click is missing from the model’s list (Chapter 2). Then set the budget from the time and money you can spend, since it is the knob that sets the bill. The paper says that for practical use one must “carefully set” all three to balance quality against time.

What it costs

Each page the search scores needs one judge call (20 sampled opinions), and each page it expands needs one action draw (20 sampled replies). The paper puts the price plainly: a budget of c = 20 means “up to 20× more LM calls” than an agent without search. It also estimates that, for the GPT-4o agent, one action prediction costs about twice as much as one value computation, because the action prompt carries more text and worked examples.

There is a quieter benefit. The paper caps every run at 5 actions, far below the 30 allowed to the baselines. Even so, GPT-4o with search (26.4%) beats the same GPT-4o without search given 30 actions (19.8%). Search is a better use of compute than simply allowing more steps.

Failure mode. The symptom: each extra look buys less. The measurement: the first 5 looks lifted success from 24.5% to 32.0%, 1.5 points per look. The next 15 looks lifted it from 32.0% to 37.0%, about 0.33 points per look. The fix: stop where the next look is no longer worth its cost, and for hard tasks think about depth, since a depth-5 tree cannot reach a goal that needs ten clicks.

A full tree has branching factor 3 and depth 3. How many pages does it hold, counting the start page?

Chapter 7

What the Tables Show

Read the main results by model, by difficulty and by website

A report card lists marks, but the marks only mean something next to a baseline. “Ana scored 80” says little. “Ana scored 80, up from 60, with the same teacher and the same exam” says a lot. This chapter reads the paper’s tables the second way: always with the baseline next to the new number.

Reading the main table

The setup is clean. The paper takes an existing agent and a fixed prompt, and changes one thing: whether search is on. It runs the full benchmarks, 910 VisualWebArena tasks and 812 WebArena tasks. A success rate (SR) is the share of tasks the checker marks as solved. A relative change (the Δ column) is the gain as a share of the baseline: (26.4 − 18.9) / 18.9 = 39.7%. In points the gain is 7.5.

On VisualWebArena, GPT-4o with the Set-of-Marks screenshot goes from 18.9% to 26.4%. That is a new best at the time of writing, per the paper, ahead of the earlier agents it lists (ICAL at 23.4%, and the same GPT-4o agent given 30 steps at 19.8%). On WebArena, text-only GPT-4o goes from 15.0% to 19.2%, a relative gain of 28.0%.

Weaker models gain more. Llama-3-70B-Instruct, with image captions, goes from 7.6% to 16.7% on VisualWebArena, a relative gain of 119.7%. With search it comes close to the best frontier models that do not search. On WebArena, text-only Llama-3 goes from 7.6% to 10.1%, a gain of 32.3%. Table 8 in the appendix repeats the test with more models, and the gain stays large: GPT-4o-mini rises from 9.1% to 14.4% (+58.2%), and Llama-3-70B with the open LLaVA-1.6-34B as the judge rises from 7.6% to 13.5% (+77.6%). That last setup is fully open source and can be reproduced without any paid model.

One honest limit stands out. On WebArena, other published agents reach much higher, up to 45.7%, with techniques tuned to the sites, such as site-specific guidelines or a better input format. The paper calls these methods orthogonal, which means they work on a different part of the problem and could be combined with search. It does not claim to beat them.

Where the gain falls

The benchmark labels each VisualWebArena task with an action difficulty: easy tasks need 3 or fewer human actions, medium tasks need 4 to 9, and hard tasks need 10 or more. Search helps at every level, but not equally. The medium tasks gain most: 12.7% to 22.2%, a relative gain of 75%. Easy tasks gain 24% (34.2% to 42.3%) because they often need little planning. Hard tasks gain 47% (10.2% to 14.9%). The authors suggest the depth cap of 5 suits medium tasks, and that hard tasks may need deeper trees.

By website, every site improves. On VisualWebArena the largest gains are on Classifieds (+44%) and Shopping (+45%), and the smallest is on Reddit (+20%). On WebArena the largest is the CMS site (+50%). The paper notes that its judge relies heavily on screenshots, which may be why the gain is bigger on the visual benchmark than on the text benchmark.

Read the tables

Choose a table. Each pair of bars is one row: the baseline without search, then the same agent with search. Tap a row name to read its numbers.

All values are the paper’s: Tables 2 and 8 (models), 5 (difficulty), 6 (VisualWebArena sites) and 7 (WebArena sites). Model rows use the paper’s printed relative change; the others are computed from the two rates. The paper prints one number per cell and no error bars in the tables we read.

Three stories from the figures

Numbers hide the mechanism, so the paper shows runs. In shopping task #256 the agent must add two canned fruits of one brand to a compare list. The baseline adds the first item, then returns to the homepage at step 3 and gets confused. With search, the agent adds the first item, types a search query, and adds the correct second item. The extra branches let it find a route the single path missed.

In classifieds task #48 the agent must find a post that shows an exact picture. Taking the first sampled action at every step fails. Search tries several, and the judge’s scores steer it back from bad ones. Shopping task #96 shows the same pattern: the baseline fails, and the search prunes weaker branches to reach a success. All three share one cause. The first sample is not always the best action, and trying clicks in the live site gives evidence that thought alone cannot.

Reading traps. A big relative gain from a small base looks larger than it is: +119.7% for Llama-3 is 9.1 points. Compare the end rates too. Also check what was held equal: here the model, the prompt and the benchmark, with an action cap of 5 for search runs.

A worked read shows why the weaker-model result matters. Without search, Llama-3-70B scores 7.6% and GPT-4o scores 18.9% on VisualWebArena, a gap of 11.3 points. With search, Llama-3-70B reaches 16.7%, which closes 9.1 of those 11.3 points, about 80% of the gap. Extra answer-time compute made a smaller model act almost like a larger one.

Which task group gained most from search on VisualWebArena, and what is the paper’s explanation?

Chapter 8

Ablations and Limits

Find out which parts carry the gain, and where search breaks

When a new engine is bolted onto a car, the test is simple: take the engine out and see if the car still goes as fast. An ablation does this for a method. It removes or swaps one part and measures what is lost. The parts of the paper’s search are the branches (Chapter 2), the judge (Chapter 3), and the search shape and budget (Chapter 6). This chapter adds the one comparison we have not seen yet, then turns to where the method breaks.

Why search a tree, and not just try the whole task many times?

There is a simpler way to spend extra compute. Run the agent n times from the start to the end, with random draws, so each run is a full trajectory. Score every finished trajectory with the same judge, and commit to the best. This is trajectory reranking. It uses the same judge and the same sampling as the tree search.

The paper tests it on the 200-task subset. Reranking improves with more runs but flattens out near 7 runs, at a success rate of about 30%. Tree search with a budget of only c = 5 reaches 32.0%. At the equal spending of n = 5 runs and c = 5 looks, tree search is ahead. With c = 20, it reaches 37.0%.

Method (GPT-4o agent, 200 VWA tasks)Success rate
No search24.5%
Trajectory reranking, about 7 runs (it flattens here)about 30%
Tree search, c = 5 (similar compute to 5 runs)32.0%
Tree search, c = 2037.0%

From Section 5.1 and Figure 3 of the paper. The 30% figure is read from the text; the plot is the source for the full curve.

Do the sums. Seven full runs lift success by about 5.5 points, from 24.5% to about 30%. Five looks of tree search lift it by 7.5 points, to 32.0%. A plausible reason, ours and not the paper’s: reranking pays to finish every run, even the ones that went wrong in the first click, while tree search drops a bad branch as soon as the judge scores it low.

The paper gives two reasons. First, reranking cannot backtrack. It can only judge a whole run after the fact, so it cannot prune a bad branch halfway. Second, reranking must carry each run to the end before the judge can look. If a run contains a harmful step, such as buying something, the harm has already happened. Tree search can check a page before it goes further.

Limit one: it is slow

Search spends answer-time compute. A budget of c = 20 can mean up to 20 times more model calls. Replay (Chapter 5) adds browser time on top. The paper expects better inference engines to help, and it advises setting b, d and c with care. For a user waiting on an agent, this is a real cost.

Limit two: destructive actions

A destructive action changes a site in a way that is hard or impossible to undo. Placing an order is the paper’s example. In a benchmark the site is a test copy, so a reset wipes the damage. On a live site it does not. A worry of ours, not a result from the paper: the judge may rate an “order placed” page highly, since it looks like a finished task, and a search that follows high scores would be drawn to it.

The paper offers three ways out. A classifier can predict which actions are destructive and block expansion of those pages. Manual rules can fence off pages that are off limits. A world model, a learned simulator of what the site would do, could let the search imagine actions without doing them. The paper adds that tree search makes this constraint easy to add, because the value function can simply score a destructive branch as zero. Offline tasks where everything can be reset, such as programming or spreadsheets, suit search better.

Guard the destructive click

The search explores a toy shop. One page, “Place order”, cannot be undone on a live site and the judge scores it high. Choose whether a gate blocks destructive pages, then press Run the search.

Illustrative: a four-page toy and scores we chose. The paper’s suggestion (Section 5.4) is a classifier that predicts destructive actions and stops expansion of those states, or a value function that scores them as unsafe. We did not implement the paper’s classifier; the gate here is a flag on one page.

Limit three: the judge is built for the web

The judge reads screenshots and navigation history. For software engineering agents, the better signal is the output of running code, so the judge would have to change. The paper leaves that for future work, and names Monte Carlo tree search as a richer search for later.

Failure mode. The symptom: the logs of a live site show orders, posts or deletions made during a run that was supposed to be exploring. The measurement: count state-changing requests per task in the site log. The fix: the gate above, plus a sandbox or test account for any search that runs against a real service.

The paper also lists broader risks: sharper phishing or scraping tools, privacy, effects on work, and bias inherited from the model. Its own point is that the value function can carry safety rules as well as success scores.

Why does the paper say trajectory reranking is less practical than tree search for real sites?

Chapter 9

The Field Guide

Keep the numbers, the terms, the checklist and the core code of the paper on one page

Here is the whole paper in one breath. A web agent that commits to its first idea at every click is wrong too often, and the errors pile up. The paper adds an answer-time search around any such agent. The agent proposes a few clicks (Chapter 2). A second model call scores each page it reaches (Chapter 3). A best-first search always explores the highest-scoring waiting page next, stops at a threshold or a budget, and walks to the best page it found (Chapter 4). The site is reset and the saved clicks replayed to go back (Chapter 5). On 910 VisualWebArena tasks this lifts GPT-4o from 18.9% to 26.4%. The price is up to c times more model calls.

The numbers to keep

WhatValueWhere
Search settingsdepth d = 5, branching b = 5, budget c = 20, at most 5 actions per runSection 4.1
Action draws20 chain-of-thought outputs per page, temperature 1.0, top-p 0.95, keep the top b by countSection 4.1
Judge20 reasoning paths (temperature 1.0, top-p 1.0), scores 1 / 0.5 / 0, averaged; GPT-4oSection 4.1, A.3.2
Input sizesviewport 1280 by 2048 pixels; text cut to 3,840 tokensA.3.1
BenchmarksWebArena 812 tasks; VisualWebArena 910 tasks; people 78% and 89%Sections 1, 2.1
GPT-4o, VWA18.9% to 26.4% (+39.7%)Table 2
GPT-4o, WA15.0% to 19.2% (+28.0%)Table 2
Llama-3-70B, VWA and WA7.6% to 16.7% (+119.7%); 7.6% to 10.1% (+32.3%)Table 2
Budget (200 VWA tasks)24.5% with no search; 32.0% at c = 5; 37.0% at c = 20Figure 2, 5.1
Judge ablationLLaVA 30.0%; GPT-4o 28.5% (1 opinion), 32.5% (5), 37.0% (20); true reward 43.5%Table 4
Reranking vs treereranking flattens at about 30% near 7 runs; tree search 37.0% at c = 20Figure 3
By difficultyeasy +24%, medium +75%, hard +47%Table 5
Costup to c times the LM calls; action call about 2 times a value call5.4, footnote 4

The words to keep

TermPlain meaning
State, observationEverything the site holds; the part of it the agent can see
FrontierThe pile of waiting pages, kept as a max priority queue
PopTake the highest-priority waiting page off the frontier
Value functionA judge that scores a page from 0 to 1
Self-consistencyAsk many times with randomness on, then average or vote
Branching factor b, depth d, budget c, threshold θClicks tried per page; clicks deep; pages scored; score at which to stop
Backtracking by replayReset the site, then redo the saved clicks
Destructive actionA click whose effect is hard or impossible to undo

Where it is hard to go wrong, and where it is easy

Use this device as a quick diagnosis. Pick the symptom that you see in a search agent. It tells you the chapter and the first thing to measure.

Diagnose a search agent

Pick what you see. The card names the cause the paper points to, what to measure, and what to change.

The causes and fixes come from the paper’s analysis, Sections 4 and 5. The measurements are our suggestions for checking each cause, not tests the paper ran.

The checklist for a re-implementation

  1. Base agent. Any prompt-based agent that gives one action per call. Add nucleus sampling so you can draw many different replies.
  2. Proposals. Draw 20 replies, parse each to an action, count, keep the top b = 5.
  3. Judge. Prompt a multimodal model with the task, the last d screenshots, the actions and the URL. Parse status and on-track. Map to 1, 0.5, 0. Average 20 samples.
  4. Frontier. A max priority queue of (score, recipe). Children enter with the parent’s score. Decide your tie rule and your start-state rule, and write them down.
  5. Reset and replay. Reset to the initial state, replay the recipe, and check you landed where you meant to.
  6. Stops. Stop at the threshold or at the budget c. Go to the best page found. Repeat the search from there, up to the action cap.
  7. Guard. Block expansion of destructive pages. Use a test site.
  8. Measure. Report the baseline with the same cap on actions, and the number of model calls per task.

The core as code

pythonimport heapq, itertools
from collections import Counter

def propose(lm, task, obs, b=5, n=20):
    replies = lm.generate(prompt(task, obs), n=n, temperature=1.0, top_p=0.95)   # n strings
    counts = Counter(parse_action(r) for r in replies)                 # action -> count
    return [a for a, _ in counts.most_common(b)]                       # the branches

def value(judge, task, history, n=20):
    scores = []
    for text in judge.generate(judge_prompt(task, history), n=n, temperature=1.0, top_p=1.0):
        ok, on_track = parse_judge(text)                         # bad format -> (False, False)
        scores.append(1.0 if ok else 0.5 if on_track else 0.0)
    return sum(scores) / n                                       # in [0, 1]

def go_to(env, recipe):
    env.reset()
    for a in recipe: env.step(a)
    return env.observe()

def tree_search(env, lm, judge, task, prefix, d=5, b=5, c=20, theta=0.9):
    tie = itertools.count()
    frontier = [(-1.0, next(tie), prefix)]          # (-priority, tie-break, recipe); start page first
    best_v, best, looked = -1.0, prefix, 0
    while frontier and looked < c:
        _, _, recipe = heapq.heappop(frontier)                   # 1 pop the best waiting page
        obs = go_to(env, recipe)                                 # 2 reset and replay
        v = value(judge, task, obs.history); looked += 1   # 3 score it
        if v >= best_v: best_v, best = v, recipe             # 4 keep the best (ties move on)
        if v >= theta or looked >= c: break                # 5 stop rules
        if len(recipe) - len(prefix) < d:                     # 6 branch
            for a in propose(lm, task, obs, b):
                heapq.heappush(frontier, (-v, next(tie), recipe + [a]))   # child gets the parent's score
    return best

def run_agent(env, lm, judge, task, max_actions=5):
    done = []
    while len(done) < max_actions:
        plan = tree_search(env, lm, judge, task, prefix=done)
        if plan == done or plan[-1].startswith("stop"): done = plan; break
        done = plan                                              # walk to the best page found, then search again
    return done

Our compact version of Algorithm 1. One difference: the paper executes each child’s action when it adds the child, and we defer that to the pop, which gives the same recipes with fewer trips. The threshold value 0.9 is our choice; the paper does not print one.

Read it line by line and name the chapter behind each choice. The proposal step is Chapter 2. The judge is Chapter 3. The six numbered lines in tree_search are the loop from Chapter 4. go_to is Chapter 5. The defaults d, b, c are Chapter 6.

Where this sits

This paper is the reading for the Multimodal Interaction lecture of MIT MMAI, where agents that see, plan, search, remember and act are the topic. It stands on a line of work: ReAct and chain of thought for reasoning before acting, self-consistency for voting over samples, and the game-search tradition of A*, Deep Blue and Monte Carlo tree search. Its twist is to run the search in the live environment, with a model as the judge.

Keep going

Credit

The paper is “Tree Search for Language Model Agents” by Jing Yu Koh, Stephen McAleer, Daniel Fried and Ruslan Salakhutdinov of Carnegie Mellon University, published in Transactions on Machine Learning Research (2025). Read it at arXiv 2407.01476; the authors release code and models at jykoh.com/search-agents. Every number here is theirs unless a device says it is a toy. The wording, the diagrams and the toy worlds are ours.

The takeaway. A language model agent gets more reliable when it may try before it commits. Propose a few clicks, let a judge score the pages they reach, explore the best one next, and back up by replaying. The gain grows with compute, so the real question is how many looks each task is worth.

Now press Present or Teach and explain the loop out loud from memory: what the frontier holds, why a child gets its parent’s score, and why the site is reset and replayed. Then go back to the tree at the top and run one task at each budget.

A friend says: “Tree search made the agent smarter, because the model was fine-tuned on search traces.” What is wrong?
Tree Search for Language Model Agents
Read the paper · Code and models · The lecture this paper belongs to · The course site · Back to Gleams