File size: 24,623 Bytes
cdcce8d
 
e4328c4
cdcce8d
 
 
 
 
8edee29
 
 
 
dd60ba4
8edee29
 
 
 
 
bc7e224
8edee29
 
 
 
 
 
 
 
 
dd60ba4
8edee29
9d7e33b
 
bc7e224
8edee29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc7e224
 
 
292e56f
 
 
 
 
 
 
 
 
 
58cf7e4
292e56f
 
8edee29
 
 
 
 
bc7e224
 
8edee29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292e56f
8edee29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc7e224
 
 
 
8edee29
 
 
bc7e224
8edee29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc7e224
 
 
8edee29
bc7e224
8edee29
 
 
 
 
 
 
 
 
bc7e224
8edee29
bc7e224
8edee29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292e56f
 
8edee29
292e56f
 
8edee29
292e56f
 
8edee29
 
292e56f
 
bc7e224
292e56f
bc7e224
 
8edee29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc7e224
 
8edee29
 
 
bc7e224
8edee29
bc7e224
8edee29
bc7e224
8edee29
bc7e224
8edee29
bc7e224
8edee29
bc7e224
8edee29
 
 
bc7e224
 
 
8edee29
 
 
 
 
 
 
 
 
3ce60ce
19071f9
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
---
license: mit
title: Auto Dev Agent
sdk: gradio
emoji: πŸ’»
colorFrom: green
colorTo: indigo
---
# AutoDevAgent

> Autonomous code generation, execution, debugging, and testing β€” powered by LangGraph + Groq

