๐ง Agentic AI for CodingMarch 7, 2026โ
Tests passing
Agentic AI Debugger
A CLI tool that integrates with IDEs to autonomously debug Python code. It uses agentic AI to analyze stack traces, error messages, and code context to suggest and apply fixes. This tool streamlines debugging by providing intelligent recommendations and fixes in real time.
What It Does
- Analyze Python code and error messages using OpenAI's API.
- Suggest fixes and provide explanations for errors.
- Automatically apply fixes to code files.
- Process individual files or entire directories of Python scripts.
Installation
Install the required dependencies:
pip install openai richUsage
Run the tool from the command line:
python agentic_ai_debugger.py --file <path_to_file> --error <error_message> --api-key <your_openai_api_key>Options
--file: Path to a Python file to debug.--directory: Path to a directory containing Python files to debug.--error: Error message or stack trace to analyze (required).--auto-apply: Automatically apply suggested fixes.--api-key: Your OpenAI API key (required).
Example
python agentic_ai_debugger.py --file example.py --error "ZeroDivisionError" --api-key YOUR_API_KEY --auto-applySource Code
import argparse
import os
import openai
from rich.console import Console
from rich.table import Table
console = Console()
class AgenticAIDebugger:
def __init__(self, api_key, auto_apply=False):
self.api_key = api_key
self.auto_apply = auto_apply
openai.api_key = self.api_key
def analyze_code(self, code, error_message):
"""Analyze the code and error message using OpenAI API."""
prompt = f"""
You are an expert Python developer. Analyze the following code and error message. Suggest fixes and explain them clearly.
Code:
{code}
Error Message:
{error_message}
"""
try:
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500
)
return response["choices"][0]["text"].strip()
except Exception as e:
console.print(f"[red]Error communicating with OpenAI API: {e}")
return None
def apply_fix(self, file_path, fix):
"""Apply the suggested fix to the file."""
try:
with open(file_path, "r") as file:
original_code = file.read()
fixed_code = original_code + "\n\n# Suggested Fix:\n" + fix
with open(file_path, "w") as file:
file.write(fixed_code)
console.print(f"[green]Fix applied to {file_path}")
except Exception as e:
console.print(f"[red]Error applying fix: {e}")
def process_file(self, file_path, error_message):
"""Process a single Python file."""
if not os.path.isfile(file_path):
console.print(f"[red]File not found: {file_path}")
return
try:
with open(file_path, "r") as file:
code = file.read()
suggestions = self.analyze_code(code, error_message)
if suggestions:
console.print("\n[bold]Suggestions:[/bold]")
console.print(suggestions)
if self.auto_apply:
self.apply_fix(file_path, suggestions)
except Exception as e:
console.print(f"[red]Error processing file: {e}")
def process_directory(self, directory, error_message):
"""Process all Python files in a directory."""
if not os.path.isdir(directory):
console.print(f"[red]Directory not found: {directory}")
return
for root, _, files in os.walk(directory):
for file in files:
if file.endswith(".py"):
file_path = os.path.join(root, file)
self.process_file(file_path, error_message)
def main():
parser = argparse.ArgumentParser(description="Agentic AI Debugger: Autonomously debug Python code using AI.")
parser.add_argument("--file", type=str, help="Path to a Python file to debug.")
parser.add_argument("--directory", type=str, help="Path to a directory containing Python files to debug.")
parser.add_argument("--error", type=str, required=True, help="Error message or stack trace to analyze.")
parser.add_argument("--auto-apply", action="store_true", help="Automatically apply suggested fixes.")
parser.add_argument("--api-key", type=str, required=True, help="OpenAI API key.")
args = parser.parse_args()
debugger = AgenticAIDebugger(api_key=args.api_key, auto_apply=args.auto_apply)
if args.file:
debugger.process_file(args.file, args.error)
elif args.directory:
debugger.process_directory(args.directory, args.error)
else:
console.print("[red]You must specify either --file or --directory.")
if __name__ == "__main__":
main()
Community
Downloads
ยทยทยท
Rate this tool
No ratings yet โ be the first!
Details
- Tool Name
- agentic_ai_debugger
- Category
- Agentic AI for Coding
- Generated
- March 7, 2026
- Tests
- Passing โ
- Fix Loops
- 5
Quick Install
Clone just this tool:
git clone --depth 1 --filter=blob:none --sparse \ https://github.com/ptulin/autoaiforge.git cd autoaiforge git sparse-checkout set generated_tools/2026-03-07/agentic_ai_debugger cd generated_tools/2026-03-07/agentic_ai_debugger pip install -r requirements.txt 2>/dev/null || true python agentic_ai_debugger.py