FoundationAgents/ReCode

Next paradigm for LLM Agent. Unify plan and action through recursive code generation for adaptive, human-like decision-making.

What it solves

ReCode addresses the gap between high-level strategic planning and low-level execution in LLM agents. Traditional agents often struggle to balance these two, either planning too vaguely or getting bogged down in trivial details. ReCode provides "universal granularity control," allowing an agent to dynamically shift from broad goals to specific, executable actions.

How it works

ReCode uses a recursive code generation approach that treats plans and actions as a single representation:

  • Tree-structured Code: The agent organizes its approach as a tree of partial programs. Each node represents a sub-task and tracks its own execution history.
  • Recursive Expansion: High-level plans are written as placeholder functions. When the agent needs more detail, the LLM recursively expands these placeholders into more specific calls or smaller subroutines.
  • Dynamic Execution Loop: Each node is executed immediately. Based on the resulting observations from the environment, the agent decides whether to expand the plan further, retry the action, or mark the task as finished.
  • Constrained Executor: A Python-based executor manages environment variables and validates the code blocks to ensure the agent uses the available toolset correctly.

Who it’s for

This project is designed for AI researchers and developers building autonomous agents that need to operate in complex environments (like ALFWorld, WebShop, or ScienceWorld) where tasks require both long-term planning and precise execution.

Highlights

  • Unified Representation: Merges planning and action into a single recursive code structure.
  • High Performance: Outperforms baselines like ReAct and CodeAct, achieving a perfect score in ALFWorld using Claude-4-Sonnet.
  • Data Efficient: Shows strong results when combined with supervised fine-tuning (SFT) using Qwen2.5-7B-Instruct.
  • Extensible: Includes a standardized Env interface to easily integrate new simulation environments.