An AI-powered coding agent built with Python, LangChain, LangGraph, and Ollama.
The agent understands coding requests, creates implementation plans, generates and modifies Python files using tools, requests human approval before tool execution, performs functional testing, and uses bounded self-repair to fix failed implementations.
- 🧠 Planning — Creates a step-by-step implementation plan.
- 💻 Code Generation — Generates and modifies Python files using a local LLM.
- 🛠️ Tool Calling — Uses file-management tools to interact with the workspace.
- 👤 Human-in-the-Loop — Requests approval before executing tools.
- 🧪 Automated Testing — Executes generated Python programs and captures output/errors.
- ✅ Functional Testing — Compares expected and actual output.
- 🔧 Self-Repair — Attempts to fix code when testing fails.
- 🔁 Bounded Repair — Limits repair attempts to prevent endless loops.
- 💾 Checkpointing — Uses LangGraph checkpointing to maintain workflow state.
- 📊 LangSmith — Provides tracing and observability for the agent workflow.
- 🏠 Local LLM — Uses Ollama instead of a cloud-based LLM API.
USER
│
▼
PLANNER
│
▼
CODER
│
Tool required?
/ \
YES NO
│ │
▼ ▼
HITL TESTER
│ / \
▼ PASS FAIL
TOOLS │ │
│ ▼ ▼
└──────► END REPAIR
│
▼
CODER
│
▼
TESTER
Maximum repair attempts: 3
The user provides a coding task.
Example:
Create a Python file called calculator.py with a function add(a, b)
that returns the sum of two numbers, and print the result of adding 5 and 3.
The planner converts the request into a simple implementation plan.
Example:
1. Create calculator.py
2. Define add(a, b)
3. Return a + b
4. Print add(5, 3)
EXPECTED OUTPUT: 8
The coder receives:
- User request
- Implementation plan
- Previous test result
- Conversation/tool messages
It can use:
list_files
read_file
write_file
Before a tool is executed, the agent pauses and asks for approval.
Example:
--- HUMAN APPROVAL ---
Tool: write_file
Arguments:
{
"filename": "calculator.py",
"content": "..."
}
Allow this tool? (yes/no):
If approved, the tool executes.
If rejected, the request is returned to the coder.
The tester:
- Checks whether the file exists.
- Executes the Python program.
- Captures standard output and errors.
- Checks for runtime failures.
- Compares actual output with the expected output.
Example:
Expected: 8
Actual: 8
PASS
If the program produces an incorrect result:
Expected: 8
Actual: 2
the workflow enters the repair process:
FAIL
↓
REPAIR
↓
CODER
↓
read_file
↓
write_file
↓
TESTER
The agent can make up to 3 repair attempts.
| Technology | Purpose |
|---|---|
| Python | Core application |
| LangChain | LLM and tool integration |
| LangGraph | Agent workflow and state management |
| Ollama | Local LLM execution |
| LangSmith | Tracing and observability |
| TypedDict | Agent state definition |
ai-coding-agent/
│
├── src/
│ └── ai_coding_agent/
│ ├── __init__.py
│ ├── main.py
│ ├── graph.py
│ ├── state.py
│ ├── tools.py
│ └── tester.py
│
├── workspace/
│ └── .gitkeep
│
├── pyproject.toml
├── requirements.txt
├── uv.lock
├── .env.example
├── .gitignore
└── README.md
main.py— Handles user interaction, graph execution, and human approval.graph.py— Defines the LangGraph workflow, planner, coder, HITL, tools, tester, and repair logic.state.py— Defines the shared state used throughout the workflow.tools.py— Containslist_files,read_file, andwrite_file.tester.py— Executes generated Python files and performs runtime and functional testing.
git clone https://github.com/GreshmaMotupalli/ai-coding-agent.git
cd ai-coding-agentpython -m venv .venvActivate it on Windows:
.venv\Scripts\activatepip install -r requirements.txtInstall and run Ollama, then pull the model configured for the project.
Example:
ollama pull qwen3:4bSet the model in .env:
OLLAMA_MODEL=qwen3:4bAdd your LangSmith configuration to .env:
LANGSMITH_TRACING=true
LANGSMITH_API_KEY=your_api_key
LANGSMITH_PROJECT=ai-coding-agentNever commit your real API key to GitHub.
From the project environment:
cd src/ai_coding_agent
python main.pyYou: Create a Python file called calculator.py with a function
add(a, b) that returns the sum of two numbers, and print the
result of adding 5 and 3.
--- PLANNER ---
EXPECTED OUTPUT: 8
--- CODER ITERATION 1 ---
--- HUMAN APPROVAL ---
Tool: write_file
Allow this tool? (yes/no): yes
Tool approved.
--- CODER ITERATION 2 ---
--- TESTER ---
PASS
Expected: 8
Actual: 8
--- FINAL RESULT ---
PASS
Expected: 8
Actual: 8
File: calculator.py
Repair attempts: 0
When generated code produces an incorrect result, the agent enters a bounded repair loop.
--- TESTER ---
FAIL
Expected: 8
Actual: 2
--- REPAIR ATTEMPT 1 ---
--- CODER ITERATION 3 ---
The coder receives the previous test result and attempts to fix the code.
--- TESTER ---
PASS
Expected: 8
Actual: 8
--- FINAL RESULT ---
PASS
Expected: 8
Actual: 8
File: calculator.py
Repair attempts: 1
LangSmith is used to observe and debug the agent workflow.
A trace can show the sequence of operations:
Planner
↓
Coder
↓
Tool Call
↓
Human Approval
↓
Tool Execution
↓
Coder
↓
Tester
↓
Repair (if required)
This makes it easier to understand how the LangGraph agent executes each task.
This project demonstrates practical understanding of:
- LangChain
- LangGraph
- State-based agent workflows
- LLM tool calling
- Human-in-the-loop workflows
- LangGraph checkpointing
- Automated code execution
- Functional testing
- Error-driven self-repair
- Bounded agent loops
- Local LLMs with Ollama
- LangSmith observability
Possible future improvements include:
- More robust test-case generation
- Support for additional programming languages
- Better code validation
- Improved error classification
- More detailed execution reports
The current project intentionally focuses on a simple and understandable coding-agent architecture rather than adding unnecessary complexity.
Greshma Motupalli
GitHub: GreshmaMotupalli