Skip to main content

PyFix Agent: Autonomous ReAct Debugging Loop

An autonomous, multi-turn AI debugging agent built entirely from scratch in Python.

Unlike standard wrappers that simply ask an LLM to "fix this code," PyFix Agent implements a custom ReAct (Reasoning and Acting) state machine and utilizes Abstract Syntax Tree (AST) manipulation to surgically patch Python files in real-time. It evaluates its own fixes by executing the code inside a subprocess, iterating dynamically until the script passes or it reaches the maximum iteration limit.


Installation

You can install PyFix Agent directly from PyPI:

pip install pyfix-agent

This will automatically register the pyfix-agent executable in your terminal path.

Install from Source

If you want to run or modify the source code locally:

# Clone the repository
git clone https://github.com/LightY-01/pyfix-agent.git
cd pyfix-agent

# Install package in editable mode
pip install -e .

Configuration

Export your Hugging Face Hub token to your environment variables to ensure secure API access:

Bash (Linux/macOS):

export HF_TOKEN="your_huggingface_token_here"

PowerShell (Windows):

$env:HF_TOKEN="your_huggingface_token_here"

CLI Usage Guide

Point the agent at any broken Python script. Use the --verbose flag to watch the ReAct state machine's internal thought process.

# Run the agent CLI
pyfix-agent --script my_broken_code.py --verbose --max_iter 5

# Run using a specific Hugging Face model
pyfix-agent --script my_broken_code.py --model "mistralai/Mixtral-8x7B-Instruct-v0.1" --verbose

CLI Command Options

Argument Type Default Description
--script str Required Path to the broken Python script to debug
--max_iter int 5 Maximum number of debugging iterations
--verbose flag False Enable logging of reasoning, tracebacks, actions, and observations in ReAct format
--model str Qwen/Qwen2.5-72B-Instruct:cheapest Model endpoint ID on Hugging Face Serverless API

How It Works

  1. Execution Engine: Runs the target script via Python subprocesses, capturing standard outputs, standard errors, and stack traces with safety timeout thresholds.
  2. Context Memory: Maintains a chronological conversation history array, allowing the LLM to learn from its previously failed patching attempts without losing the original code context.
  3. AST Surgery: Parses the LLM's response and uses Python's native ast.NodeTransformer to swap out broken function nodes with the corrected logic, leaving the rest of the file entirely untouched. It also automatically extracts and moves any newly declared import statements to the top level of the script.

Metadata

Release files for pyfix-agent 2.0.1

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

Source distribution (sdist)

Source distribution for pyfix-agent 2.0.1
File Size Uploaded Provenance
pyfix_agent-2.0.1.tar.gz 6.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyfix-agent 2.0.1
File Interpreter ABI Platform
pyfix_agent-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.5 kB

Release files / pyfix_agent-2.0.1.tar.gz

Download URL pyfix_agent-2.0.1.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
46bacc7ae476a4818cba152a2843a07d09806d595bcc8453d88991642ef8f38d
BLAKE2b-256 checksum
How to use checksums
b830936735b144f62e0cb14aeb1c51d0e29cec923589ea3abcb389315f409a91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Release files / pyfix_agent-2.0.1-py3-none-any.whl

Download URL pyfix_agent-2.0.1-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0a76116eb21c454e7db39535756e26accb7d79e87801ba1530b440b5891531db
BLAKE2b-256 checksum
How to use checksums
0ca26ea5dae5af6e07ead260261f8a13c9a9f6778359a961bce630664c141430
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Security for pyfix-agent 2.0.1

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.

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