WorksComputer Science
PTGPO: Prefix Tree Group Policy Optimization
Abstract
Training language agents on long-horizon interactive tasks is challenging because sparse terminal rewards provide weak credit signals for intermediate actions. Existing group-based methods either assign a shared trajectory-level advantage or estimate step-level advantages from state groups, which may conflate the current action with subsequent decisions. We propose Prefix Tree Group Policy Optimization (PTGPO), a critic-free method that constructs prefix trees over trajectory suffixes within anchor-state groups. PTGPO assigns each tree edge a credit given by the difference between its child and parent empirical mean returns, capturing the conditional return change revealed by each additional action. These prefix-tree credits provide fine-grained learning signals without requiring a critic or additional rollouts. Experiments on interactive benchmarks ALFWorld, WebShop and Sokoban show that PTGPO consistently improves over RL baselines, demonstrating its effectiveness.
Introduction
Recent advances [1, 2] in large language models (LLMs) have extended their capabilities beyond static text generation toward interactive reasoning and decision-making. LLM-powered agents can perceive, reason, and act across diverse environments, including embodied tasks [3, 4], web navigation [5, 6], and interactive games [7, 8]. Unlike single-turn generation, these applications require long-horizon planning and coherent sequences of actions, where intermediate decisions shape subsequent observations and task completion. Reinforcement learning (RL) provides a natural post-training framework for improving such agents through interaction and task-level feedback [9, 10, 11]. A central challenge is translating this feedback into effective learning signals for the individual decisions made throughout an episode.
Group-based reinforcement learning methods such as GRPO [12] have become an effective critic-free paradigm for LLM training, where multiple responses can be sampled for the same prompt and compared using verifiable outcome rewards. These methods have demonstrated strong performance on single-turn tasks, particularly mathematical reasoning. However, extending these methods to long-horizon multi-turn agentic tasks remains challenging [11]. In such environments, an episode may involve many interaction steps, while rewards are often sparse, so assigning a single trajectory-level advantage to every action obscures which decisions actually caused success or failure [13, 14].
Recent methods such as GiGPO [15] mitigate this issue by grouping steps with identical environment states. However, computing step-level advantages from trajectory outcomes within such groups may conflate the grouped action with later decisions, creating a credit-assignment mismatch.
As illustrated in Figure 1, even when two samples share the same current state and take the same action, their terminal rewards may differ, or even have opposite signs, because their subsequent actions diverge. This difference should not be attributed to the current action, but rather to the subsequent action that actually determines the outcome. However, these decisive actions often occur after the trajectories have entered sparse or non-identical states, where reliable state-level groups can no longer be formed. The unresolved return variation should therefore be carried forward along the shared action prefix and progressively decomposed as subsequent actions are revealed. When the trajectories branch into groups with different conditional mean returns, credit can be assigned to the newly revealed branching action.

