Skip to main content

An autonomous, multi-turn AI debugging agent built from scratch using AST surgery.

Project description

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.

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

pyfix_agent-2.0.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyfix_agent-2.0.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file pyfix_agent-2.0.0.tar.gz.

File metadata

  • Download URL: pyfix_agent-2.0.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for pyfix_agent-2.0.0.tar.gz
Algorithm Hash digest
SHA256 14c138b350c4865681de17a2f38c0c46bf240a18d98eb056922d716fd31b0431
MD5 545cecb063dd90f089584b5c82378a5d
BLAKE2b-256 450c33f728c3fb91e8f03557d58ec4336a4d115e4ac6c8055310d0d966934708

See more details on using hashes here.

File details

Details for the file pyfix_agent-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyfix_agent-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for pyfix_agent-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf65cf0fb8ded5dbb2008a15d511c5cc746e72944413c9961440b7697dc01216
MD5 53403952eb8e44745353f5db321d8566
BLAKE2b-256 5383d4f98d2dd78bc05814fe945c0b41ba5c6e181e7a1accb9bb75196efb084a

See more details on using hashes here.

Supported by

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