Skip to main content

AI-powered runtime debugging agent for Python web applications

Project description

Python Debug Agent

An AI-powered runtime debugging agent that embeds directly into your Python web application. Add one dependency, configure an LLM key, and chat with your live app at /agent to inspect memory, threads, routes, HTTP requests, GC stats, and more.

Quick Start

1. Install

pip install debug-agent[fastapi]

2. Integrate (FastAPI)

from fastapi import FastAPI
from debug_agent.middleware import create_fastapi_router

app = FastAPI()

# One line to integrate
app.include_router(create_fastapi_router())

3. Configure LLM

export LLM_API_KEY=your-key
export LLM_BASE_URL=https://api.openai.com/v1  # optional
export LLM_MODEL=gpt-4o                         # optional

4. Run and open

http://localhost:8000/agent

Framework Integrations

FastAPI / Starlette

from debug_agent.middleware import create_fastapi_router
app.include_router(create_fastapi_router())

Flask

from flask import Flask
from debug_agent.middleware import create_flask_blueprint
app = Flask(__name__)
app.register_blueprint(create_flask_blueprint())

Any ASGI App (Starlette Mount)

from starlette.routing import Mount
from debug_agent.middleware import create_starlette_app
routes = [Mount("/agent", app=create_starlette_app())]

Built-in Tools (18+)

Tool Description
get_gc_stats GC collection counts per generation
get_memory_summary RSS, object counts, top types
trigger_gc Force GC and show before/after
get_thread_summary Thread count, names, daemon status
get_thread_dump Stack traces for all threads
get_runtime_info Python version, platform, PID
get_memory_allocations tracemalloc top allocations
get_routes List all web routes/endpoints
get_middleware List registered middleware
get_installed_packages Installed pip packages
get_environment_variables Environment variables (masked secrets)
get_recent_requests HTTP request ring buffer
get_slow_requests Slowest requests sorted by duration
get_error_requests Error requests (4xx/5xx)
get_request_stats P50/P95/P99 latency, error rate
get_process_info PID, CPU time, container detection
get_system_info OS, CPU cores, load average
get_disk_usage Disk usage for working directory

Custom Tools

from debug_agent import debug_tool, ToolParam

@debug_tool("check_db_pool", "Check database connection pool stats")
def check_db_pool() -> dict:
    return {"active": 5, "idle": 10, "max": 20}

That's it. The tool is auto-discovered and made available to the LLM.

Configuration

Env Var Default Description
DEBUG_AGENT_ENABLED true Enable/disable
DEBUG_AGENT_BASE_PATH /agent URL path
LLM_BASE_URL https://api.openai.com/v1 LLM endpoint
LLM_API_KEY (required) API key
LLM_MODEL gpt-4o Model name
LLM_TEMPERATURE 0.3 Sampling temp
LLM_MAX_TOOL_ROUNDS 10 Max tool rounds

Run the Demo

pip install -e ".[dev]"
export LLM_API_KEY=your-key
python demo/app.py
# Open http://localhost:8000/agent

License

MIT

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

debug_agent_py-0.2.1.tar.gz (30.0 kB view details)

Uploaded Source

Built Distribution

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

debug_agent_py-0.2.1-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

Details for the file debug_agent_py-0.2.1.tar.gz.

File metadata

  • Download URL: debug_agent_py-0.2.1.tar.gz
  • Upload date:
  • Size: 30.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for debug_agent_py-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b6c5aee4ecf5e05b3001eeae9a58eb3021edbb2dd50beb002370af4f176e2429
MD5 e7ad8bbb01f79389bd4fe5e485f82f5c
BLAKE2b-256 934a9d49f2aa2c6a9eb962494cf94b9e98ed3e745fd55d510880b79ae0a47b5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for debug_agent_py-0.2.1.tar.gz:

Publisher: pypi-publish.yml on topcheer/python-debug-agent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file debug_agent_py-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: debug_agent_py-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 35.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for debug_agent_py-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db2345747fc4ad7a9d0fbc3df987ec7e4c0e6ab43b021e2c20c181f099e4cf0f
MD5 fbcf710e637d8c6a5cf260db30499d90
BLAKE2b-256 4b78cb92c0c5b92dacdf7a2cf5fbc43fdf1871fa9205835f35e58b7aa07b490a

See more details on using hashes here.

Provenance

The following attestation bundles were made for debug_agent_py-0.2.1-py3-none-any.whl:

Publisher: pypi-publish.yml on topcheer/python-debug-agent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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