Skip to main content

An AI-powered agent that helps fix and heal buggy code

Project description

Healing Agent 🩺

Healer Agent is an intelligent code assistant that catches with detailed context and fixes errors in your Python code. It leverages the power of AI to provide smart suggestions and corrections, helping you write more robust and "self-healing" code.

⚠️ Not intended for production use. Be extra careful with the optional AUTO_FIX function, as although it makes backups of your code, it actually changes and runs your code. ⚠️

Goal: first actually usable autonomous coding agent in production

Features ✨

  • 🚨 Automatic error detection and handling of diverse exception types
  • 💡 Smart error analysis and solution suggestions (auto-generated fixing hints and code)
  • 🔍 Comprehensive error analysis including exception details, stack traces, local and globalvariables and root cause identification
  • 🧠 Advanced AI-powered code healing using LLMs of different providers
  • 🔧 Zero-config integration with Python projects (just import and decorate)
  • 💾 Robust error tracking and debugging:
    • Exception context saved to JSON (code, error details, function info and args)
    • Automatic code backups before fixes
    • Detailed analysis results and fix history
    • Quick test of fixes
  • 🤖 (Optionally) Fully automated operation with minimal human intervention

How it works 🧠

graph TD
    A[Import healing_agent] --> B[Configuration: AI access etc.]
    B --> C[Decorate functions with healing_agent]
    C --> D[Run Code / Execute Functions]
    D -->|No problem| L[Success]
    D -->|Exception?| F[Get and Save Detailed Context]
    F --> G[Auto-generate Fixing Hints and Code with AI]
    G --> H[Test Generated Code]
    H --> I[Create backup]
    I --> J[Apply Code Fixes]
    J --> D

Installation 💻

To install Healing Agent, follow these steps:

PIP package from GitHub:

pip install git+https://github.com/matebenyovszky/healing-agent

OR from source:

  1. Clone the repository:

    git clone https://github.com/matebenyovszky/healing-agent.git
    
  2. Navigate to the project directory:

    cd healing-agent
    
  3. Install:

    pip install -e .
    

    OR run overall test to install and test functionality:

    python scripts/overall_test.py
    

Usage 🔧

To use Healing Agent in your project, follow these steps:

  1. Import the healing_agent decorator in your Python file:

    import healing_agent
    
  2. Decorate the function you want to monitor with @healing_agent:

    @healing_agent
    def your_function():
        # Your code here
    

    You can also pass parameters to the decorator to change the behavior set in the config file:

    @healing_agent(AUTO_FIX=False)
    def your_function():
        # Your code here
    
  3. Run your Python script as usual. Healing Agent will automatically detect, save context and attempt to fix any errors that occur within the decorated function.

Context (and code file backup in case of auto-fix) is saved to a JSON/Python file in the same directory as your script with actual timestamp in the filename.

Configuration ⚙️

Healing Agent provides extensive configuration options through the healing_agent_config.py file, which defines essential settings such as the AI provider and API credentials. The configuration system follows these principles:

  1. Automatic Configuration Loading: On startup, Healing Agent attempts to load settings from healing_agent_config.py
  2. Fallback Mechanism: If the configuration file is not found, the system falls back to pre-defined default settings
  3. Auto-Configuration: When no configuration file exists, Healing Agent automatically creates one in the default user directory

Supported AI Providers

Healing Agent integrates with multiple AI providers - list could be extended:

  • OpenAI
  • Azure OpenAI
  • LiteLLM
  • Anthropic
  • Ollama

Note: While multiple providers are supported, Azure OpenAI has been extensively tested. Support for other providers is under active development (feedback welcome).

Testing 🧪

To test Healing Agent, you can use the scripts/test_file_generator.py script to generate test files in the tests directory. overall_test.py will run all tests and provide a report on the functionality of Healing Agent.

Use Cases 💡

  • Development: Use Healing Agent during development to catch and fix errors early, and let AI generate fixes for your code. This is what you would do anyways, but now it's automated. 😁
  • Educational Tool: Use Healing Agent as a learning tool to understand AI coding capabilities and limitations.

Cooking open source 🍳

Healing Agent is distributed under the MIT License. See LICENSE for more information. Feedback and contributions are welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

healing_agent-0.2.4.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

healing_agent-0.2.4-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file healing_agent-0.2.4.tar.gz.

File metadata

  • Download URL: healing_agent-0.2.4.tar.gz
  • Upload date:
  • Size: 30.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for healing_agent-0.2.4.tar.gz
Algorithm Hash digest
SHA256 0e69af51ec8aeea2dd096869213c3a4e6d3dadc78e9411a8baaa049b2c610947
MD5 16ba6046ca778b48c497e0688cb2a55d
BLAKE2b-256 e31700a98f752c5667bdd2539e30521d45694e30312208a541ad38bcae2d6e6d

See more details on using hashes here.

File details

Details for the file healing_agent-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for healing_agent-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9186160671eb1b8ce463e077370e9b1259fe32b71a32e6f4ed3a3553a121a8ca
MD5 766e546516be095a016442f1eed3ee02
BLAKE2b-256 ebd8af6baab17d45490826b265e2dec02dd2bb82570bf233064e32f00e221f01

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page