ReCAP: Recursive Context-Aware Reasoning and Planning for Large Language Model Agents

Zhenyu Zhang, Tianyi Chen, Weiran Xu, Alex Pentland, Jiaxin Pei · DOI

TL;DR

Large language models (LLMs) struggle with long-horizon tasks that require complex reasoning and dynamic replanning. This paper introduces ReCAP, a novel hierarchical framework that uses recursive context-aware reasoning and planning to maintain coherence across different levels of detail, significantly improving performance on challenging tasks.

What Problem Does This Paper Address?

LLMs are increasingly used for complex tasks that involve multiple steps and require adapting to changing environments. However, existing methods like sequential prompting often suffer from "context drift," where the LLM loses track of the original goal as the task progresses. Hierarchical prompting methods, while better at structuring tasks, can lead to a loss of continuity between different levels of reasoning or incur significant computational overhead. This paper addresses the challenge of enabling LLM agents to perform robust, long-horizon reasoning and planning in dynamic environments, ensuring that high-level goals are consistently maintained and low-level actions remain aligned with those goals, even when faced with unexpected events or failures.

Methods

ReCAP introduces a hierarchical framework with a shared context for reasoning and planning. It employs three key mechanisms:

  1. Plan-ahead task decomposition: Instead of generating subtasks one by one, ReCAP first generates a complete list of subtasks for a given goal. It then executes the first subtask and refines the remaining plan based on the outcome.
  2. Structured re-injection of parent plans: When returning from a completed subtask (or a failed one), the parent's plan (including its thoughts and remaining subtasks) is re-injected into the LLM's context. This ensures consistent multi-level context and maintains coherence across different levels of reasoning.
  3. Memory-efficient execution: ReCAP uses a sliding window for its active prompt, keeping the context size manageable. Critical planning information is reintroduced through structured injection, preventing the loss of high-level intent due to context truncation. This approach ensures that the external state grows linearly with recursion depth.

Datasets

The paper evaluates ReCAP on the following benchmarks:

  • ALFWorld: A symbolic, text-only simulator for embodied reasoning with natural-language actions.
  • Robotouille: An embodied cooking environment designed for evaluating LLM agents on long-horizon tasks, with both synchronous and asynchronous modes.
  • FEVER: A dataset for fact verification, testing knowledge-intensive reasoning.
  • SWE-bench Verified: A benchmark for repository-level coding issue resolution.

No new benchmarks were introduced; the focus was on evaluating ReCAP's performance on existing, challenging tasks.

Key Insights and Ideas

  • The power of structured backtracking: ReCAP's ability to re-inject parent plans upon returning from subtasks is crucial. This mechanism allows the agent to "remember" its higher-level goals and adapt its plan dynamically, preventing it from getting lost in local details or failing due to unexpected environmental changes.
  • Shared context is key for coherence: Maintaining a single, evolving LLM context across all recursion depths, rather than isolated contexts for each level, significantly improves continuity and prevents fragmentation of information.
  • Plan-ahead decomposition is more robust: Generating a full subtask list upfront and then refining it offers a more stable approach than step-by-step planning, especially in dynamic environments where plans might need significant revision.
  • Efficiency matters: The sliding window and structured injection mechanisms are vital for keeping the LLM's context manageable and preventing performance degradation due to excessive context length.

Key Results

ReCAP demonstrated significant improvements across various benchmarks:

  • Robotouille (Synchronous): Achieved a 32% gain in success rate compared to ReAct.
  • Robotouille (Asynchronous): Achieved a 29% improvement in success rate compared to ReAct.
  • ALFWorld: Improved over ReAct by 7%.
  • FEVER: Performed similarly to ReAct, indicating its robustness even on shorter tasks.
  • SWE-bench Verified: Achieved the highest success rate among evaluated methods using GPT-4.1.

Qualitatively, ReCAP was shown to avoid infinite loops in challenging scenarios (like blocked stations in Robotouille) by detecting the loop, backtracking, and replanning, whereas ReAct would get stuck.

Limitations and Future Work

The authors acknowledge several limitations:

  • Reliance on LLM quality: ReCAP delegates all decision-making to the LLM, making it sensitive to model quality and prone to propagating errors if the LLM misinterprets feedback.
  • Increased interaction trajectory: The recursive nature can lead to longer interaction trajectories and increased API overhead, potentially impacting end-to-end latency.

Future work directions include:

  • Modularizing the architecture: Decoupling high-level planning from low-level execution, potentially using different models for each.
  • Reducing interaction costs: Exploring reasoning compression, dynamic step control, and API batching.
  • Challenging linear context assumption: Investigating alternative memory structures, such as executable graphs, for more targeted retrieval and optimized reasoning.
  • Developing safeguards: Exploring interpretable reasoning trees and confidence-aware action proposals for safer deployment in safety-critical applications.

Summary updated

BibTeX
@inproceedings{zhang2025recap,
  author = {Zhenyu Zhang and Tianyi Chen and Weiran Xu and Alex Pentland and Jiaxin Pei},
  title = {{ReCAP: Recursive Context-Aware Reasoning and Planning for Large Language Model Agents}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=r2ykUnzuGt},
}
Figure