Figure 1. Comparison of state-group and prefix-tree credit assignment under the undiscounted setting (). Identical actions may receive conflicting advantages when their subsequent actions lead to different returns. PTGPO recursively groups trajectory suffixes by action prefix, where node values denote empirical mean returns and edge labels denote child-parent mean differences. Colors indicate identical actions.
In this work, we propose Prefix Tree Group Policy Optimization (PTGPO), a critic-free method for fine-grained credit assignment in long-horizon tasks. PTGPO constructs a prefix tree for each anchor-state group, recursively grouping trajectory suffixes by shared action prefixes. For each parent-child edge in the tree, PTGPO assigns credit equal to the difference between the child and parent empirical mean returns. This quantity measures the conditional return increment introduced by the newly revealed action. Across three challenging agentic benchmarks ALFWorld, WebShop and Sokoban, PTGPO consistently outperforms existing prompting and RL baselines. Our analysis further shows that the proposed prefix-tree credit assignment provides effective step-level learning signals, making PTGPO a practical solution for long-horizon agentic tasks with sparse rewards.
Method
For each sampled trajectory , let its length be . For each sampled step , we define the discounted return as
where is the discount factor. In sparse terminal-reward tasks, intermediate rewards are zero.
Following GiGPO, we use the same anchor-state matching strategy to construct step-level root groups over sampled rollouts. Let denote an anchor state, and let
be the set of all step occurrences that share this anchor state.
For each group, PTGPO builds a prefix tree. Let be a sequence of actions. The corresponding node is the set
Samples with the same action sequence of length are included. The root is . If extends by one action , then the node is a child of , and we have
Thus, starting from the root, PTGPO recursively splits each node according to the next action, merging sampled steps with the same future action prefix into the same branch.
For any nonempty node, its empirical mean return is
For a sampled step with , consider its prefix-tree path, where and . The unnormalized state-group step advantage [15] then admits the following decomposition along a path expanded to depth :
where
is the credit assigned to the newly added action for each , reflecting the change in mean return from parent to child, while differences due to later actions remain within for further decomposition. A node can be expanded only if .
PTGPO normalizes each credit by the standard deviation of returns in its root group:
For action , PTGPO sums the normalized edge credits from starting steps :
Each edge credit is normalized by the standard deviation of the root group associated with its starting step , with each term capturing a distinct conditional-return innovation under a different anchor-conditioned prefix decomposition. In practice, the accumulated magnitude remains well controlled because the maximum expansion depth of each prefix tree is limited and valid root groups become increasingly sparse along the trajectory.
| Type | Method | Pick | Look | Clean | Heat | Cool | Pick2 | All | Score | Succ. |
| Closed-Source Model | ||||||||||
| Prompting | GPT-4o | 75.3 | 60.8 | 31.2 | 56.7 | 21.6 | 49.8 | 48.0 | 31.8 | 23.7 |
| Prompting | Gemini-2.5-Pro | 92.8 | 63.3 | 62.1 | 69.0 | 26.6 | 58.7 | 60.3 | 42.5 | 35.9 |
| Qwen2.5-1.5B-Instruct | ||||||||||
| Prompting | Direct Prompt | 5.9 | 5.5 | 3.3 | 9.7 | 4.2 | 0.0 | 4.1 | 23.1 | 5.2 |
| Prompting | ReAct | 17.4 | 20.5 | 15.7 | 6.2 | 7.7 | 2.0 | 12.8 | 40.1 | 11.3 |
| Prompting | Reflexion | 35.3 | 22.2 | 21.7 | 13.6 | 19.4 | 3.7 | 21.8 | 55.8 | 21.9 |
| RL Training | PPO | 64.8±3.5 | 40.5±6.9 | 57.1±4.9 | 60.6±6.6 | 46.4±4.0 | 47.4±1.9 | 54.4±3.1 | 73.8±3.0 | 51.5±2.9 |
| RL Training | RLOO | 88.3±3.0 | 52.8±8.6 | 71.0±5.9 | 62.8±8.7 | 66.4±5.5 | 56.9±4.7 | 69.7±2.5 | 73.9±5.6 | 52.1±6.7 |
| RL Training | GRPO | 85.3±1.5 | 53.7±8.0 | 84.5±6.8 | 78.2±7.9 | 59.7±5.0 | 53.5±5.6 | 72.8±3.6 | 75.8±3.5 | 56.8±3.8 |
| RL Training | GiGPO | 93.6±6.7 | 82.1±8.0 | 90.3±6.9 | 89.7±5.5 | 77.5±4.0 | 73.3±11.4 | 84.8±5.5 | 81.6±4.6 | 67.5±4.8 |
| RL Training | PTGPO (Ours) | 96.6±3.6 | 87.6±6.9 | 97.4±2.3 | 100.0±0.0 | 86.0±6.6 | 89.3±8.2 | 92.6±2.5 | 87.1±0.4 | 74.3±1.5 |
| Qwen2.5-7B-Instruct | ||||||||||
| Prompting | Direct Prompt | 33.4 | 21.6 | 19.3 | 6.9 | 2.8 | 3.2 | 14.8 | 26.4 | 7.8 |
| Prompting | ReAct | 48.5 | 35.4 | 34.3 | 13.2 | 18.2 | 17.6 | 31.2 | 46.2 | 19.5 |
| Prompting | Reflexion | 62.0 | 41.6 | 44.9 | 30.9 | 36.3 | 23.8 | 42.7 | 58.1 | 28.8 |
| RL Training | PPO | 92.3±4.0 | 64.0±8.4 | 92.5±2.4 | 89.5±7.0 | 80.3±2.0 | 68.8±8.3 | 80.4±2.7 | 81.4±3.1 | 68.7±5.1 |
| RL Training | RLOO | 87.6±4.3 | 78.2±8.3 | 87.3±5.8 | 81.3±7.6 | 71.9±5.2 | 48.9±8.4 | 75.5±4.6 | 80.3±3.2 | 65.7±4.0 |
| RL Training | GRPO | 90.8±5.1 | 66.1±6.7 | 89.3±5.4 | 74.7±6.9 | 72.5±5.4 | 64.7±7.3 | 77.6±5.2 | 79.3±2.8 | 66.1±3.7 |
| RL Training | GiGPO | 95.2±5.9 | 86.7±4.3 | 96.4±3.4 | 93.7±5.9 | 84.1±5.9 | 92.8±2.4 | 91.9±1.6 | 82.5±1.3 | 70.5±1.1 |
| RL Training | PTGPO (Ours) | 100.0±0.0 | 96.0±3.5 | 97.3±2.4 | 97.6±4.1 | 86.9±5.0 | 97.2±2.4 | 96.0±1.1 | 90.7±2.0 | 82.0±1.6 |
Table 1. Performance on ALFWorld and WebShop. We train each RL method with 3 random seeds and report the mean and standard deviation. The best performances are highlighted in bold.
Finally, PTGPO is combined with the base episode advantage:
where and are the mean and standard deviation of terminal rewards across the group.
Here is sequence-level and shared by all actions in the response, while provides step-level credit by decomposing the suffix-dependent return along the prefix tree. Figure 2 gives an intuitive example of the resulting advantage decomposition. PTGPO shifts credit from uniformly rewarding or penalizing every step to emphasizing the key decision points that separate successful and failed trajectories.

