TL;DR
This project investigates whether structured multi-agent orchestration with execution-based validation can improve the reliability of LLM-generated backend algorithms compared to single-pass generation. Correctness is enforced through runtime execution and testing, not textual self-review.
Large Language Models (LLMs) have demonstrated strong capabilities in automated code generation. However, most existing systems rely on single-agent, single-pass generation, which often fails in scenarios requiring strict logical correctness—particularly in data structure and algorithm (DSA)–driven backend systems, where determinism, efficiency, and edge-case handling are critical.
This project proposes a multi-agent framework for backend logic synthesis, verification, and optimization using LLMs. The system decomposes code generation into specialized agents, orchestrated through a deterministic workflow graph.
Unlike prior approaches, correctness is enforced through execution and testing, rather than relying on textual self-evaluation. All experiments are fully reproducible using locally hosted LLMs, making the system suitable for academic research and evaluation.
Despite producing syntactically valid code, LLMs frequently:
- hallucinate incorrect logic
- miss edge cases
- generate inefficient implementations
- falsely validate incorrect solutions via self-review
This project is motivated by the following research question:
Can structured multi-agent orchestration with execution-based validation improve the reliability of LLM-generated backend algorithms compared to single-pass generation?
- Multi-agent decomposition of backend algorithm generation
- Execution-first correctness validation (runtime > text)
- Hybrid evaluation agent (deterministic + LLM-generated tests)
- Retry-controlled workflow using LangGraph
- Transparent state propagation and debugging
- Empirical comparison with single-agent baselines
- Optional algorithm memory for technique and pattern retrieval
- Fully local and reproducible LLM execution
The framework consists of specialized agents, each responsible for a well-defined role:
- Classifies problem type (Dynamic Programming, Graph, Data Structure, etc.)
- Selects appropriate algorithmic strategy
- Produces structured reasoning
- Optionally retrieves relevant techniques and patterns from a local vector database
- Converts plans into deterministic Python code
- Uses low-temperature generation for stability
- Performs static logical inspection
- Identifies potential flaws (non-authoritative)
- Executes code in a controlled environment
- Validates correctness using test cases
- Hybrid testing approach:
- deterministic tests for known DSA problems
- LLM-generated tests for unseen or open-ended cases
- Routes workflow based on execution outcome
- Controls retries and termination
- Improves time and memory efficiency
- Runs only after correctness is empirically verified
- Generates human-readable algorithm explanations
Workflow orchestration is implemented using LangGraph, enabling deterministic execution paths, bounded retries, and explicit state transitions.
The system optionally incorporates an algorithm memory module, implemented as a vector database:
- Stores common DSA techniques, patterns, and strategies
- Retrieved by the Planner Agent when applicable
- Enables reuse of known algorithmic approaches
- Reduces hallucinated or inconsistent planning decisions
This component is modular and can be enabled or disabled without affecting the core workflow.
- Code is executed, not just reviewed
- Runtime errors or incorrect outputs trigger regeneration
- Final acceptance depends solely on execution success
- One-pass LLM generation
- No execution feedback
- No retries or optimization
This contrast highlights the reliability gap between single-agent and execution-verified multi-agent systems.
| Category | Problem |
|---|---|
| Dynamic Programming | Climbing Stairs |
| Graph Algorithms | Task Dependency Resolution (Topological Sort) |
| Data Structures | LRU Cache (O(1) operations) |
Each problem was solved using:
- a single-agent LLM baseline
- the proposed multi-agent framework
Screenshots of execution results, evaluation traces, and agent workflows are included.
Multi-Agent-Project/
│
├── agents/
│ ├── planner_agent.py
│ ├── generate_agent.py
│ ├── review_agent.py
│ ├── evaluator_agent.py # Hybrid execution-based evaluator
│ ├── optimizer_agent.py
│ ├── explainer_agent.py
│ └── single_agent/
│ ├── run_single_agent.py # Baseline comparison
│ └── single_agent.py
│
├── graph/
│ └── workflow.py # LangGraph orchestration
│
├── memory/ # Optional algorithm memory module
│ ├── technique_store.py
│ ├── technique_retriever.py
│ ├── seed_techniques.py
│ └── TECHNIQUES.py
│
├── models/
│ └── all-MiniLM-L6-v2 # Embedding model (download if memory enabled)
│
├── prompts/
│ ├── planner.txt
│ ├── generator.txt
│ ├── review.txt
│ ├── evaluator.txt
│ ├── explain.txt
│ └── optimizer.txt
│
├── screenshots/
│ ├── single_agent/
│ └── multi_agent/
│
├── util/
│ ├── llm.py
│ ├── code_extractor.py
│ └── code_sanitize.py
│
├── app.py # Streamlit interface
├── requirements.txt
└── README.md
- Python
- LangChain
- LangGraph
- Ollama (local LLM inference)
- Streamlit
- FastAPI (optional)
- ChromaDB (optional algorithm memory)
All models are run locally via Ollama.
| Role | Model |
|---|---|
| Planner / Reviewer / Explainer | qwen2.5:7b-instruct |
| Generator / Optimizer | qwen2.5-coder:7b-instruct |
pip install -r requirements.txt
ollama servestreamlit run app.pypython -m agents.single_agent.run_single_agentscreenshots/
├── single_agent/
│ ├── q1_dp.png
│ ├── q2_graph.png
│ └── q3_lru.png
└── multi_agent/
├── q1_dp_eval.png
├── q2_graph_eval.png
└── q3_lru_eval.png
These screenshots demonstrate:
- execution-based correctness enforcement
- retry and regeneration behavior
- optimization improvements
- failure modes of single-agent generation
This project aligns closely with research interests in:
- Trustworthy AI
- Agentic LLM Systems
- Automated Software Engineering
- Execution-Verified Code Generation
Relevant programs:
- MScAC (AI) – University of Toronto
- MSc AI / CS – University of Zurich
- Automatic test generation with coverage guarantees
- Formal verification integration
- Cross-language backend support
- Larger model benchmarking (32B+ LLMs)
- Secure sandboxed execution environments
L. Sai Deekshith
AI / ML Research-Focused Developer
Interests:
Agentic AI · Generative AI · Reliable & Fine-Tuned LLMs · Code Generation Systems · Backend Engineering · Trustworthy ML & DL