Source-linked AI summary

Development of an Autonomous AI Coding Agent using Monte Carlo Tree Search (MCTS) and Gemini LLM Frameworks

Pravin Game, Vipin Ramakrishnan, Prathamesh Wagh

arXiv:2608.29096v1cs.LGcs.AI

TL;DR

One-shot code generation struggles with complex logic, optimization, and hallucinated errors. This paper presents an autonomous Gemini-powered coding agent that uses MCTS and self-criticism to search and refine implementations, producing more reliable and optimized code than zero-shot generation.

  • Problem

    One-shot code-generation systems struggle with complex logical dependencies, optimization, and logical hallucinations in executable code.

  • Method

    The agent treats code generation as MCTS-based search, evaluating LLM-generated alternatives with a self-critic and backpropagating scores to refine solutions.

  • Results

    The MCTS-based agent improved reliability, technical optimization, syntactic correctness, and production-environment optimization compared with zero-shot generation.

  • Takeaways & Limitations

    Treating coding as search-based refinement can move LLM-generated programming from zero-shot output toward production-oriented software.

  • Takeaways & Limitations

    The current system remains scoped by planned extensions for rare programming languages, real-time collaboration, and offline local-LLM operation.

Abstract

from arXiv · show

The ongoing changes in software engineering requirements have created a substantial need for automated tools which can create secure source code from natural language input. The performance of traditional Large Language Models (LLMs) becomes limited by their "one-shot" capability which results in logical hallucinations together with reduced algorithmic performance during complicated operations. The research presents an autonomous AI Coding Agent which establishes a connection between LLM-generated content and production-ready software through its organized methodology for decision making. Our framework uses the Gemini 2.5 Flash API for essential reasoning capabilities while employing a tailored Monte Carlo Tree Search (MCTS) method to solve code generation challenges as a search operation. The agent uses a "Self-Critic" evaluator system to test different implementation methods which it ranks according to their accuracy and difficulty level before it improves its operational framework through backpropagation. The system operates through a Flask-based web interface which delivers instant feedback together with syntax highlighting features. Our experimental results show that the MCTS-based method achieves a 92% success rate on complex logical prompts while surpassing standard zero-shot generation models.

Chapter 1: Introduction

The chapter introduces an autonomous AI Coding Agent designed to address production challenges in AI-generated code. It combines Flask, LangChain, and MCTS with Fast Mode and MCTS Mode to support organized code development and quality assurance.

  • Motivation: The proposed agent autonomously executes software-development steps while using the Gemini 2.5 Flash API to analyze user needs and create code.It is presented as a response to the time programmers spend on manual debugging and complex algorithm improvement.
  • Problem Statement: AI-based code generation faces one-shot inaccuracy, optimization deficiencies, and logical hallucinations that reduce production effectiveness.These issues involve missed complex dependencies, weak time and memory optimization, and syntactically correct code containing execution-breaking logical errors.
  • Objectives: The project combines a Flask web interface, secure LangChain-based code extraction, and an independent MCTS module for quality assurance and search.These components are defined as the project’s three main implementation objectives.
  • Operation Modes: The system provides Fast Mode for standard procedures and MCTS Mode for advanced algorithm development.The two modes are intended to support different levels of coding complexity.

Chapter 2: Literature Survey

Automated programming has progressed from rule-based templates to Transformer- and LLM-based code generation. Current approaches combine MCTS search, self-criticism, grounding, and orchestration frameworks to improve automated software development.

  • Evolution of Automated Programming: Transformer models and LLMs are now essential technologies for automatic code generation in modern software development.Automated programming evolved from rule-based templates through early region-based and convolutional networks to deep learning systems.
  • Monte Carlo Tree Search: MCTS explores complex decision trees by balancing new-path exploration with exploitation of successful paths.Its effectiveness was demonstrated in Go, and combining MCTS with AlphaCode improved competitive programming performance.
  • Reasoning and Grounding: Self-Criticism, Tree-of-Thought, and Dual-Prompting improve LLM outputs by enabling grounding, self-assessment, and hallucination correction before execution.RAG is also used to maintain policy compliance in critical safety systems.
  • Agent Orchestration: LangChain and Flask provide orchestration layers for controlling conversation flow, preserving user information, and building small-scale AI systems.Recent studies validated Gemini-class models within these frameworks for automated algorithm generation and evaluation.

Chapter 3: System Architecture