Figure 2. Illustration of PTGPO advantage decomposition under the undiscounted setting (). Episode-level advantages are shared by all actions in the same trajectory, while prefix-tree credits redistribute return residuals to branching decisions that change the conditional mean return. “End” marks the termination of a prefix decomposition.
Then the clipped policy optimization objective of PTGPO is:
where
Experiments
Setup
Benchmarks. We train agents on three challenging multi-turn benchmarks: ALFWorld [3], WebShop [5] and Sokoban [7]. ALFWorld is a text-based embodied environment where agents complete household tasks through multi-step interaction. WebShop is a web-based interactive benchmark where LLM agents navigate a simulated shopping website to purchase items matching user instructions. Sokoban is a visual grid-based game benchmark where agents move boxes onto target locations through multi-step actions.
Baselines. We compare PTGPO against baselines across paradigms: (1) Closed-source models: GPT-4o [16] and Gemini-2.5-Pro [17]. (2) Prompting methods: ReAct [19] and Reflexion [19]. (3) RL training methods: PPO [20], RLOO [21], GRPO [12] and GiGPO [15], covering both critic-based and group-based policy optimization methods. For VLMs, we focus on comparisons with group-based RL methods.
Implementation. We use Qwen2.5-1.5B-Instruct and Qwen2.5-7B-Instruct [22] as the base models for ALFWorld and WebShop, and Qwen2.5-VL-3B-Instruct [23] for Sokoban. For fair comparison, all RL methods use identical training configurations. We train each method for 160 training iterations with a discount factor of and a learning rate of . In each iteration, we sample 16 training instances and generate a group of 8 trajectories for each instance, resulting in 128 rollouts per iteration. Each episode allows up to 50 environment steps in ALFWorld and up to 15 environment steps in WebShop and Sokoban. We use 8 NVIDIA H20 96GB GPUs for training.
Experiment Results
Main Results
Table 1 shows that PTGPO consistently outperforms prompting methods and RL baselines across multi-turn agentic tasks. On Qwen2.5-1.5B, PTGPO achieves 92.6 on ALFWorld and 74.3% success on WebShop, improving over GRPO by 19.8 and 17.5 points, respectively. With Qwen2.5-7B, PTGPO further improves to 96.0 on ALFWorld and 82.0% success rate on WebShop. On the visual Sokoban benchmark, PTGPO reaches 85.2 as shown in Table 2, outperforming GRPO and GiGPO, demonstrating its effectiveness for both LLM and VLM agents. To further examine the training dynamics, Figure 3(a) reports the episode success rate on ALFWorld as a representative example. PTGPO reaches around 0.8 success rate after about 75 steps, while GiGPO reaches a similar level after about 105 steps and GRPO fails to do so within 160 steps, showing better training efficiency.
| Type | Method | Sokoban [6×6] |
| Prompting | Direct Prompt | 11.7 |
| RL Training | GRPO | 73.9±1.6 |
| RL Training | GiGPO | 77.6±2.5 |
| RL Training | PTGPO | 85.2±1.6 |
Table 2. Performance on Sokoban. We train each RL method with 3 random seeds and report the mean and standard deviation. The best performances are highlighted in bold.

