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, GC, modules, database connections, routes, HTTP requests, and more.

Quick Start

1. Install

pip install debug-agent-py

2. Integrate (Flask)

from flask import Flask
from debug_agent import setup_debug_agent

app = Flask(__name__)

# One line to integrate
setup_debug_agent(app)

3. Configure LLM

export LLM_API_KEY=your-key
export LLM_BASE_URL=https://open.bigmodel.cn/api/coding/paas/v4  # default
export LLM_MODEL=glm-5.2                                          # default

Supports any OpenAI-compatible endpoint.

4. Run and open

http://localhost:8000/agent

Features

  • Streaming AI responses with real-time tool call badges (pending / success / error)
  • Context compression — automatically summarizes old conversation when token limit is approached
  • Dark-themed chat UI with full markdown rendering (tables, code blocks, lists)
  • Max tool rounds (25) with forced final summary when limit is reached
  • 34 diagnostic tools across 10 inspectors
  • Works with Flask, FastAPI, and Django

Inspectors & Tools (34)

Memory Inspector

Tool Description
get_tracemalloc_stats Python tracemalloc top allocations by file/line
get_object_counts Count objects by type via gc
get_gc_stats gc.get_stats() generation details
get_ref_cycles Count reference cycles detected by gc
trigger_gc Force garbage collection

Threads Inspector

Tool Description
get_thread_info List all threads with name, daemon, alive status
get_thread_count Active thread count
get_thread_summary Thread state distribution

Database Inspector

Tool Description
get_sqlalchemy_engines Find SQLAlchemy engines and pool status
get_db_connections Inspect database connection pools

Modules Inspector

Tool Description
get_loaded_modules List loaded Python modules (sys.modules) with versions
get_module_count Total loaded module count
get_installed_packages List installed packages from pip

Async Tasks Inspector

Tool Description
get_async_tasks List pending asyncio tasks
get_event_loop_info Event loop details: type, running state

Runtime Inspector

Tool Description
get_memory_info Process memory info (RSS, VMS, shared)
get_cpu_usage CPU usage percentage
get_python_info Python version, implementation, executable path

System Inspector

Tool Description
get_system_info Hostname, platform, CPU cores, disk
get_environment_variables Environment variables (masked secrets)
get_disk_usage Disk usage for working directory

Framework Inspector

Tool Description
get_routes List all registered web routes/endpoints
get_middleware List registered middleware

HTTP Tracker Inspector

Tool Description
get_recent_requests Recent HTTP requests ring buffer
get_slow_requests Slowest requests by duration
get_error_requests Error requests (4xx/5xx)
get_request_stats P50/P95/P99 latency, error rate

Custom Tools

from debug_agent import debug_tool

@debug_tool('check_redis', 'Check Redis connection')
def check_redis():
    return {'connected': True}

Configuration

Env Var Default Description
LLM_BASE_URL https://open.bigmodel.cn/api/coding/paas/v4 LLM endpoint
LLM_API_KEY (required) API key
LLM_MODEL glm-5.2 Model name
LLM_MAX_TOOL_ROUNDS 25 Max tool-calling rounds
LLM_CONTEXT_WINDOW_TOKENS 100000 Context window size

Run the Demo

export LLM_API_KEY=your-key
cd demo && python app.py
# Open http://localhost:8000/agent

PyPI

debug-agent-py

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.2.tar.gz (30.6 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.2-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: debug_agent_py-0.2.2.tar.gz
  • Upload date:
  • Size: 30.6 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.2.tar.gz
Algorithm Hash digest
SHA256 b18ba9c99e721a9e5eaeaa4e1aa77c05d50707c44cef03f90fcb969a7203bd37
MD5 22043008b74761b1711f206460f70d22
BLAKE2b-256 f98ea8d836b2fe4ebd8a0876a6bbeda0b0a56986166b824c496e8705bde34bd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for debug_agent_py-0.2.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: debug_agent_py-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 35.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0ffe20e73ae9f64a5ac556015122fe0f2a2ca922495d1985b7c25b8e11e97b1b
MD5 80ce8e8d7270c7fc00f499bad896ca85
BLAKE2b-256 9709477b67a5797938e2bb2bce095d59d195675941f485fcdaf40f6502807955

See more details on using hashes here.

Provenance

The following attestation bundles were made for debug_agent_py-0.2.2-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