Skip to main content

🤖 AI Automated Code Repair Agent

AI Code Repair Agent Banner

AI Automated Code Repair Agent is a professional, autonomous CLI tool that executes Python scripts, detects crashes, and uses an AI-driven workflow to analyze, repair, and securely verify fixes before recommending them. It packages everything you need—from intelligent error parsing to isolated Docker-based verification—so you can point it at a script and get reliable, reproducible results.

PyPI Package: ai-code-repair-agent


✨ Core Features

  • 🤖 Autonomous End-to-End Workflow: Run agent <script.py> and let the tool handle execution, crash detection, analysis, patching, and reporting.
  • 🧠 AI-Powered Code Generation (Gemini): Sends rich error context to Google's Gemini LLM to propose logical, high-quality fixes—not just syntax band-aids.
  • 🛡️ Secure Sandbox Verification: Builds an isolated Docker container on the fly, runs tests, and accepts only verified solutions.
  • 🔮 Auto-Dependency & Environment Discovery: Inspects the target script to infer third‑party dependencies and auto‑generate requirements.txt and a Dockerfile.
  • 🎯 Environment-Aware Diagnostics: Distinguishes code bugs from environment issues (e.g., ModuleNotFoundError) and recommends precise pip install commands when appropriate.
  • 📦 Professional CLI Experience: Distributed via PyPI with a user-friendly agent configure command for easy setup and a built-in Docker prerequisite check.

🧭 Decision Workflow

First-Time User Setup

graph TD
    A[New User] --> B[pip install ai-code-repair-agent];
    B --> C[agent configure];
    C --> D[Enters API Key];
    D --> E[✅ Agent is ready to use];

Main Repair Workflow

graph TD
    A[User executes `agent <script_path>`] --> B{Docker Running?};
    B -- No --> C[❌ End: Advise user to start Docker];
    B -- Yes --> D[ProcessRunner executes script];
    D --> E{Crash Detected?};
    E -- No --> F[✅ End: Success];
    E -- Yes --> G[ErrorParser analyzes traceback];
    G --> H{Error Type?};
    H -- ModuleNotFoundError --> I[👩‍🏫 Reporter advises `pip install` & exits];
    H -- Other Error --> J[ContextManager retrieves faulty function];
    J --> K[AICore sends context to Gemini LLM];
    K --> L[Receives proposed code fix];
    L --> M[🛡️ SandboxVerifier begins test];
    M --> N{Test Passed?};
    N -- Yes --> O[🎉 Reporter shows success & diff];
    N -- No --> P[❌ Reporter shows failure];

    style C fill:#e63946,stroke:#333,stroke-width:2px
    style I fill:#f9f,stroke:#333,stroke-width:2px

🏗️ System Architecture

This project is modular for clarity, testability, and extensibility.

  • agent/cli.py — Orchestrator & CLI (argparse), handles configure command, Docker prerequisite check, and full workflow.
  • agent/process_runner.py — Executes target scripts (subprocess), captures stdout/stderr, determines crash state.
  • agent/error_parser.py — Parses Python tracebacks into structured data via regex.
  • agent/context_manager.py — Extracts faulty function context using ast for high-signal AI prompts.
  • agent/ai_core.py — Prompts and calls Google Gemini, securely loading API key from a .env in the user's home directory.
  • agent/sandbox_verifier.py — Uses Docker SDK to build sandbox environments, apply patches, and verify.
  • agent/reporter.py — Provides human-friendly output with colorama and clean diffs.

🛠️ Tech Stack

Category Technology
Core Language Python 3.9+
Execution subprocess, tempfile, pathlib
Analysis ast, inspect, re, traceback, difflib, stack-data
AI Google Gemini via google-generativeai
Sandboxing Docker & Docker SDK for Python; auto-generated Dockerfile and requirements.txt
CLI & UX argparse, colorama, interactive agent configure command
Packaging PyPI with pyproject.toml, versioned CLI entry point

🚀 Getting Started

Prerequisites

Installation & Configuration

pip install ai-code-repair-agent
agent configure

🧪 Usage

agent path/to/your/buggy_script.py
agent path/to/script_with_args.py --input data.csv --output results.json

🧩 Design Principles

  • Safety First: AI-generated code is never trusted without sandbox verification.
  • Minimal Friction: One-time setup, then zero-config runs.
  • Clear Boundaries: Distinguishes environment issues from logic bugs.
  • Modular & Extensible: Clean interfaces for easy customization and future enhancements.
  • Reproducible: Dockerized tests ensure consistent behavior across environments.

🔍 Example Module Layout

ai_code_repair_agent/
└─ agent/
   ├─ __init__.py
   ├─ cli.py              # CLI orchestrator, configure command, Docker check
   ├─ process_runner.py   # Run target script, capture outputs
   ├─ error_parser.py     # Parse tracebacks
   ├─ context_manager.py  # Extract faulty function via AST
   ├─ ai_core.py          # Prompt & call Gemini, load API key
   ├─ sandbox_verifier.py # Build Docker envs & verify
   └─ reporter.py         # Colorized results & diffs

🧱 Security & Privacy

  • No source exfiltration: Only error-specific context is sent to the AI.
  • Ephemeral sandboxes: Containers are temporary and removed post-execution.
  • Secrets management: API keys securely stored in a .env file in your home directory.

📜 License

Distributed under the MIT License. See LICENSE for details.


👤 Author

Darshan S

Release files for ai-code-repair-agent 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ai-code-repair-agent 1.1.2
File Size Uploaded
ai_code_repair_agent-1.1.2.tar.gz 14.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ai-code-repair-agent 1.1.2
File Interpreter ABI Platform
ai_code_repair_agent-1.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 29.5 kB

Release files / ai_code_repair_agent-1.1.2.tar.gz

Download URL ai_code_repair_agent-1.1.2.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7d2cfb1dc049d5ecd545da450882fd527d94ac9b19d620eff21060624b5ae548
BLAKE2b-256 checksum
How to use checksums
e0adafd81df474a4e0f69ccb3aec95fdf0c992914e5af27d9627f11e23859a6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / ai_code_repair_agent-1.1.2-py3-none-any.whl

Download URL ai_code_repair_agent-1.1.2-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83e9c8c1e9c632d4dc995d32d882c6049f6156932cc7a610366e9e55028de9a9
BLAKE2b-256 checksum
How to use checksums
a6f0c08f454506b33bd3b285c4c3270d191cea0127fc9bf6e9fb65d41ab104a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page