Figure 3. (a) Episode Success Rate during Training on ALFWorld. (b) Distribution of maximum expanded tree depth at epoch 160 on ALFWorld.
Ablation Studies
Table 3 evaluates the main components and design choices of PTGPO. Unless otherwise specified, the full method uses unrestricted prefix-tree expansion with and sums all valid prefix credits associated with each action. Removing the prefix-tree advantage reduces performance by 19.8, 17.5, and 11.3 points on ALFWorld, WebShop, and Sokoban, respectively, confirming that fine-grained prefix credit is the primary source of improvement. In comparison, removing the episode-level advantage has little effect on ALFWorld but causes larger drops on WebShop and Sokoban, indicating that the trajectory-level signal provides complementary global supervision.
| Variant | ALFWorld | WebShop | Sokoban |
| PTGPO | 92.6 | 74.3 | 85.2 |
| Advantage Composition | |||
| w/o Episode-level Adv | 92.4 | 71.8 | 81.5 |
| w/o Prefix-tree Adv | 72.8 | 56.8 | 73.9 |
| Aggregation Strategy | |||
| Mean | 84.3 | 71.4 | 82.3 |
| Nearest Anchor | 91.5 | 73.2 | 84.1 |
| Prefix Depth | |||
| 87.6 | 70.0 | 78.6 | |
| 88.3 | 72.9 | 83.3 | |
| 92.1 | 74.5 | 83.6 | |
| Expansion Threshold | |||
| 90.0 | 72.0 | 83.6 | |
| 85.5 | 71.1 | 81.5 | |
| 84.3 | 73.3 | 81.8 |
Table 3. Ablation study of PTGPO on ALFWorld and WebShop using Qwen2.5-1.5B-Instruct, and on Sokoban using Qwen2.5-VL-3B-Instruct. The best performances are highlighted in bold.
We next compare different strategies for combining the credits assigned to the same action by multiple anchor states. Mean aggregation consistently underperforms the default summation strategy, with a particularly large drop on ALFWorld. Using only the nearest valid anchor performs substantially better than mean aggregation, but remains below credit summation on all three benchmarks. These results suggest that different anchor states provide complementary credit signals: restricting learning to the nearest anchor discards useful longer-range evidence, whereas averaging can dilute informative signals when only a small number of valid anchors are available. Summation preserves and accumulates these signals. Moreover, because an action can only receive credit from trees that reach it, the number of accumulated terms is bounded by the tree depth and is further limited by sparse state matching and the expansion threshold.
Increasing the maximum prefix depth generally improves performance. Expanding the depth from 2 to 8 improves ALFWorld from 87.6 to 92.1 and WebShop from 70.0 to 74.5, while Sokoban improves from 78.6 to 83.6. Depth 8 is already close to unrestricted expansion, consistent with Figure 3(b), which shows that most trees terminate within eight levels. Finally, increasing generally degrades performance. Although a larger threshold yields more reliable node-level return estimates, it prevents many sparsely supported branches from being expanded and consequently removes useful fine-grained credits. Overall, provides the best balance between estimation reliability and credit coverage.
Computational Overhead
We measure the method-specific advantage computation cost on ALFWorld with Qwen2.5-1.5B-Instruct at epoch 160. PTGPO shares the same rollout, probability computation, and policy update pipeline as other group-based methods, with a common cost of about 210.968s per iteration, and introduces additional computation only for prefix-tree construction and prefix-wise advantage estimation. The method-specific advantage computation costs are 0.192s for GRPO, 0.559s for GiGPO, and 1.713s for PTGPO. Despite the additional overhead introduced by prefix-tree construction, PTGPO’s extra computation accounts for only 0.812% of the common training cost and has a negligible impact on overall training efficiency.
Conclusion
In this paper, we propose PTGPO, a novel reinforcement learning method for long-horizon interactive agents with sparse rewards. PTGPO mitigates the credit assignment problem by decomposing trajectory returns through prefix-wise conditional mean increments, assigning step-level credit to actions according to how future action prefixes change expected returns. Experiments on interactive benchmarks show that PTGPO consistently improves over existing RL baselines. Further analyses demonstrate the effectiveness of prefix-tree advantages and show that PTGPO introduces only minor computational overhead without requiring extra rollouts or critic models.
References
- [1]Aixin Liu, Aoxue Mei, Bangcai Lin, Bing Xue, Bingxuan Wang, Bingzheng Xu, Bochao Wu, Bowei Zhang, Chaofan Lin, Chen Dong, et al., “Deepseek-v3. 2: Pushing the frontier of open large language models,” arXiv preprint arXiv:2512.02556, 2025.arxiv.org/abs/2512.02556
- [2]An Yang, Anfeng Li, Baosong Yang, Beichen Zhang, Binyuan Hui, Bo Zheng, Bowen Yu, Chang Gao, Chenghen Huang, Chenxu Lv, et al., “Qwen3 technical report,” arXiv preprint arXiv:2505.09388, 2025.arxiv.org/abs/2505.09388
- [3]Mohit Shridhar, Xingdi Yuan, Marc-Alexandre Côté, Yonatan Bisk, Adam Trischler, and Matthew Hausknecht, “Alfworld: Aligning text and embodied environments for interactive learning,” arXiv preprint arXiv:2010.03768, 2020.arxiv.org/abs/2010.03768
- [4]Guanzhi Wang, Yuqi Xie, Yunfan Jiang, Ajay Mandlekar, Chaowei Xiao, Yuke Zhu, Linxi Fan, and Anima Anandkumar, “Voyager: An open-ended embodied agent with large language models,” arXiv preprint arXiv:2305.16291, 2023.arxiv.org/abs/2305.16291
- [5]Shunyu Yao, Howard Chen, John Yang, and Karthik Narasimhan, “Webshop: Towards scalable real-world web interaction with grounded language agents,” Advances in Neural Information Processing Systems, vol. 35, pp. 20744–20757, 2022.arxiv.org/abs/2207.01206
- [6]Boyu Gou, Demi Ruohan Wang, Boyuan Zheng, Yanan Xie, Cheng Chang, Yiheng Shu, Huan Sun, and Yu Su, “Navigating the digital world as humans do: Universal visual grounding for gui agents,” in International Conference on Learning Representations, 2025, vol. 2025, pp. 30851–30883.arxiv.org/abs/2410.05243
- [7]Max-Philipp B. Schrader, “gym-sokoban,” https://github.com/mpSchrader/gym-sokoban, 2018.
- [8]Zelai Xu, Chao Yu, Fei Fang, Yu Wang, and Yi Wu, “Language agents with reinforcement learning for strategic play in the werewolf game,” arXiv preprint arXiv:2310.18940, 2023.arxiv.org/abs/2310.18940
- [9]Zehan Qi, Xiao Liu, Iat Long Long, Hanyu Lai, Xueqiao Sun, Jiadai Sun, Xinyue Yang, Yu Yang, Shuntian Yao, Wei Xu, et al., “Webrl: Training llm web agents via self-evolving online curriculum reinforcement learning,” in International Conference on Learning Representations, 2025, vol. 2025, pp. 79791–79821.arxiv.org/abs/2411.02337
- [10]Bowen Jin, Hansi Zeng, Zhenrui Yue, Jinsung Yoon, Sercan Arik, Dong Wang, Hamed Zamani, and Jiawei Han, “Search-rl: Training llms to reason and leverage search engines with reinforcement learning,” arXiv preprint arXiv:2503.09516, 2025.
- [11]Zihan Wang, Kangrui Wang, Qinenq Wang, Pingyue Zhang, Linjie Li, Zhengyuan Yang, Xing Jin, Kefan Yu, Minh Nhat Nguyen, Licheng Liu, et al., “Ragen: Understanding self-evolution in llm agents via multi-turn reinforcement learning,” arXiv preprint arXiv:2504.20073, 2025.arxiv.org/abs/2504.20073
- [12]Zhihong Shao, Peiyi Wang, Qiao Zhu, Runxin Xu, Junxiao Song, Xiao Bi, Haowei Zhang, Mingchuan Zhang, YK Li, Yang Wu, et al., “Deepseekmath: Pushing the limits of mathematical reasoning in open language models,” arXiv preprint arXiv:2402.03300, 2024.arxiv.org/abs/2402.03300
- [13]Zixuan Wang, Yuchen Yan, Hongxing Li, Teng Pan, Dingming Li, Ruiqiang Zhang, Weiming Lu, Jun Xiao, Yueting Zhuang, and Yongliang Shen, “Milestone-guided policy learning for long-horizon language agents,” arXiv preprint arXiv:2605.06078, 2026.arxiv.org/abs/2605.06078
- [14]Hui-Ze Tan, Xiao-Wen Yang, Hao Chen, Jie-Jing Shao, Yi Wen, Yuteng Shen, Weihong Luo, Xiku Du, Lan-Zhe Guo, and Yu-Feng Li, “Hindsight credit assignment for long-horizon llm agents,” arXiv preprint arXiv:2603.08754, 2026.arxiv.org/abs/2603.08754
- [15]Lang Feng, Zhenhai Xue, Tingcong Liu, and Bo An, “Group-in-group policy optimization for llm agent training,” Advances in Neural Information Processing Systems, vol. 38, pp. 46375–46408, 2026.arxiv.org/abs/2505.10978
- [16]Aaron Hurst, Adam Lerner, Adam P. Goucher, Adam Perelman, Aditya Ramesh, Aidan Clark, Al O Ostrow, Akila Wēlı̄hinda, Alan Hayes, Alec Radford, et al., “Gpt-4o system card,” arXiv preprint arXiv:2410.21276, 2024.arxiv.org/abs/2410.21276
- [17]Gheorghe Comanici, Eric Bieber, Mike Schaeckermann, Ice Pasupat, Noveen Sachdeva, Inderjit Dhillon, Marcel Blistein, Ori Ram, Dan Zhang, Evan Rosen, et al., “Gemini 2.5: Pushing the frontier with advanced reasoning, multimodality, long context, and next generation agentic capabilities,” arXiv preprint arXiv:2507.06261, 2025.arxiv.org/abs/2507.06261
- [19]Noah Shinn, Federico Cassano, Ashwin Gopinath, Karthik Narasimhan, and Shunyu Yao, “Reflexion: Language agents with verbal reinforcement learning,” Advances in neural information processing systems, vol. 36, pp. 8634–8652, 2023.arxiv.org/abs/2303.11366
- [20]John Schulman, Filip Wolski, Prafulla Dhariwal, Alec Radford, and Oleg Klimov, “Proximal policy optimization algorithms,” arXiv preprint arXiv:1707.06347, 2017.arxiv.org/abs/1707.06347
- [21]Arash Ahmadian, Chris Cremer, Matthias Gallé, Marzieh Fadaee, Julia Kreutzer, Olivier Pietquin, Ahmet Üstün, and Sara Hooker, “Back to basics: Revisiting reinforce-style optimization for learning from human feedback in llms,” in Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), 2024, pp. 12248–12267.arxiv.org/abs/2402.14740
- [22]An Yang, Baosong Yang, Beichen Zhang, Binyuan Hui, Bo Zheng, Bowen Yu, Chengyuan Li, Dayiheng Liu, Fei Huang, Haoran Wei, et al., “Qwen2.5 technical report,” arXiv preprint arXiv:2412.15115, 2024.arxiv.org/abs/2412.15115
- [23]Shuai Bai, Keqin Chen, Xuejing Liu, Jialin Wang, Wenbin Ge, Sibo Song, Kai Dang, Peng Wang, Shijie Wang, Jun Tang, et al., “Qwen2.5-vl technical report,” arXiv preprint arXiv:2502.13923, 2025.arxiv.org/abs/2502.13923