Multi-agent code generation system for competitive programming.
Combines a Generator (DeepSeek-chat) + Reviewer (DeepSeek-R1) + ChromaDB memory.
| Baseline | Model | pass@1 | Cost/problem |
|---|---|---|---|
| B0 | deepseek-chat, single agent, no memory | 6% | — |
| B1 | deepseek-chat Generator + deepseek-R1 Reviewer + ChromaDB | 19% | $0.0098 |
Dataset: LiveCodeBench 100 problems (Codeforces-style, stdio)
Problem
↓
[1] Memory Retrieval ChromaDB lookup (no API call)
↓
[2] Generator deepseek-chat, with memory context injected
↓
[3] Reviewer deepseek-R1, checks boundary/complexity/format
↓
[4] Executor local subprocess, stdin/stdout comparison
↓
[5] Memory Update write episode → every 10 problems consolidate → every 50 prune
# 1. Clone and set up env
git clone https://github.com/Hugoean/sagecode.git
cd sagecode
pip install openai python-dotenv chromadb datasets
# 2. Configure API key
cp .env.example .env
# Edit .env and fill in DEEPSEEK_API_KEY
# 3. Test API connectivity
python tests/test_api.py
# 4. Run one problem (smoke test)
python main.py demo
# 5. Run a batch
python main.py batch --n 10
# 6. Run full baseline (100 problems, ~2.5h, ~$1)
python main.py baseline --n 100python main.py demo # 1 problem, verbose
python main.py batch --n 10 # 10 problems, sorted by difficulty
python main.py batch --n 10 --no-sort # 10 problems, original order
python main.py baseline --n 100 # full baseline, saves JSON to data/sagecode/
├── agents/generation/
│ ├── generator.py DeepSeek-chat code generator (with memory injection)
│ └── reviewer.py DeepSeek-R1 code reviewer (truncation-safe)
├── memory/
│ ├── chroma_store.py ChromaDB 3-layer store (episodic/semantic/procedural)
│ ├── retriever.py Memory retrieval → prompt context
│ └── updater.py store / consolidate (every 10) / prune (every 50)
├── executor/
│ └── stdio_exec.py Local subprocess executor for stdio problems
├── data/
│ ├── loader.py LiveCodeBench / BigCodeBench / SWE-Bench loader
│ └── *.json Baseline result files
├── pipeline.py Main orchestration + token cost tracking
├── main.py CLI entry point
└── api_client.py Unified DeepSeek/OpenAI client factory
# .env (copy from .env.example)
DEEPSEEK_API_KEY=sk-your-key-here
DEEPSEEK_BASE_URL=https://api.deepseek.com
GENERATOR_MODEL=deepseek-chat # cheap, fast
REVIEWER_MODEL=deepseek-reasoner # R1, slow but thorough