arXiv:2610.30933cs.CLOct 2026

Manuscript Offprint

arXiv:2610.30933

ReflectPO: Reflection-Guided Policy Optimization for Long-Horizon LLM Agents

Rumei Li, Xunliang Cai

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

ABSTRACT

With external tools, large language models (LLMs) can tackle complex tasks through sustained environmental interaction. LLM-based agents are therefore increasingly used to tackle complex long-horizon tasks in real-world environments. However, these tasks involve sequential, interdependent decisions and changes in environmental states. Early execution errors affect subsequent interaction histories and environmental states, and their effects accumulate along the decision chain. To address this challenge, we propose Reflection-Guided Policy Optimization (ReflectPO), a reinforcement learning framework for autonomous error recovery in long-horizon tasks. ReflectPO comprises two core components. The first is Reflection-Guided Sampling. We use branch differences and repeated visits in interaction trajectories to construct hints for error recovery. The second is Tree-Structured Credit Assignment. We organize sampled trajectories into trees and assign action-level credit using parent–child reward differences and recovery gains. Experiments over two long-horizon tool-use benchmarks show that ReflectPO outperforms multiple existing baselines in most domains. It also achieves the best overall performance on average. Further analyses show that ReflectPO effectively improves agents' ability to recognize their own deviations, recover from erroneous states, and continue making progress toward task completion.

1 INTRODUCTION

Large language models (LLMs) have made steady progress in tasks such as reasoning, instruction following, task planning, and tool use (DeepSeek-AI, 2025; Dong et al., 2025b; Erdogan et al., 2025; Dong et al., 2026a; Li et al., 2025b; Wei et al., 2025a). This progress has also supported the development of LLM-based agents. LLM-based agents use tools to interact with external environments and turn model decisions into actions for complex real-world tasks (Wei et al., 2025b; Fang et al., 2026; Chen et al., 2025; Feng et al., 2025a; Yao et al., 2024; Bandi et al., 2026; Luo et al., 2025; Li et al., 2025a). Such tasks involve long-horizon interactions in which decisions shape subsequent states and interaction histories (Dong et al., 2026c). These dependencies complicate state tracking and decision-making.

To improve agents’ ability to handle these long-horizon dependencies, reinforcement learning methods optimize agent policies through multi-turn agent–environment interactions, with designs targeting trajectory exploration, credit assignment, and error recovery (Dong et al., 2025c; Chen et al., 2026a; Su et al., 2025; Wang et al., 2026f). Despite these performance gains, execution errors can still alter subsequent states and interaction histories, causing deviations to accumulate and tasks to fail (Ma et al., 2026; Saeidi et al., 2026). Detecting and recovering these errors remains difficult, making autonomous recovery a key challenge for reliable long-horizon execution.

To support recovery from errors during long-horizon execution, existing methods provide inference-time assistance or train agents to recover from failed attempts. Inference-time recovery methods use language feedback, memory, or external verification to assess ongoing execution (Shinn et al., 2023; Gou et al., 2024). However, these methods often require additional external assistance at test time. Training-based recovery methods derive learning signals from failed trajectories, step-level feedback, or diagnostic information (Yuan et al., 2025; Wang et al., 2025a; Zhang et al., 2026). However, their reliance on externally provided error locations or recovery guidance limits supervision for deciding when to initiate recovery independently. Meanwhile, general-purpose reinforcement learning primarily optimizes task outcomes, but these outcome-based signals provide indirect guidance for error detection and recovery (Dong et al., 2025c;a; Chen et al., 2026a). Prior studies also show that better task-solving performance does not automatically improve self-verification (Chen et al., 2026b; Liu et al., 2026). Overall, these approaches provide limited support for learning autonomous error recovery. Therefore, how to enable agents to identify their own errors and recover from deviations remains an open challenge.

In this paper, we propose Reflection-Guided Policy Optimization (ReflectPO), a reinforcement learning method for error recovery in long-horizon agent tasks. Specifically, ReflectPO introduces two recovery trajectory sampling strategies: contrast-based sampling and loop-based sampling. The former organizes trajectories for the same task into a shared prefix tree, and constructs hints from differences between execution paths. The latter constructs a local interaction graph for each trajectory, and derives hints from loops within that trajectory. Guided by these hints, the agent resumes the task from recovery anchors and generates recovery trajectories.

To derive precise policy update signals from sampled trajectories, we design a tree-structured credit assignment method that accounts for both the effects of local decisions and the gains from recovery. These training signals reinforce effective task execution and error recovery, improving agents' ability to complete long-horizon tasks.

We evaluate ReflectPO on two tool-use benchmarks. ReflectPO consistently improves average performance on both benchmarks. Further analyses suggest that trained agents can autonomously identify execution errors and recover from deviations to some extent, demonstrating its effectiveness in long-horizon agent tasks.

In summary, our main contributions are as follows:

• We propose ReflectPO, which uses directed graphs to extract local differences and repeated visitation patterns from natural reasoning trajectories. Two sampling strategies use these patterns to guide agents in generating recovery trajectories.

• We propose tree-structured credit assignment based on the structure of sampled trajectories. It more accurately captures the effects of local decisions on subsequent outcomes and the actual gains from recovery.

• We conduct systematic experiments on two challenging long-horizon tasks. ReflectPO improves average performance over conventional methods. Further analyses show that trained agents exhibit clear error recovery behaviors.

References (78)