Dual-Agent Coding System: Worker + Reviewer
A lightweight, extensible Python system for automated code testing and review using two specialized agents:
- Worker Agent: Fast, small local model (llama3.1:8b via Ollama) for quick test generation and minimal code changes.
- Reviewer Agent: Slower, powerful model (devstral:latest via Ollama) for deep code quality review and corrections.
Architecture
krish-agent/
├── cli.py # Command-line interface and orchestrator
├── worker.py # Fast worker agent (test generation, minimal fixes)
├── reviewer.py # Deep reviewer agent (code quality, corrections)
├── tools.py # Shared utilities (file I/O, git, run commands)
├── prompts.py # System prompts for both agents
├── memory.py # Task logging and history
└── README.md # This file
Features
- Fast Worker Agent: Uses small local LLM to quickly generate unit tests and make focused changes
- Deep Review with Devstral: Optional powerful reviewer for code quality and comprehensive feedback
- Test Execution: Built-in pytest integration with automatic test running and reporting
- Memory & History: Persistent task logging with statistics tracking
- Clean Separation: No heavy frameworks—explicit orchestration with clear responsibilities
- Extensible Prompts: Easy to customize system prompts in
prompts.py
Installation
Requirements
- Python 3.8+
- Ollama (https://ollama.ai)
- llama3.1:8b model (~4GB)
- devstral:latest model (~30GB+)
Quick Setup (5 minutes)
See QUICKSTART.md for step-by-step instructions. Short version:
# 1. Install Ollama from https://ollama.ai
# 2. Pull models
ollama pull llama3.1:8b
ollama pull devstral:latest
# 3. Start Ollama server (keep running)
ollama serve
# 4. In another terminal, run the agent
python cli.py add-tests example_test_output.py --review
Usage
Basic Test Generation
# Generate tests for a single file
python cli.py add-tests src/main.py
# Generate tests for a directory
python cli.py add-tests src/
# Generate and request review
python cli.py add-tests src/main.py --review
# Generate, review, and apply corrections automatically
python cli.py add-tests src/main.py --apply-corrections
View Task History
# Show recent tasks
python cli.py history
# Show statistics
python cli.py stats
# Export task memory to file
python cli.py export-memory tasks.json
Configuration
Worker Agent (llama3.1:8b)
The worker is configured to use llama3.1:8b on Ollama:
worker = WorkerAgent(
model_endpoint="http://localhost:11434", # Ollama default
model_name="llama3.1:8b" # Fast 8B model
)
To use a different model, edit cli.py:
self.worker = WorkerAgent(model_name="llama2:13b") # or any available model
Reviewer Agent (devstral:latest)
The reviewer is configured to use devstral:latest on Ollama:
reviewer = ReviewerAgent(
model_endpoint="http://localhost:11434", # Ollama default
model_name="devstral:latest" # Powerful reviewer model
)
To use a different model, edit cli.py:
self.reviewer = ReviewerAgent(model_name="neural-chat:latest") # or any available model
How It Works
Worker Agent (llama3.1:8b)
Calls Ollama's /api/generate endpoint:
# Real implementation in worker.py
response = requests.post(
"http://localhost:11434/api/generate",
json={
"model": "llama3.1:8b",
"prompt": prompt,
"stream": False
},
timeout=120
)
return response.json()['response']
Typical flow:
- Reads target file(s)
- Generates pytest tests (~2-5 seconds)
- Writes to
tests/directory - Runs
pytestand returns results
Reviewer Agent (devstral:latest)
Calls the same Ollama endpoint with Devstral:
# Real implementation in reviewer.py
response = requests.post(
"http://localhost:11434/api/generate",
json={
"model": "devstral:latest",
"prompt": prompt,
"stream": False
},
timeout=180
)
return response.json()['response']
Typical flow:
- Reads worker's test code and results
- Evaluates quality and coverage (~10-30 seconds)
- Proposes improvements or corrections
- Optionally applies and re-runs tests
System Prompts
Both agents use specialized prompts defined in prompts.py:
- WORKER_SYSTEM_PROMPT: Fast, focused test generation
- REVIEWER_SYSTEM_PROMPT: Deep quality review
Customize these to match your coding standards, test frameworks, or specific requirements.
Typical Workflow
-
Worker Phase (seconds)
- Reads target file(s)
- Generates unit tests using small local model
- Writes tests to
tests/directory - Runs
pytestand captures results - Returns structured JSON summary
-
Review Phase (optional, slower)
- Reviewer reads worker's plan and generated tests
- Uses Devstral to evaluate quality and coverage
- Identifies gaps and issues
- Proposes improvements or corrections
-
Correction Phase (optional)
- Apply reviewer's corrections
- Re-run tests to verify improvements
- Log final results to memory
Memory & Logging
All tasks are logged to .agent_memory.json:
{
"timestamp": "2025-01-15T10:30:45.123456",
"task_id": "task_main_1736936445",
"success": true,
"worker": {
"model": "llama3.1:8b",
"plan": "Add comprehensive unit tests...",
"files_modified": ["tests/test_main.py"],
"execution_time": 2.45
},
"reviewer": {
"model": "devstral",
"quality_score": 8,
"issues_found": ["Limited edge case coverage"],
"execution_time": 5.12
}
}
Extending the System
Add a New Command
Edit cli.py in the main() function:
# Add a new subcommand
fix_bugs = subparsers.add_parser("fix-bugs", help="Fix identified bugs")
fix_bugs.add_argument("target", help="File or directory to fix")
# Handle in the command dispatcher
elif args.command == "fix-bugs":
result = orchestrator.fix_bugs(args.target)
Create a New Agent Type
- Create a new file:
agent_type.py - Follow the pattern of
worker.pyorreviewer.py - Import and use in
cli.py
Customize Prompts
Edit prompts.py to define new roles or adjust existing behavior:
CUSTOM_AGENT_PROMPT = """Your specialized role and instructions here..."""
Performance
Speed
- Worker (llama3.1:8b): 2-5 seconds per task on GPU
- Reviewer (devstral:latest): 10-30 seconds per review on GPU
Hardware Requirements
- Minimum: 8GB GPU VRAM (llama3.1:8b only)
- Recommended: 16GB+ GPU VRAM for both models
- CPU-only: 10-50x slower, not recommended
Optimization Tips
- Load models sequentially (not simultaneously) to save VRAM
- Use
--reviewonly when needed (slower) - Use
--apply-correctionsfor automatic improvements - Run on GPU for best performance
Example Scenario
# Generate tests for a new utility module
python cli.py add-tests src/utils.py
# Output:
# [STEP 1] Worker agent: Generating tests...
# [✓] Worker completed in 2.34s
# - Plan: Add comprehensive unit tests for utility functions
# - Files to modify: ['tests/test_utils.py']
# - Test result: PASS
# Now review and improve
python cli.py add-tests src/utils.py --apply-corrections
# Output:
# [STEP 1] Worker agent: Generating tests...
# [✓] Worker completed in 2.34s
# [STEP 2] Reviewer agent: Reviewing generated tests...
# [✓] Reviewer completed in 5.67s
# - Issues found: 2
# - Quality score: 8/10
# - Corrections: Added edge case tests for empty inputs
# [STEP 3] Applying reviewer's corrections...
# [✓] Tests after corrections: PASS
Troubleshooting
"Cannot connect to Ollama at http://localhost:11434"
# Make sure Ollama is running
ollama serve
# Verify connectivity
curl http://localhost:11434/api/tags
"Model not found: llama3.1:8b"
ollama pull llama3.1:8b
"Model not found: devstral:latest"
ollama pull devstral:latest
Tests failed after generation
This is normal! Review feedback improves tests:
python cli.py add-tests src/main.py --review
Slow performance
Check GPU memory:
# CUDA (Linux)
nvidia-smi
# Metal (macOS)
ollama list # Shows memory per model
If only 8GB VRAM: don't use --review, just generate tests.
License
MIT (or your preferred license)
Contributing
Pull requests welcome! Areas for improvement:
- Real LLM API integrations
- Parallel test execution
- Enhanced diff generation
- Web UI for memory browsing
- Integration with GitHub/GitLab
- Support for other test frameworks (unittest, pytest plugins)
Metadata
Release files for krish-agent 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| krish_agent-3.0.0.tar.gz | 48.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| krish_agent-3.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 100.7 kB
Release files / krish_agent-3.0.0.tar.gz
| Download URL | krish_agent-3.0.0.tar.gz |
|---|---|
| Size | 48.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
211395bab02fa4e11cb8c523979819151e2d1868d2cc80be1fa3108bc7a624eb
|
|
BLAKE2b-256 checksum How to use checksums |
fc2281c5945d59b024e03059c599da3c62267bf2c98326fbe21f43be5706da1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / krish_agent-3.0.0-py3-none-any.whl
| Download URL | krish_agent-3.0.0-py3-none-any.whl |
|---|---|
| Size | 52.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cfccb5ab22852773b5be96d3640f77568ce9bc85f1024196de59006f30dc1b0a
|
|
BLAKE2b-256 checksum How to use checksums |
cb3c2d055b2e754ef3b57de2fb944cb1d8bcbb4f1df2fbe11bcc10941cd633f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Security for krish-agent 3.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.