← Open Source
FoundationAgents

ReCode

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

AI EngineeringPrompt & ScaffoldPython
Open on GitHub
Momentum
+0stars in 24 hours0.0%
571
Stars
69
Forks
+0
This week
1
Contributors
Created 2025-10-27 · Updated 2026-10-14 · #16802 today
Top developers
MoshiQAQ

FoundationAgents/ReCode is ranked 16,802 with 571 stars.

Same-category comparison

FoundationAgents/ReCode is ranked 16,802 among these 8 peers; NabilRFG12/Reverse-Engineer-anything is ranked 16,805.

Same-category comparison
NameRankMetrics
sentient-engineering/sentient16,771
Language:
Python
Stars:
573
Forks:
67
Description:
the framework/ sdk that lets you build browser controlling agents in 3 lines of code. join chat @ https://discord.gg/umgnyQU2K8.
twostraws/Swift-Concurrency-Agent-Skill16,772
Stars:
573
Forks:
23
Description:
Swift Concurrency agent skill for Claude Code, Codex, and other AI tools.
docsagent/docsagent16,786
Language:
TypeScript
Stars:
572
Forks:
8
google/dotprompt16,789
Language:
Dart
Stars:
572
Forks:
72
Description:
Executable GenAI prompt templates.
NabilRFG12/Reverse-Engineer-anything16,805
Stars:
571
Forks:
196
Description:
Reverse engineer anything with agents, from app behavior down to native binaries.
netaart/cohub16,817
Language:
TypeScript
Stars:
571
Forks:
11
Description:
A living space where people and agents create, play, and build together.
Baidu-AIP/java-sdk16,819
Language:
Java
Stars:
570
Forks:
222
cchio/deep-pwning16,827
Language:
Python
Stars:
570
Forks:
131
Description:
Metasploit for machine learning.
Key parameters and specifications
Key parameters and specifications
ParameterValue
LanguagePython
CategoryAI Engineering
SubcategoryPrompt & Scaffold
KeywordsPlanning, Reasoning
Stars571
Forks69
Contributors1
Created date2025-10-27
Updated date2026-10-14
Stars in 1 day0
Stars in 7 days0
Rank16,802
Previous rank16,593
Rank change-209
7-day stars rank15,732
Previous 7-day stars rank15,743
7-day stars rank change11
Total stars rank17,451
Previous total stars rank17,422
Total stars rank change-29
README summary

ReCode: Unify Plan and Action for Universal Granularity Control If you encounter any difficulties in using or reproducing the code, please contact me at zhaoyangyu713@gmail. ReCode introduces recursive code generation for LLM agents, unifying plan and action into a single representation. This repository hosts the reference implementation used in the paper, along with environment wrappers and experiment tooling. Core Idea ReCode adopts a divide-and-conquer strategy, decomposing complex tasks into executable code fragments: 1. **Tree-structured code**: Organizes

partial programs in a tree where each node captures one sub-task and records its execution trace. **Dynamic execution loop**: Each node is executed immediately; fresh observations decide whether to expand further, retry, or finish. **Shared executor state**: A constrained Python executor maintains environment variables, validates code blocks, and exposes the toolset available to the agent. Repository Layout – CLI entry point that instantiates agents/envs, manages concurrency, and writes run summaries. – ReCode agent implementation, prompt templates, and utility helpers. – Environment

wrappers and assets for , , and . – LLM profile templates and (expected) pricing metadata used by the async client. – Shared components: async OpenAI wrapper, constrained executor, logging helpers, error types. – Paper figures used throughout this README. Experiments To evaluate the effectiveness of ReCode, we divide our experiments into the inference part and the training part. **Inference Result**: we compare against several mainstream paradigm (ReAct, CodeAct) and some of the work focused on improving LLM-based agent planning (AdaPlanner and ADaPT). ReCode achieved

significant performance improvements across all three environments, with an average score of 60. 8, surpassing the best baseline method by 10. _With our tests, ReCode can achieve a perfect **100** score in ALFWorld under . **Training Result**: we conduct supervised fine-tuning (SFT) on ReCode, ReAct and CodeAct with . ReCode+SFT delivers an impressive average performance of 70. 4% across all environments, outperforming both ReAct+SFT (67. 8%), highlighting its exceptional data efficiency. Quick Start To run ReCode, we need a

conda environment. Then, it is necessary to configure dependencies for three environments (it has not been confirmed whether conflicts will arise in the same environment), and we suggest configuring them in three separate environments. Set to the dataset root or edit to point to your local paths: ScienceWorld Follow the instruciton from the ScienceWorld repository. WebShop Thanks to ETO for providing a convenient script to configure WebShop environment. Ensure points to a valid API credential (copy if you need a

template), then run a short dry run in any enabled environment: Replace with or once their assets are available. Logs are written to , and the console prints a condensed summary for quick diagnostics. Configure LLM Access contains named profiles. The flag selects which profile to forward to . If you do not want to record costs, set for the profile. As a fallback, you can omit the file and set in the environment; the default profile will then use it. A

