Abstract
REPL-Plan is a novel planning framework that enables Large Language Models (LLMs) to solve complex, long-horizon tasks by interacting with a recursive Read-Eval-Print Loop (REPL). By treating sub-tasks as dynamic function calls that spawn new interactive environments, REPL-Plan combines the structural power of code with the flexible reasoning of natural language. Evaluated on ALFWorld, WebShop, and live web tasks, REPL-Plan demonstrates superior performance and robustness compared to existing text-based and code-augmented baselines, achieving a 97.0% success rate on ALFWorld and significantly outperforming competitors on real-world web navigation.
Introduction
While Large Language Models (LLMs) possess impressive common-sense reasoning, they often stumble when faced with complex, multi-step planning tasks. They are prone to "hallucinations" and struggle to maintain a coherent state over long horizons. Existing solutions generally fall into two camps: purely text-based methods like Chain-of-Thought, which lack the rigid structure needed for complex logic, and code-augmented methods that prompt the LLM to write a script. However, pure code is brittle; it struggles with "fuzzy" problems and requires the model to have perfect forethought—writing an entire bug-free script in one go is difficult even for humans.
REPL-Plan addresses these limitations by creating a top-down, interactive environment where the LLM can prototype, execute, and correct its plan line-by-line.
Methods: The LLM-REPL
The core innovation is the LLM-REPL. Unlike a standard code interpreter, an LLM-REPL is a stateful environment where the LLM can execute code line-by-line, allowing it to adapt to environment changes or errors immediately.
A key feature is Recursive Spawning. If the LLM encounters a complex sub-task, it can "call" that function even if it isn't predefined. The system then "spawns" a child LLM-REPL specifically for that sub-task. Arguments and return values are passed between parent and child REPLs using get_args() and answer(). This modular approach keeps the "main" plan clean and prevents the context window from becoming overwhelmed by the messy details of every sub-step.
Experimental Evaluation
The authors evaluated REPL-Plan on three challenging benchmarks:
- ALFWorld: A simulated household environment requiring agents to navigate rooms and manipulate objects.
- WebShop: A simulated e-commerce site where agents must search for and purchase items based on specific user requirements.
- Real-World Web Tasks: A new benchmark introduced in this paper involving navigation of live websites (e.g., Dell, BestBuy). These tasks feature massive observation data (4k to 20k tokens per page), making them significantly harder than simulated environments.
Results and Discussion
REPL-Plan achieved state-of-the-art performance across all tested domains. In ALFWorld, it reached a 97.0% success rate, surpassing the previous state-of-the-art baseline, THREAD (95.5%). In WebShop's complex settings, REPL-Plan reached a 52% success rate with GPT-4o-mini, significantly outperforming THREAD (21%).
The most striking results were observed in the Real-World Web benchmark. On complex tasks involving live websites, REPL-Plan achieved 39.6% of the expert score, while baselines like ReACT (17.6%) and THREAD (0.0%) struggled to handle the massive context.
Key Insights
- Top-Down Abstraction: REPL-Plan allows the model to stay at a high level of abstraction, delegating "fuzzy" or repetitive work to child processes.
- Interactivity: By seeing the result of a single line of code, the LLM can immediately pivot, making it far more robust than generating long scripts.
- Robustness to "Bugs": Ablation studies showed that the interactive nature of the REPL allows the LLM to catch and fix errors on the fly, even when given "buggy" demonstrations.
Conclusion
REPL-Plan demonstrates that combining the structural benefits of code with the interactive flexibility of a REPL significantly enhances LLM planning capabilities. While it currently relies on $k$-shot demonstrations and has higher computational costs due to its iterative nature, it provides a robust framework for tackling long-horizon, real-world tasks that were previously inaccessible to autonomous agents.
Summary updated