[![HuggingFace Space](https://img.shields.io/badge/πŸ€—%20HuggingFace-Live%20Demo-FFD21E)](https://huggingface.co/spaces/SivaSai8143/auto-dev-agent)
[![Python](https://img.shields.io/badge/Python-3.10%2B-3776AB?logo=python&logoColor=white)](https://www.python.org/)
[![License](https://img.shields.io/badge/License-MIT-green)](LICENSE)
[![LangSmith](https://img.shields.io/badge/LangSmith-Tracing-1C3C3C?logo=langchain&logoColor=white)](https://smith.langchain.com)
[![W&B](https://img.shields.io/badge/Weights_%26_Biases-Tracking-FFBE00?logo=weightsandbiases&logoColor=000)](https://wandb.ai)

---

## What is this?

AutoDevAgent is a multi-agent AI system that takes a natural language task description and autonomously writes, runs, debugs, and tests Python or SQL code β€” without any manual intervention. It uses a LangGraph state machine to coordinate nine specialised agents, each responsible for one step of the software development loop: planning, generation, execution, error classification, debugging, test generation, explanation, and flowchart diagramming. The system is designed for developers who want to see how agentic AI handles real code quality requirements β€” not just code generation, but full-cycle verification including automated unit tests and self-healing retry loops.

---

## Live Demo

πŸ€— [Try it on HuggingFace Spaces](https://huggingface.co/spaces/SivaSai8143/auto-dev-agent)

<video src="https://huggingface.co/spaces/SivaSai8143/auto-dev-agent/resolve/main/assets/auto-dev-agent-demo.mp4" controls autoplay loop muted width="100%"></video>

---

## Tech Stack

| Component           | Tool                  | Purpose                                                              |
|---------------------|-----------------------|----------------------------------------------------------------------|
| Agent Orchestration | LangGraph 0.2+        | State machine with conditional edges, retry loops, and streaming     |
| LLM Framework       | LangChain 0.3+        | LLM client abstraction, message formatting, prompt templates         |
| LLM Provider        | Groq API              | Fast inference for Llama 3.1 8B, Llama 4 Scout 17B, Llama 3.3 70B   |
| State Management    | Pydantic V2           | Typed, validated, immutable pipeline state shared across all agents  |
| UI                  | Gradio 6.0+           | Streaming reactive UI with live pipeline visualiser                  |
| Python Execution    | subprocess (stdlib)   | Isolated Python code execution with 15-second timeout                |
| SQL Execution       | sqlite3 (stdlib)      | In-memory SQLite for SQL query execution and test assertions          |
| Observability       | LangSmith             | Per-call LLM tracing, latency, token counts, and prompt inspection   |
| Experiment Tracking | Weights & Biases      | Benchmark run logging, success rate trends, token usage metrics      |
| Deployment          | HuggingFace Spaces    | Zero-config hosting with Gradio auto-detection                       |

---

## Total Cost

| Item | Cost |
|---|---|
| HuggingFace Spaces hosting | Free |
| Groq API β€” Llama 3.1 8B (classification, flowchart) | Free (14,400 req/day) |
| Groq API β€” Llama 4 Scout 17B (planning, tests, explanation) | Free (100 emails/day) |
| Groq API β€” Llama 3.3 70B (code generation, debugging) | Free (1,000 req/day) |
| LangSmith β€” LLM tracing | Free (5,000 traces/month) |
| Weights & Biases β€” experiment tracking | Free (unlimited for personal use) |
| **Total** | **0** |

---
## Architecture

AutoDevAgent runs every task through a fixed-topology LangGraph state machine. The user's task enters the pipeline at the top, passes through a sequence of specialised agents, and either exits as a successful result or loops back through a debug cycle. The pipeline has two independent retry budgets β€” one for execution failures (code crashes) and one for test failures (code runs but tests don't pass) β€” so neither type of failure escalates to human intervention prematurely.

### Agent Pipeline

```
User Task
    β”‚
    β–Ό
[Clarification] ──── unclear ────► ask user, then restart
    β”‚ clear
    β–Ό
[Language Detect] ──────────────── Python / SQL / override
    β”‚                               (model routing also runs here,
    β”‚                                before the LangGraph pipeline starts)
    β–Ό
[Planner] ──────────────────────── breaks task into labelled steps
    β”‚
    β–Ό
[Code Generator] ───────────────── writes Python function or SQL query
    β”‚
    β–Ό
[Executor] ─────────────────────── runs code in subprocess / SQLite
    β”‚
    β”œβ”€β”€ PASS ──────────────────────────────────────────────┐
    β”‚                                                       β”‚
    └── FAIL ──► [Error Classifier] ──► [Debug Agent] ─── retry (max 5)
                                                β”‚
                                        max retries hit?
                                                β”‚
                                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                              execution fail             test fail
                                   β”‚                         β”‚
                            [HITL panel]             regen (max 2Γ—)
                            user edits code          then PARTIAL_SUCCESS

    PASS ──► [Test Generator] ──► [Test Runner]
                                       β”‚
                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       PASS                          FAIL
                        β”‚                              β”‚
                   [Explanation]            [Debug Agent] ──► retry (max 3)
                   [Flowchart]                         β”‚
                        β”‚                    max test-fix cycles hit?
                   [SUCCESS]                           β”‚
                                               [PARTIAL_SUCCESS]
```

### Project Structure

```
autodevagent/
β”‚
β”œβ”€β”€ app.py                          # Gradio UI entry point β€” wires all components
β”œβ”€β”€ config.py                       # All settings: API keys, model names, retry limits
β”œβ”€β”€ requirements.txt                # Pinned dependencies
β”‚
β”œβ”€β”€ agents/
β”‚   β”œβ”€β”€ clarification_agent.py      # Checks if the task is specific enough to execute
β”‚   β”œβ”€β”€ code_generator.py           # Writes Python functions or SQL queries
β”‚   β”œβ”€β”€ debug_agent.py              # Diagnoses failures and rewrites code to fix them
β”‚   β”œβ”€β”€ detect_agent.py             # Classifies task language + scope gate + coding gate
β”‚   β”œβ”€β”€ explanation_agent.py        # Writes plain-English explanation of the final code
β”‚   β”œβ”€β”€ flowchart_agent.py          # Generates Mermaid.js logic diagram
β”‚   β”œβ”€β”€ model_router.py             # Assigns best-fit model to each agent role
β”‚   β”œβ”€β”€ planning_agent.py           # Decomposes the task into labelled plan steps
β”‚   β”œβ”€β”€ polisher_agent.py           # Optional safe refactors with diff display
β”‚   β”œβ”€β”€ test_generator.py           # Writes unittest (Python) or assertion (SQL) tests
β”‚   └── __init__.py
β”‚
β”œβ”€β”€ pipeline/
β”‚   β”œβ”€β”€ graph.py                    # LangGraph StateGraph β€” all nodes, edges, routing
β”‚   β”œβ”€β”€ state.py                    # Pydantic V2 PipelineState β€” single source of truth
β”‚   β”œβ”€β”€ router.py                   # Conditional edge helpers
β”‚   └── __init__.py
β”‚
β”œβ”€β”€ executors/
β”‚   β”œβ”€β”€ python_executor.py          # Runs Python code in a subprocess with timeout
β”‚   β”œβ”€β”€ sql_executor.py             # Runs SQL against in-memory SQLite
β”‚   β”œβ”€β”€ test_runner.py              # Runs generated unittest file, parses results
β”‚   └── __init__.py
β”‚
β”œβ”€β”€ ui/
β”‚   β”œβ”€β”€ pipeline_visualiser.py      # Animated HTML/CSS pipeline card renderer
β”‚   β”œβ”€β”€ components.py               # Reusable Gradio component builders
β”‚   β”œβ”€β”€ session_history.py          # Per-session run history tracker
β”‚   └── __init__.py
β”‚
β”œβ”€β”€ evaluation/
β”‚   β”œβ”€β”€ benchmark.py                # 5 fixed benchmark tasks (3 Python + 2 SQL)
β”‚   β”œβ”€β”€ metrics.py                  # Aggregates success rate, tokens, iterations
β”‚   └── __init__.py
β”‚
β”œβ”€β”€ observability/
β”‚   β”œβ”€β”€ langsmith_tracer.py         # LangSmith trace setup and token extraction
β”‚   β”œβ”€β”€ wandb_tracker.py            # W&B benchmark run logger
β”‚   └── __init__.py
β”‚
└── utils/
    β”œβ”€β”€ dependency_manager.py       # Auto-installs missing pip packages at runtime
    β”œβ”€β”€ error_cache.py              # Tracks seen errors to force different fix strategies
    β”œβ”€β”€ token_counter.py            # Accumulates token usage across all LLM calls
    └── __init__.py
```

---

## Features

### Core Agent Loop

1. **Clarification gate** β€” before running anything, checks if the task is specific enough. If ambiguous, asks one targeted question and waits for the user's answer before proceeding.
2. **Non-coding gate** β€” rejects general knowledge questions with a friendly message. Only blocks on high/medium confidence to avoid false positives.
3. **Scope gate** β€” rejects full-project requests ("build a YouTube app"). Any single SQL query is always in-scope regardless of complexity.
4. **Language auto-detection** β€” fast 8B model classifies Python vs SQL. User can override via radio button at any time.
5. **Task-aware model routing** β€” analyses the task and assigns the best model to each agent role. Reasoning-heavy and SQL tasks route Llama 3.3 70B to the generator and debugger; planning, tests, and explanation always use Llama 4 Scout; error classification and flowchart use Llama 3.1 8B.
6. **Structured planning** β€” PlanningAgent decomposes the task into typed, labelled steps before any code is written.
7. **Code generation** β€” CodeGeneratorAgent writes a self-contained Python function or SQL query using the plan as a scaffold.
8. **Sandboxed execution** β€” Python code runs in a `subprocess` with a 15-second timeout; SQL runs in an in-memory SQLite instance with a 10-second timeout.
9. **Error classification** β€” fast 8B model classifies every failure as `syntax | runtime | logic | timeout` before the debug agent runs, so the fix strategy is targeted rather than generic.
10. **Self-healing debug loop** β€” DebugAgent rewrites the code up to 5 times per attempt. After 5 failures it attempts a full code regeneration (up to 2 regens). For execution failures that exhaust all retries, escalates to Human-in-the-Loop.
11. **Error cache** β€” tracks every error message seen in the current run. If the same error recurs, forces the debug agent to try a completely different fix strategy instead of repeating the same failing approach.
12. **Two-tier retry budgets** β€” test failures and execution failures have completely separate retry counters (`max_test_fix_retries=3`, `max_debug_retries=5`). Test failures never escalate to HITL β€” they exit as `PARTIAL_SUCCESS` after all retries.
13. **Human-in-the-Loop panel** β€” when execution failures exhaust all retry budgets, presents the user with the last error, a code editor, and fix-strategy options. Resubmission re-runs the full pipeline with the user's edits as context.

### SQL Support

- **Schema inference** β€” for SQL tasks with no schema given, the PlanningAgent infers a realistic table structure from the task description.
- **Dummy data generation** β€” the planner generates `INSERT` statements with representative data so the query can be executed and verified against known values.
- **SQLite execution** β€” all SQL runs against an in-memory SQLite database; no external database required.
- **Assertion-based tests** β€” SQL tests use positional result access (`row[0]`, `row[1]`) rather than column names, ensuring correctness even for aggregate expressions like `MAX(salary)` that SQLite returns as raw strings.

### Test Generation

After code executes successfully, TestGeneratorAgent writes a `unittest` test suite (Python) or a set of Python `sqlite3` assertion tests (SQL). Tests are frozen as a stable target β€” the same suite runs on every retry cycle so the debug agent has a consistent benchmark to aim for. Tests cover a happy-path case, an edge case, and a boundary case, each with a docstring explaining the exact input and expected outcome. Tests must use independently derived input values β€” not the same example values shown in the code's execution output.

### Auto-Polisher

PolisherAgent is implemented as a standalone module (`agents/polisher_agent.py`) that applies safe, cosmetic refactors β€” renaming unclear variables, adding docstrings, extracting repeated logic into helpers, removing redundant code β€” and returns a `difflib` unified diff of the changes. The agent is fully implemented but is not yet connected to the Gradio UI; it is ready to be wired in as a "Polish" button in a future release.

### Code Explanation & Flowchart

ExplanationAgent writes a plain-English walkthrough of how the final code works, targeted at someone who can read code but didn't write it. FlowchartAgent generates a Mermaid.js `graph TD` flowchart of the logic. Flowcharts are only generated for Python code longer than 20 lines (or always for SQL) β€” below that threshold, the diagram adds no value over reading the code directly. The Mermaid output goes through a four-layer sanitisation pipeline: prompt rules β†’ LLM syntax validation β†’ LLM fix retry β†’ parse-and-rebuild in `app.py`. The rebuild step also drops orphaned nodes (nodes not reachable from the start node via BFS) automatically.

### Observability

- **LangSmith tracing** β€” when `enable_langsmith=True`, every LLM call is traced with prompt, response, latency, and token count. Key validation runs at startup to silently disable tracing if the API key is invalid.
- **Token counter** β€” `TokenUsage` accumulates prompt and completion tokens across all agents in a run. Displayed live in the stats strip after each run.
- **Rate limit warning** β€” monitors request count against Groq's free tier limit (30 RPM). Fires a warning at 80% usage.
- **Model switcher** β€” dropdown in the UI lets users pin a specific model or leave it on Auto for the model router to decide.
- **Error cache** β€” `ErrorCache` in `utils/error_cache.py` stores a hash of every error seen in the current run. Injected into the debug prompt to force novel fix attempts.

### Pipeline Visualiser

The right column of the UI shows a live animated pipeline card for each agent node. Cards are rendered as a complete HTML/CSS string on every LangGraph streaming yield β€” the current state is baked directly into CSS class names (`av-running`, `av-done`, `av-pending`, `av-error`) so no JavaScript is needed. Each card shows the agent name, its assigned model (from the model router), and its current status with a colour-coded glow animation.

### Evaluation Harness

A built-in benchmark runs 5 fixed tasks through the full pipeline:

| # | Task                       | Language |
|---|----------------------------|----------|
| 1 | Reverse a string           | Python   |
| 2 | Fibonacci sequence         | Python   |
| 3 | Find duplicates in a list  | Python   |
| 4 | Top N customers by revenue | SQL      |
| 5 | Department headcount query | SQL      |

Results are logged to W&B with success rate, average debug iterations, average tokens per task, and total execution time. The harness is accessible from the **Evaluation harness** accordion in the UI.

---

## Benchmark Results

All 5 tasks run end-to-end through the full pipeline β€” clarification β†’ detect β†’ plan β†’ generate β†’ execute β†’ test β†’ explain β€” with no manual intervention. Model: Llama 4 Scout 17B for all primary roles Β· Llama 3.1 8B for classification and flowchart.

| Task                     | Language | Status  | Iterations | Tokens | Time   |
|--------------------------|----------|---------|------------|--------|--------|
| Reverse string           | Python   | βœ… Pass | 0          | 3,390  | 3.5s   |
| Fibonacci sequence       | Python   | βœ… Pass | 0          | 3,899  | 4.2s   |
| Find duplicates          | Python   | βœ… Pass | 0          | 4,124  | 4.2s   |
| Top customers by revenue | SQL      | βœ… Pass | 0          | 3,173  | 3.7s   |
| Department headcount     | SQL      | βœ… Pass | 0          | 4,308  | 11.5s  |

**5/5 tasks passed Β· 0 debug iterations on every task Β· avg 3,779 tokens/task Β· avg 5.4s/task**

All tasks passed on the first generation attempt with zero debug iterations needed. Python tasks each ran 6 unit tests; SQL tasks ran 3 assertion tests. All 24 tests passed across the full run.

---

## Getting Started

### Prerequisites

- Python 3.10 or higher
- A [Groq API key](https://console.groq.com) β€” required
- A [LangSmith API key](https://smith.langchain.com) β€” optional, for LLM tracing
- A [Weights & Biases API key](https://wandb.ai) β€” optional, for benchmark tracking

### Installation

```bash
# 1. Clone the repo
git clone https://github.com/sivasaiyadav8143/autodevagent.git
cd autodevagent

# 2. Install dependencies
pip install -r requirements.txt

# 3. Set up environment variables
cp .env.example .env
# Edit .env and add your API keys

# 4. Run
python app.py
# Opens at http://localhost:7
```

### Environment Variables

| Variable            | Required | Where to get it                                                   |
|---------------------|----------|-------------------------------------------------------------------|
| `GROQ_API_KEY`      | βœ… Yes   | [console.groq.com](https://console.groq.com)                     |
| `LANGSMITH_API_KEY` | Optional | [smith.langchain.com](https://smith.langchain.com)               |
| `LANGCHAIN_PROJECT` | Optional | Any string β€” groups traces in LangSmith. Default: `autodevagent` |
| `WANDB_API_KEY`     | Optional | [wandb.ai/authorize](https://wandb.ai/authorize)                 |
| `WANDB_PROJECT`     | Optional | Any string β€” groups runs in W&B. Default: `autodevagent`         |

To enable LangSmith tracing, also set `enable_langsmith=True` in your `.env`.
To enable W&B tracking, also set `enable_wandb=True` in your `.env`.

---

## Usage

### Running a Python Task

1. Type a task in the **Task description** box, e.g. *"Write a function that checks if two strings are anagrams, case-insensitive, ignoring spaces and punctuation"*
2. Leave **Language** on `Auto (recommended)` β€” the detect agent will pick Python.
3. Leave **Model** on `Auto` β€” the model router will assign the best model per role.
4. Click **β–Ά Run**.
5. Watch the pipeline visualiser animate each agent as it fires.
6. Results appear in the **Code**, **Tests**, **Explanation**, and **Flowchart** tabs.

### Running a SQL Task

1. Type a SQL task, e.g. *"Write a query to find the second highest salary from an employees table. Assume no schema is given β€” infer it."*
2. Language will be auto-detected as SQL. The planner will infer an `employees` schema and generate `INSERT` dummy data.
3. The SQL executor runs the query against an in-memory SQLite database.
4. The test generator writes three assertion tests using positional row access.

### Running the Benchmark

1. Scroll to the **Evaluation harness** accordion at the bottom of the left column.
2. Select a model from the dropdown (or leave on Auto).
3. Click **β–Ά Run benchmark**.
4. Results are displayed as a Markdown table and logged to W&B if enabled.

---

## Known Limitations

1. **SQL test data is inferred, not real** β€” the planner generates dummy `INSERT` data based on the task description. For complex business queries, the dummy data may not cover all edge cases, causing tests to pass on simplified data but fail on real data.
2. **subprocess isolation, not Docker** β€” Python code runs in a subprocess on the host machine. There is no container sandbox, so code has filesystem and network access. Do not run untrusted code.
3. **No C-extension support** β€” packages that require C compilation (e.g. `numpy`, `pandas` with native binaries) may not install correctly in the subprocess environment on all platforms.
4. **Mermaid diagram quality degrades for complex logic** β€” deeply nested conditionals, multiple recursive branches, and long functions produce simplified or inaccurate flowcharts. The diagram describes logical flow, not exact control flow.
5. **Groq free tier rate limits** β€” the free tier allows 30 requests per minute. A single pipeline run with multiple debug retries can use 10–15 requests. The rate limit warning fires at 80% usage; heavy benchmarking may hit the limit.

---

## Future Improvements

1. **Docker sandbox** β€” run generated code inside a Docker container for true isolation and consistent package environments.
2. **SQL stress test mode** β€” generate multiple sets of dummy data with edge cases (nulls, empty tables, duplicate keys) and run the query against all of them.
3. **JavaScript and Bash support (V2)** β€” extend the pipeline to support JS (Node.js subprocess) and Bash scripts.
4. **Full database support** β€” connect to PostgreSQL or MySQL instead of SQLite, allowing real schema and data to be used for SQL tasks.
5. **Persistent session storage** β€” save session history to disk so completed runs survive page refreshes.
6. **CI/CD for automated benchmarks** β€” run the benchmark harness on every commit and post results to W&B automatically.

---

## Design Decisions

**Why LangGraph over a manual loop**

The debug loop β€” generate β†’ execute β†’ fail β†’ classify β†’ fix β†’ repeat β€” is a cycle with conditional exits. Implementing this as a manual `while` loop with if-else branches works but becomes unmaintainable as retry budgets, regen counters, and test-fix cycles are added. LangGraph expresses the same logic as a state machine with named nodes and typed edges. Each node is a pure function (receives state, returns partial update), making the flow readable, debuggable, and easy to extend with new agents.

**Why Pydantic V2 for pipeline state**

Every agent in the pipeline reads from and writes to a shared `PipelineState` object. Using Pydantic V2 means every field is typed and validated β€” a bug where an agent sets `debug_iterations` to a string instead of an int is caught immediately at assignment time, not three agents later when something tries to compare it. The `model_copy()` method makes immutable partial updates clean and safe.

**Why the error cache forces a different fix strategy**

Without the error cache, the debug agent will sometimes generate the same broken code twice in a row β€” especially for logic errors where the first "fix" attempts the same approach. The cache stores a hash of every error message seen in the current run and injects the full history into the debug prompt: *"You have already tried X and Y β€” both produced the same error. Try a completely different approach."* This breaks the loop and forces genuine variation in fix strategies.

**Why the flowchart has a 20-line threshold**

For short functions (under 20 lines), a Mermaid flowchart adds little beyond what reading the code directly provides. The diagram overhead β€” one LLM call, post-processing, rendering β€” is only worth it when the function is long enough that the logical flow is non-obvious. SQL queries always get a flowchart because even a short query (`SELECT MAX(salary) FROM employees`) has a meaningful multi-step logical flow (load table β†’ find maximum β†’ return result) that benefits from visualisation.

---

## License

MIT β€” see [LICENSE](LICENSE) for details.

---

## Author

**Siva Sai Yadav**

[HuggingFace](https://huggingface.co/SivaSai8143) Β· [LinkedIn](https://linkedin.com/in/sivasai-mudugandla/)

---

*Built as an open-source portfolio project using entirely free infrastructure.*