Abstract
Current Large Language Model (LLM) reasoning frameworks often rely on verbose natural language, leading to high token costs and logical ambiguities. We present CodeAgents, a novel prompting framework that transforms natural-language reasoning into structured, modular pseudocode. By utilizing Python-like control structures and specialized agent roles, CodeAgents achieves state-of-the-art planning accuracy while reducing token consumption by up to 87%.
1. Introduction
While LLMs have demonstrated significant potential as planning engines, existing strategies such as Chain-of-Thought (CoT) and ReAct are limited by their reliance on unconstrained natural language. This verbosity results in high latency and API costs. Furthermore, the inherent ambiguity of free-form text complicates plan verification and error recovery. CodeAgents addresses these challenges by introducing a "token-aware" orchestration method that prioritizes logical precision and resource efficiency through codified reasoning.
2. Methodology
The core of CodeAgents is Codified Multi-Agent Reasoning. Instead of traditional prose-based reasoning, the framework utilizes a pseudocode template that incorporates Pythonic syntax, including typed variables and control flows (loops and if-else blocks).
The framework orchestrates three specialized agent roles:
- Planner: Responsible for synthesizing high-level pseudocode plans.
- ToolCaller: Executes specific tool invocations, such as API calls.
- Replanner: Analyzes structured error traces to surgically revise sub-plans.
A key feature is the use of Precondition Assertions. By embedding assert statements within the plan, agents can handle environmental discrepancies locally (e.g., via an else branch) rather than re-initiating the entire planning process, which is computationally expensive.
3. Experimental Setup
CodeAgents was evaluated across three diverse benchmarks to test different reasoning dimensions:
- VirtualHome: A 3D simulation environment for household tasks, testing long-horizon planning and error recovery.
- GAIA (General AI Assistant): Real-world tasks requiring complex tool integration and web browsing.
- HotpotQA: A multi-hop question-answering dataset requiring cross-document reasoning.
4. Results and Discussion
CodeAgents demonstrated substantial improvements in both performance and efficiency across all tested models, including Gemini-2.5, GPT-4, and LLaMA-4-Maverick.
4.1 Performance and Accuracy
The framework achieved a new state-of-the-art success rate of 56% on the VirtualHome benchmark. On the GAIA dataset, CodeAgents showed absolute gains of 3–36 percentage points over natural language baselines.
4.2 Token and Cost Efficiency
The transition to codified reasoning significantly reduced resource consumption. Input tokens were reduced by 55–87%, while output tokens decreased by 41–70%. On the GAIA benchmark using Gemini-2.5-Flash, the cost per task dropped from $11.05 to $3.60 (a 67.4% reduction) while simultaneously increasing accuracy by over 10%.
5. Conclusion
CodeAgents demonstrates that code is a more semantically dense and efficient medium for LLM reasoning than natural language. By providing a formal scaffold, the framework reduces hallucinations and improves interpretability. Future work will explore the integration of multi-modal execution layers and the application of this framework to more creative, conversational tasks.
Summary updated