A production-ready multi-agent AI system that reads your codebase, diagnoses bugs, and fixes them autonomously using an iterative agentic loop powered by Gemini Flash.
- Multi-agent roles: Planner, Reviewer, Executor, Verifier
- Retry with exponential backoff: handles 429/rate limits gracefully
- Proper Python logging: structured, timestamped, verbose mode
- Dry-run mode: preview proposed edits before applying
- Session history: every run saved as JSON for audit/replay
- Git checkpoints: optional commit after each iteration
- Error context input: seed agent with stack traces/logs
- API health check: validate key/model/quota from CLI
- Test suite: unit tests for all core modules
AIAgents/
├── agentic_fix/
│ ├── __init__.py
│ ├── agent.py # Main agentic control loop
│ ├── api_check.py # API quota/access health check
│ ├── config.py # Env + runtime settings
│ ├── context.py # Repo scanning + context building
│ ├── gemini_client.py # Gemini API with retry + error handling
│ ├── git_utils.py # Git checkpoint utilities
│ ├── logger.py # Structured Python logging setup
│ ├── prompts.py # Role-specific prompts
│ ├── schema.py # Data models for plans/edits/results
│ ├── session.py # Run session history (JSON logs)
│ ├── verify.py # Safe verification command runner
│ └── workspace.py # Apply/preview edits
├── tests/ # Unit tests for agent modules
│ ├── test_context.py
│ ├── test_schema.py
│ ├── test_session.py
│ ├── test_verify.py
│ └── test_workspace.py
├── sample_buggy_repo/ # Simple demo target
├── sample_complex_repo/ # Multi-file buggy demo target
├── main.py # CLI entrypoint
├── requirements.txt
└── .gitignore
- Create and activate a virtual environment.
- Install dependencies:
pip install -r requirements.txt- Add environment variables in
.env:
GEMINI_API_KEY=your_api_key_here
GEMINI_MODEL=gemini-2.0-flash
MAX_AGENT_ITERATIONS=5
MAX_FILES_IN_CONTEXT=20
MAX_CHARS_PER_FILE=4000
ENABLE_REVIEWER=truepython main.py --check-apiPerforms a tiny live call to validate your key, model, and quota.
python main.py "Fix failing tests" --repo ./sample_complex_repo --verify "python -m pytest -q" --verbosepython main.py "Fix billing module bugs" --repo "C:/path/to/repo" --verify "python -m pytest -q"| Flag | Description |
|---|---|
--repo PATH |
Target repo folder (default: .) |
--verify CMD |
Verification command (e.g. pytest -q) |
--verbose |
Detailed step-by-step logging |
--max-iterations N |
Override max loop iterations |
--no-reviewer |
Disable reviewer agent for this run |
--error-file PATH |
Seed first iteration with error logs |
--check-api |
Validate API key/model/quota and exit |
--dry-run |
Preview edits without applying |
--git-checkpoint |
Git commit after each iteration |
python main.py "Fix checkout pricing, shipping threshold, and tax bugs" \
--repo ./sample_complex_repo \
--verify "python -m pytest -q" \
--verbose \
--error-file ./sample_complex_repo/error_logs/pytest_failure.txtpython -m pytest tests/ -v- Scans repo files (extension filtering + ignored dirs).
- Produces a bounded snapshot of file contents.
- Receives task + repo snapshot + previous failure context.
- Returns strict JSON with edits, verify command, done flag.
- Reviews planner output for safety/minimality/quality.
- Can approve, return feedback, or provide revised plan.
- Applies edits (
create/replace). - Path-escape protection + permission error handling.
- Runs safe allowlisted commands with timeout.
- Captures stdout/stderr.
- Failed verification output fed back to next planner iteration.
- Optional
--error-fileseeds first iteration context. - Loop stops on: success, planner done, or max iterations.
- Every run writes a JSON session log to
.agentic_fix_logs/. - Contains all iterations, plans, reviews, edits, and verify results.
- With
--git-checkpoint, commits after each successful edit iteration. - Easy rollback to any iteration.