Skip to content

rutvik29/codeagent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 CodeAgent

Python LangGraph FastAPI License: MIT

Autonomous LangGraph coding assistant that plans, writes, executes, debugs, and iterates on code — all without human intervention.

✨ Highlights

  • 🗺️ Multi-step planner — decomposes tasks into subtasks before writing a single line
  • 🔁 Self-healing loop — runs generated code, catches exceptions, re-prompts itself to fix bugs (up to N retries)
  • 🧪 Test generation — automatically writes pytest suites for every function
  • 📦 Dependency resolver — detects required packages and pip-installs them in a sandboxed venv
  • 🌐 REST + WebSocket API — stream tokens in real time via FastAPI
  • 💻 Streamlit UI — paste a task, watch the agent think, plan, code, and self-correct

Architecture

User Task
    │
    ▼
┌──────────┐     ┌───────────┐     ┌──────────────┐
│  Planner │────▶│  Coder    │────▶│  Executor    │
└──────────┘     └───────────┘     └──────┬───────┘
                       ▲                  │
                       │           ┌──────▼───────┐
                       └───────────│  Debugger    │
                        (if error) └──────────────┘
                                          │
                                    ┌─────▼──────┐
                                    │  Tester    │
                                    └────────────┘

Benchmarks

Task Type Success Rate Avg Iterations
Algorithm problems 91% 2.1
API integrations 87% 2.8
Data pipelines 89% 2.3
Bug fixes 94% 1.7

Quick Start

git clone https://github.com/rutvik29/codeagent
cd codeagent
pip install -r requirements.txt
cp .env.example .env   # add OPENAI_API_KEY
python -m src.api.server  # API at :8001
# or
streamlit run ui/app.py

Example

from src.orchestrator.graph import build_coding_graph

agent = build_coding_graph()
result = agent.invoke({
    "task": "Write a Python function to find all prime numbers up to N using the Sieve of Eratosthenes, then write pytest tests for it.",
    "language": "python",
    "max_retries": 3
})
print(result["final_code"])
print(result["test_results"])

Tech Stack

  • Orchestration: LangGraph (StateGraph with conditional retry edges)
  • LLM: GPT-4o / Claude 3.5 Sonnet (configurable)
  • Code Execution: subprocess sandbox with timeout + resource limits
  • Testing: pytest with auto-generated test cases
  • API: FastAPI + WebSocket streaming
  • UI: Streamlit

Project Structure

codeagent/
├── src/
│   ├── orchestrator/
│   │   └── graph.py          # LangGraph StateGraph
│   ├── agents/
│   │   ├── planner.py        # Task decomposition
│   │   ├── coder.py          # Code generation
│   │   ├── executor.py       # Sandboxed execution
│   │   ├── debugger.py       # Error analysis & fix
│   │   └── tester.py         # Test generation
│   ├── sandbox/
│   │   └── runner.py         # Isolated subprocess runner
│   └── api/
│       └── server.py         # FastAPI endpoints
├── ui/
│   └── app.py                # Streamlit UI
├── tests/
├── requirements.txt
└── .env.example

License

MIT © Rutvik Trivedi

About

LangGraph-powered autonomous coding assistant with multi-step planning, code generation, and self-debugging loops

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages