Abstract
CodeTree is a novel multi-agent framework that treats code generation as a structured tree search rather than a linear process. By orchestrating specialized LLM agents—Thinker, Solver, Debugger, and Critic—it systematically explores different coding strategies. CodeTree achieves state-of-the-art results on benchmarks like HumanEval (95.1%) and CodeContests (43.0%), outperforming traditional iterative refinement and brute-force sampling methods.
Introduction
Large Language Models (LLMs) have significantly advanced automated code generation but still struggle with complex algorithmic problems. Current methodologies typically rely on two suboptimal strategies: brute-force sampling, which is computationally expensive, and iterative refinement, which often traps models in "local optima" if the initial approach is fundamentally flawed. CodeTree addresses these gaps by enabling LLMs to explore the search space of code more like human experts—considering multiple high-level strategies and dynamically deciding when to refine or abandon a specific path.
Methodology
The CodeTree framework organizes code generation into a heterogeneous tree where the root is the problem specification and each node represents a potential solution. The search is managed by four specialized agents:
- Thinker: Proposes multiple high-level natural language strategies (e.g., hash maps vs. sliding windows).
- Solver: Implements a specific strategy into an initial code version.
- Debugger: Refines code based on execution feedback and error messages.
- Critic: Acts as the tree manager, evaluating nodes to decide whether to Refine, Abort, or Accept a solution.
Unlike fixed search algorithms like BFS or DFS, CodeTree uses the Critic agent to dynamically allocate search budget based on problem difficulty, pruning unproductive branches early.
Experimental Setup
The framework was evaluated across seven diverse benchmarks to test various levels of complexity:
- HumanEval / HumanEval+ and MBPP / MBPP+: Standard Python function completion.
- CodeContests: High-difficulty competitive programming tasks.
- APPS: Problems ranging from introductory to competition levels.
- SWE-bench: Real-world GitHub issues requiring repository-level modifications.
Results and Analysis
Using GPT-4o as the base model, CodeTree established new performance benchmarks, achieving 95.1% on HumanEval and 98.7% on MBPP. On the high-difficulty CodeContests benchmark, it reached 43.0%, a significant improvement over standard resampling (32.7%) and iterative refinement (41.8%).
Key insights from the evaluation include:
- Breadth vs. Depth: Exploring diverse strategies (breadth) is often more effective than deep debugging of a single flawed approach. If the Thinker provides a better starting point, success is more likely.
- Critic Importance: Ablation studies identify the Critic agent as the most vital component for pruning bad paths and verifying solutions beyond visible tests.
- Efficiency: CodeTree demonstrated higher token efficiency than OpenAI’s o1-preview on several benchmarks, suggesting that explicit agentic search can be more cost-effective than implicit chain-of-thought.
- Scaling: The framework's effectiveness scales with the base model's reasoning capabilities; while GPT-4o excelled, smaller models like Llama-3.1-8B showed limited gains.
Conclusion
CodeTree demonstrates that agent-guided tree search is a powerful paradigm for complex code generation. By moving beyond linear refinement, it allows for more robust exploration of the solution space. Future work will focus on reducing the cost of multi-agent orchestration and incorporating qualitative metrics such as code maintainability and computational complexity.
Summary updated