Chapter 3 presents a modular client-server architecture that separates the interface from computational services for MCTS and LLM operations. It combines a lightweight web stack with three operational components for code-version search, self-evaluation, and orchestration.

  • Architecture: The client-server architecture separates frontend interaction and code visualization from backend MCTS operations and LLM interactions.Its modular design supports adopting advanced models without fully redeveloping the user interface.
  • Technology Stack: Flask serves as the backend framework because it integrates with Python-based AI libraries and manages API requests efficiently.The architecture is designed for asynchronous AI operations while remaining lightweight and robust.
  • Technology Stack: The frontend uses HTML5, CSS3, Tailwind, and Marked.js to provide responsive interaction and readable generated code blocks.Marked.js displays generated code blocks, while Tailwind supports the responsive design.
  • Technology Stack: LangChain creates complex prompt chains, while Google Gemini 2.5 Flash provides the primary reasoning engine for code generation and assessment.This pairing supports the system’s AI orchestration layer.
  • Operational Components: The MCTS Node Manager stores code versions, the Evaluator scores generated code from 0.0 to 1.0, and the Search Orchestrator applies UCB1.The orchestrator discovers programming concepts and improves existing top-performing code segments.

Chapter 4: Methodology

Chapter 4 presents code generation as a search problem implemented through repeated MCTS processes rather than a single output. The method combines UCB1-guided node selection with dual-prompt evaluation of correctness, complexity, and readability.

  • The system treats code generation as a search problem executed through four separate repeated processes, unlike standard agents that deliver a single output.
  • UCB1 selects promising nodes by combining known performance with exploration of unexplored features.
  • After selection, the LLM expands the search tree with an improved or alternative child deployment to enhance logic processing.
  • Dual prompting assigns code construction to a Developer prompt and assessment to a Critic prompt.
  • The Critic measures Factuality (correctness), Efficiency (complexity), and Clarity (readability), returning JSON that guides the MCTS algorithm’s next step.

Chapter 5: Implementation Details

Chapter 5 describes the MCTSSearch class as the agent’s core search component, with modular separation from the web server. Its search function builds a root node from a natural-language request and runs simulations to identify the most logically valid implementation.

  • MCTSSearch Architecture: The MCTSSearch class controls the search-tree operations that provide the agent’s core intelligence.
  • MCTSSearch Architecture: The design separates search operations from the web server, enabling independent system evaluation and performance improvement.
  • Search Procedure: The search function creates a root node from the user’s natural-language request and performs multiple simulations to determine the most logically valid code implementation.

Code Implementation of the Search Loop:

The implementation combines custom logic with established AI libraries to support the system’s operation.

  • Code Implementation of the Search Loop:: The system uses a mixed strategy combining custom logic with established AI libraries.The implementation is summarized as a combination of custom and established components.

Chapter 6: Results and Testing

Chapter 6 reports that the MCTS-driven agent improved coding reliability and technical optimization by treating code generation as a search-and-refine process. Testing also showed that MCTS could correct logic hallucinations, detect edge-case failures, and iteratively improve code toward complete requirement compliance, while the web interface supported professional browser-based development.

  • The MCTS-driven agent improved reliability and technical optimization by treating coding as a search-and-refine process.
  • Testing across devices verified responsive web-interface behavior, while Copy Code and real-time markdown rendering reduced manual formatting and transfer tasks.
  • MCTS Mode identified and corrected logic hallucinations that appeared during initial Fast Mode generation.
  • The Self-Critic evaluator detected edge-case failures involving empty inputs and extensive data sets.
  • The agent improved code iteratively until it achieved complete compliance with all requirements.

Chapter 7: Conclusion

The project concludes that combining LLMs with software structures, MCTS, and Self-Critic evaluation produces syntactically correct, production-oriented code while automating assessment and improvement. Future work focuses on broader language support, collaboration, offline local models, and runtime-informed error analysis.

  • MCTS addresses hallucination in AI-generated content while the system targets syntactical correctness and production-environment optimization.The conclusion presents structured search as central to reliable coding-agent development.
  • The system provides a scalable foundation for AI-powered software-engineering tools and automates assessment and improvement, including edge-case testing.This allows developers to concentrate on architectural design work.
  • Combining the Self-Critic Evaluator with a search tree delivers the tool’s highest efficiency for academic and professional use.The passage identifies this combination as the mechanism behind the tool’s effectiveness.
  • Future development should extend full-format matching to rare programming languages, add WebSocket-based real-time collaboration, and integrate quantized local models for offline work.The proposed extensions require expanded regex and parsing logic, while local models would reduce reliance on external services.
  • Advanced error analysis should use runtime data from actual error locations to update the Correct score and improve correctness.This proposal would connect observed runtime failures to simulator-based evaluation.
Loading 2608.29096v1…