ready-to-edit template lives at ; copy it to if you're starting from scratch: Running ReCode is the canonical entry

Frequently asked questions

How many stars and forks are recorded?

FoundationAgents/ReCode has 571 stars and 69 forks.

What is the repository rank?

FoundationAgents/ReCode is ranked 16,802.

What language and category are recorded?

FoundationAgents/ReCode has 571 stars, uses Python and belongs to AI Engineering.

Which repository is closest in rank?

FoundationAgents/ReCode is compared with NabilRFG12/Reverse-Engineer-anything, ranked 16,805 with 571 stars.

README

ReCode: Unify Plan and Action for Universal Granularity Control

If you encounter any difficulties in using or reproducing the code, please contact me at zhaoyangyu713@gmail.com.

ReCode introduces recursive code generation for LLM agents, unifying plan and action into a single representation. By treating high-level plans as placeholder functions that recursively decompose into executable primitives, it achieves universal granularity control and dynamically adapts from strategic thinking to concrete actions. This repository hosts the reference implementation used in the paper, along with environment wrappers and experiment tooling.

Core Idea

ReCode adopts a divide-and-conquer strategy, decomposing complex tasks into executable code fragments:

  1. Tree-structured code: Organizes partial programs in a tree where each node captures one sub-task and records its execution trace.
  2. Recursive expansion: Placeholder functions are expanded by the LLM into more specific calls or smaller subroutines using environment-specific prompts and few-shots.
  3. Dynamic execution loop: Each node is executed immediately; fresh observations decide whether to expand further, retry, or finish.
  4. Shared executor state: A constrained Python executor maintains environment variables, validates code blocks, and exposes the toolset available to the agent.

Repository Layout

  • run.py – CLI entry point that instantiates agents/envs, manages concurrency, and writes run summaries.
  • agents/recode/ – ReCode agent implementation, prompt templates, and utility helpers.
  • envs/ – Environment wrappers and assets for alfworld, webshop, and sciworld.
  • configs/ – LLM profile templates and (expected) pricing metadata used by the async client.
  • utils/ – Shared components: async OpenAI wrapper, constrained executor, logging helpers, error types.
  • figures/ – Paper figures used throughout this README.

Experiments

To evaluate the effectiveness of ReCode, we divide our experiments into the inference part and the training part.

  1. Inference Result: we compare against several mainstream paradigm (ReAct, CodeAct) and some of the work focused on improving LLM-based agent planning (AdaPlanner and ADaPT). ReCode achieved significant performance improvements across all three environments, with an average score of 60.8, surpassing the best baseline method by 10.5 (relative 20.9%). With our tests, ReCode can achieve a perfect 100 score in ALFWorld under claude-4-sonnet.

  1. Training Result: we conduct supervised fine-tuning (SFT) on ReCode, ReAct and CodeAct with Qwen2.5-7B-Instruct. ReCode+SFT delivers an impressive average performance of 70.4% across all environments, outperforming both ReAct+SFT (67.6%) and CodeAct+SFT (55.8%), highlighting its exceptional data efficiency.

Quick Start

To run ReCode, we need a conda environment. The python version should be 3.10 or newer.

Then, it is necessary to configure dependencies for three environments (it has not been confirmed whether conflicts will arise in the same environment), and we suggest configuring them in three separate environments.

conda create -n recode-envname python=3.10 # Replace "envname" with the your environment name.
conda activate recode-envname

ALFWorld

  • Follow the ALFWorld instructions.

  • Set ALFWORLD_DATA to the dataset root or edit envs/alfworld/base_config.yaml to point to your local paths:

    export ALFWORLD_DATA=/path/to/alfworld
    

ScienceWorld

WebShop

Thanks to ETO for providing a convenient script to configure WebShop environment.

cd envs/webshop
pip install -e .
conda install -y -c conda-forge openjdk=11
pip install "en_core_web_lg @ https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-3.6.0/en_core_web_lg-3.6.0-py3-none-any.whl"

Run the provided helper to fetch the goal set and pre-built search index:

# The current path is "envs/webshop"
bash setup.sh

Install some other dependencies.

pip install -r requirements.txt # Here may not be complete, please contact me promptly if you encounter any problems

Ensure configs/profiles.yaml points to a valid API credential (copy configs/profiles_example.yaml if you need a template), then run a short dry run in any enabled environment:

python run.py -a recode -e alfworld -n 1 --split test --profile default

Replace alfworld with webshop or sciworld once their assets are available. Logs are written to logs//, and the console prints a condensed summary for quick diagnostics.

Configure LLM Access

  • configs/profiles.yaml contains named profiles. The run.py --profile flag selects which profile to forward to AsyncLLM. Example:

    models:
      default:
        api_key: "sk-your_api_key"
        base_url: "https://api.openai.com/v1"
        model: "gpt-4o-mini"
        temperature: 0.0
        track_costs: true
      gpt-4o:
        api_key: "sk-your_other_key"
        base_url: "https://api.openai.com/v1"
        model: "gpt-4o"
        temperature: 0.7
        max_tokens: 512
    
  • Cost tracking loads configs/prices.json. If you do not want to record costs, set track_costs: false for the profile.

  • As a fallback, you can omit the file and set OPENAI_API_KEY in the environment; the default profile will then use it.

  • A ready-to-edit template lives at configs/profiles_example.yaml; copy it to configs/profiles.yaml if you're starting from scratch:

    cp configs/profiles_example.yaml configs/profiles.yaml
    

Running ReCode

run.py is the canonical entry point. It resolves agent/environment aliases, manages concurrency, streams logs, and emits a structured summary.

# ALFWorld, single instance
python run.py -a recode -e alfworld -n 1 --split test --profile default

# WebShop, 3 test goals, allow deeper recursion
python run.py -a recode -e webshop -n 3 --split test --profile default --max-depth 12

# ScienceWorld, run 5 instances with 2-way concurrency
python run.py -a recode -e sciworld -n 5 -c 2 --profile gpt-4o

Key CLI flags:

  • -a / --agent – class path or alias (recode resolves to agents.recode.agent.ReCodeAgent).
  • -e / --env – environment class or alias (alfworld, webshop, sciworld).
  • -n / --instances – number of evaluation episodes.
  • -c / --concurrent – max concurrent episodes (rich progress UI automatically adapts).
  • --split, --seed, --max-depth, --profile – forwarded to both agent and environment.
  • -C / --config – YAML file whose keys override CLI flags; useful for complex sweeps.

Example YAML (configs/example.yaml):

agent: recode
env: alfworld
instances: 10
concurrent: 2
profile: gpt-4o
split: test
task_types: ["put", "clean"] # For ALFWorld
max_depth: 12
max_retry: 4

Run it with:

python run.py -C configs/example.yaml

Logging & Results

  • Each run creates logs// with:
    • running_logs/run.log – aggregated stream of agent + environment logs.
    • running_logs/instance_.log – per-instance traces (when multiple instances are launched).
    • `` – structured summary written by write_summary, containing per-instance metrics and aggregated statistics (overall + per task type).
  • The console prints a condensed summary (success rate, standard metrics, by-task breakdown) after completion.

Extending to New Environments

  1. Implement the Env interface under envs//env.py. Use base.environment.Env as the contract: implement reset, _run, is_done, is_success, and report. Return {"observations": [...], "env_name": , "env": self} from reset.
  2. Expose prompts and guidance in agents/recode/resources/:
    • prompts//actions.txt – concise description of valid run("...") calls/tools.
    • fewshots// – one or more .txt examples showing thought→execute patterns.
    • If your environment has task types, update agents/recode/agent.py::_load_resources and agents/recode/utils.parse_raw_observation to parse initial observations correctly.
  3. Register aliases by adding your class to ENV_ALIASES in run.py (optional but convenient) and, if needed, plan-specific logic in the agent utilities.
  4. Optionally add setup scripts (similar to envs/webshop/setup.sh) to document dataset fetching.

Programmatic Use

You can embed the agent directly inside your own loop by reusing the provided utilities:

import asyncio

from agents.recode.agent import ReCodeAgent
from envs.alfworld.env import AlfworldEnv

async def solve_once():
    config = {"split": "test", "task_types": ["put"], "max_depth": 10}
    env = AlfworldEnv(logger=None)
    agent = ReCodeAgent()
    init_info = env.reset(config)
    agent.reset(config, init_info)

    observations = init_info["observations"]
    while not env.is_done():
        actions = await agent.act(observations)
        observations = await env.run(actions)

    print(env.report())
    await env.close()

asyncio.run(solve_once())

The same pattern works for any Env implementation; be sure to pass a logger if you need file-backed traces.

Citation

@misc{yu2025recodeunifyplanaction,
      title={ReCode: Unify Plan and Action for Universal Granularity Control}, 
      author={Zhaoyang Yu and Jiayi Zhang and Huixue Su and Yufan Zhao and Yifan Wu and Mingyi Deng and Jinyu Xiang and Yizhang Lin and Lingxiao Tang and Yingchao Li and Yuyu Luo and Bang Liu and Chenglin Wu},
      year={2025},
      eprint={2510.23564},
      archivePrefix={arXiv},
      primaryClass={cs.AI},
      url={https://arxiv.org/abs/2510.23564}, 
}
Nearby in the ranking
Similar items