A multi-agent AI system that generates code through a collaborative workflow using OpenRouter API. The system uses 5 specialized agents working together to design, implement, test, review, and approve code.
- 5-Agent Workflow: Architect → Coder → Tester → Reviewer → Manager
- Modern Web UI: Interactive interface to test the API directly from browser
- OpenRouter Integration: Access to multiple AI models through unified API
- RESTful API: Clean API endpoints for integration
- Full-Width Code Display: Optimized for viewing generated code
pip install -r requirements.txtCreate a .env file in the project root:
OPENROUTER_API_KEY=sk-or-v1-your-key-here
OPENROUTER_MODEL=openai/gpt-4o-mini
Get your API key from: OpenRouter Settings
Option 1: Using the run script
python run_server.pyOption 2: Using uvicorn directly
uvicorn api.main:app --reload- Web UI: http://127.0.0.1:8000/
- API Docs: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
The system uses a sequential workflow with conditional looping:
- Architect - Designs high-level architecture and system structure
- Coder - Implements the code based on architecture
- Tester - Creates comprehensive test cases
- Reviewer - Reviews code quality and test coverage
- Manager - Makes final decision (approve/rewrite)
If the manager decides to rewrite, the process loops back to the coder for improvements.
POST /api/v1/generate
Request:
{
"task": "Create a Python function to calculate fibonacci numbers"
}Response:
{
"architecture": "...",
"code": "...",
"tests": "...",
"review": "...",
"final_decision": "approve"
}GET /health
GET /status
.
├── api/
│ ├── main.py # FastAPI application with web UI
│ └── routes.py # API routes
├── agents/
│ ├── architect.py # Architect agent
│ ├── coder.py # Coder agent
│ ├── tester.py # Tester agent
│ ├── reviewer.py # Reviewer agent
│ └── manager.py # Manager agent
├── orchestration/
│ ├── graph.py # LangGraph workflow definition
│ └── state.py # State definition
├── config.py # Configuration and env loading
├── requirements.txt # Python dependencies
├── run_server.py # Server startup script
└── .env # Environment variables (create this)
- Sign up at OpenRouter
- Get your API key from Settings
- Add to
.envfile:OPENROUTER_API_KEY=sk-or-v1-your-key-here
You can change the model by updating OPENROUTER_MODEL in your .env file:
openai/gpt-4o-mini(default, cost-effective)openai/gpt-4oopenai/gpt-4-turboanthropic/claude-3.5-sonnetgoogle/gemini-pro
See all models: https://openrouter.ai/models
Make sure you have credits in your OpenRouter account:
- Check credits: https://openrouter.ai/credits
- Add credits if needed
- Visit http://127.0.0.1:8000/
- Enter your task description (e.g., "Create a calculator class")
- Click "Generate Code"
- View results: Architecture, Code, Tests, Review, and Final Decision
Python:
import requests
response = requests.post(
"http://127.0.0.1:8000/api/v1/generate",
json={"task": "Create a Python function to calculate fibonacci numbers"}
)
print(response.json())cURL:
curl -X POST "http://127.0.0.1:8000/api/v1/generate" \
-H "Content-Type: application/json" \
-d '{"task": "Create a Python function to calculate fibonacci numbers"}'Error: "OPENROUTER_API_KEY not found"
- Make sure
.envfile exists in project root - Verify it contains:
OPENROUTER_API_KEY=sk-or-v1-... - Restart the server after updating
.env
Error: "API Key Issue"
- Verify your key is active at https://openrouter.ai/settings/keys
- Check you have credits at https://openrouter.ai/credits
- Make sure you're using
OPENROUTER_API_KEY(notOPENAI_API_KEY)
Error: "API Quota Exceeded"
- Add credits to your OpenRouter account
- Check usage at https://openrouter.ai/activity
- Wait for quota reset or upgrade plan
Error: "Attribute api not found"
- Use correct command:
uvicorn api.main:app --reload - Note: Use
appnotapiat the end
fastapi- Web frameworkuvicorn- ASGI serverlanggraph- Agent orchestrationlangchain-openai- LLM integrationlangchain-core- Core LangChain componentspydantic- Data validationpython-dotenv- Environment variable loading
uvicorn api.main:app --reload --host 0.0.0.0 --port 8000The system uses LangGraph to orchestrate the agent workflow:
- Each agent is a node in the graph
- State is passed between agents
- Conditional edges handle the rewrite loop
- See
orchestration/graph.pyfor workflow definition
This project is open source and available for use.
- OpenRouter Docs: https://openrouter.ai/docs
- OpenRouter Models: https://openrouter.ai/models
- OpenRouter Credits: https://openrouter.ai/credits