arXiv:2610.20334cs.AIOct 2026

Manuscript Offprint

arXiv:2610.20334

TreeFlex: Agents Navigating Their Own Search Trees

Dongzhuo Li, Fangzhou Cheng, Weiwei Li, Kevin Han, Haixu Ma, Zhongchang Sun, Ruiyi Li, Serena Li, Xiangjun Fan, Lizhu Zhang, Yuandong Tian

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Dongzhuo Li, Fangzhou Cheng, Weiwei Li, Kevin Han, Haixu Ma, Zhongchang Sun, Ruiyi Li, Serena Li, Xiangjun Fan, Lizhu Zhang, Yuandong Tian †^{\dagger}

Meta AI

†^{\dagger}Work done while at Meta

A ReAct-style agent accumulates observations, intermediate results, and failed attempts in a single context. As this context grows, stale and off-path information consumes its limited capacity and obscures relevant evidence, making focused reasoning increasingly difficult. We introduce TREEFLEX, a framework in which the agent's own policy decides where to search. The agent records each intermediate state, with a short summary, as a node in a search tree maintained by the harness. The policy is a single language model that acts in two roles. In the Reflection role, it has a global view of the tree through these summaries and picks a node to resume, together with an instruction. In the Execution role, the harness restores the path that led to that node, and the model carries out the instruction with the usual task tools until it saves a new node or proposes a solution, which Reflection then approves or sends back to another node. Through these choices, the policy decides whether to deepen the current line, branch from or revisit an earlier state, verify a proposal, or stop, without a fixed traversal order or a score for each node. We train navigation, task actions, checkpointing, and proposal review jointly with a tree-aware adaptation of GRPO, using task-level outcome rewards augmented by process rewards. After small-scale RL of a 4B model, with the same active-context limit for all methods, TREEFLEX reaches 48.8% accuracy on a challenging deep-research benchmark, versus 41.5% for flat REACT and 42.8% for FOLDAGENT, and its Pass@8 is about ten points higher than either. On SWE-bench Verified, with all three systems trained with RL from the same 9B model, TREEFLEX resolves 54.9% of tasks, versus 43.3% for FOLDAGENT and 45.2% for its step-wise variant.

Correspondence: Dongzhuo Li at lidongzh@meta.com

Meta

1 Introduction

On long-horizon tasks, an agent rarely reaches a solution in one straight path. Several candidate solutions may build on the same partial progress, a failed attempt may still reach a state worth resuming from, and later evidence may make an abandoned direction worth revisiting. In deep research, an agent may check several candidate answers against the same evidence and return to an earlier one that it had dismissed when a later document changes the picture. In agentic software engineering (SWE), it may try several fixes for the same reproduced bug and return to an earlier repository state when a later test implicates code it had set aside. Yet a standard REACT agent (Yao et al., 2023b) keeps all of this in one linear context. Every later model call then carries abandoned attempts and long off-path observations along with the evidence it needs, and undoing an attempt may also require undoing its effects on the environment. One remedy is to compress the history. Learned summarization and memory-consolidation methods select what past information remains available (Zhou et al., 2026; Li et al., 2026), but whatever they discard is gone for the rest of the episode. We instead keep several intermediate states that the agent can return to, and show the model only the context of the path it is currently working on.

Tree-search methods for language models make alternative states explicit (Yao et al., 2023a; Hao et al., 2023; Zhou et al., 2024), but having a tree does not tell the agent which branch to work on next. A hand-designed DFS, BFS, or MCTS controller imposes its own selection rule. A learned score for each node is more adaptive, but it evaluates each node in isolation, while its usefulness changes as other branches reveal new evidence and the search approaches its limits. A score also leaves open how to continue from the selected state. In

REFLECTION

global view: one card per node

Figure

B, B1B_{1}, A2A_{2} stay out of Execution's context

Figure 1 One TreeFlex search. Left: the search tree, numbered in creation order. Top: Reflection sees the task and a short card for every node. Although BB, B1B_1, and A2A_2 are newer, it calls navigate to resume A1A_1 with a new instruction. Bottom: the harness restores only the path r→A→A1r \rightarrow A \rightarrow A_1 and its saved state for Execution, so the other branches stay out of its context. Execution proposes PP, and Reflection then approves it. Both roles use the same model. In deep research, the restored path consists of cards and the saved state is empty. In SWE, the restored path is the raw context along the path, and the saved state is a repository snapshot.

other words, the useful decision is often a node paired with a plan for what to do there, not a node alone. We therefore ask whether the model that does the task can also make this choice, based on what the search has found so far.

A second question is how to train this behavior end to end. Standard agentic RL treats each episode as one growing token sequence with one final reward. A tree search breaks this assumption, because the model makes decisions from different saved states and therefore sees a different history each time. Concatenating all branches into one sequence would show the model histories it never saw during the search and bring back the long-context problem.

We introduce TREEFLEX, a framework that saves the agent's intermediate states as nodes of a search tree, each summarized by the model itself. The model works in two roles, Reflection and Execution (we later use each role's name for the model acting in that role). In Reflection, it receives the original task and a short summary of every node, which we call its card, and selects one node together with a focused instruction. The harness then restores the path to that node for Execution, where the model uses the usual task tools to carry out the instruction and either saves a new checkpoint or proposes a final solution. Reflection then either approves the proposal, which ends the search, or rejects it by selecting one node to continue from. Continuing from the current node deepens a line, while returning to an earlier node or the root starts a new branch from that state. In classical search terms, Reflection manages the frontier, which is the set of states from which search can continue. For example, best-first search keeps this frontier as an open list ordered by priority. However, unlike such a list, Reflection can return to states it has already expanded, and it pairs each choice with an instruction. Figure 1 shows one such search.

This design lets the search grow without any context having to hold every branch. Reflection's record grows by only one short card per node, and each Execution segment only sees one path. A node saves the environment state, such as a repository snapshot, as well as the raw prefix or a summary card for the segment, and returning to an earlier node restores the workspace. Therefore, the agent can use more compute to deepen a line, start a sibling, revisit earlier work, or verify a proposal without adding every explored branch to later Execution contexts.

Although the tree branches, the model's calls still happen one after another. We use this property to adapt GRPO (Shao et al., 2024). Each complete search counts as one rollout with one task reward, and each model output is trained on the exact context it was generated from, so no tree-shaped attention mask is needed.

We study TREEFLEX on deep research with BrowseComp-Plus (Chen et al., 2026) and on SWE with SWE-bench Verified (Jimenez et al., 2024; OpenAI, 2024). On the BrowseComp-Plus test split used by FOLDAGENT (Sun et al., 2026), we compare it with flat REACT, which keeps the whole history in one context, and FOLDAGENT under the same model and resource limits. Before RL, TREEFLEX has the highest accuracy at both 4B and 30B. After RL training of Qwen3-4B-Instruct-2507 (Qwen Team, 2025) with a 32k active-context limit, TREEFLEX reaches 48.8% accuracy, versus 41.5% for flat REACT and 42.8% for FOLDAGENT, and 66.0% Pass@8, versus 56.0% and 55.3%. On SWE, we train TREEFLEX and FOLDAGENT from Qwen3.5-9B with RL on SWE-Gym tasks (Pan et al., 2025) and select each run's training step on separate SWE-Gym validation tasks. TREEFLEX resolves 54.9% of tasks, versus 43.3% for FOLDAGENT and 45.2% for a FOLDAGENT variant with a step-wise delegation prompt that we wrote.

Our contributions are:

  • Policy-directed tree search. One model decides when to continue, branch, backtrack, verify, or stop, while the harness only saves and restores contexts and environment states.

  • Tree-aware policy optimization. We adapt GRPO to treat a complete tree search as one sampled rollout, train each model output on the exact context it was generated from, and combine the task reward with process penalties on the actions that caused them.

• Evaluation across two agent domains. On deep research, we compare three ways of organizing an agent's history, a single linear context (REACT), context folding (FOLDAGENT), and a search tree (TREEFLEX), under the same model and context limit. On SWE, we compare the complete FOLDAGENT and TREEFLEX systems. We report task success and resource use.

References (36)