Skip to content

Repository files navigation

SAGECODE

License: MIT

Multi-agent code generation system for competitive programming.
Combines a Generator (DeepSeek-chat) + Reviewer (DeepSeek-R1) + ChromaDB memory.

Results

BaselineModelpass@1Cost/problem
B0deepseek-chat, single agent, no memory6%
B1deepseek-chat Generator + deepseek-R1 Reviewer + ChromaDB19%$0.0098

Dataset: LiveCodeBench 100 problems (Codeforces-style, stdio)

Pipeline

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

Quick Start

# 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 100

Commands

python 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/

Project Structure

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

Environment Variables

# .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

About

Self-Improving Agent for Code Generation

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages