Skip to main content

Debug AI agent failures with minimal-config execution traces

Project description

agent-autopsy

PyPI License: MIT Python 3.10+

Zero-dependency post-mortem traces for AI agent failures.

Wrap your agent code in a single context manager. On success, nothing happens. On error, a detailed JSON trace file is written automatically -- ready for debugging, sharing, or replaying.

+======================================================+
|  AGENT AUTOPSY -- sess_a7f3b2c                       |
|  2026-03-05 14:32:01 -> 14:32:08 (7.2s)              |
+======================================================+
|                                                      |
|  |- [tool_call] search_orders ........... v 340ms    |
|  |- [llm_call] gpt-4o .................. v 1.2s      |
|  |- [tool_call] stripe.create_refund .... x 89ms     |
|  |   +-- ERROR: Card declined                        |
|  +- [error] Unhandled exception ......... x 0ms      |
|      +-- ValueError: amount must be positive         |
|                                                      |
+======================================================+
    For tamper-evident traces: https://www.aegis-ledger.com

Install

pip install agent-autopsy-sdk

For LangChain integration:

pip install agent-autopsy-sdk[langchain]

Usage

1. Basic -- wrap any agent code

from agent_autopsy import Autopsy

with Autopsy() as trace:
    trace.log("tool_call", "search_web", input="refund policy", duration_ms=340)
    trace.log("llm_call", "gpt-4o", input="Summarise results", duration_ms=1200)
    # If an exception occurs here, a JSON trace file is written automatically.
    result = my_agent.invoke({"input": "Process refund for order #9281"})

# Success -> nothing written (silent)
# Error   -> ./autopsy_sess_<hash>.json created

2. With LangChain -- automatic event capture

from agent_autopsy import Autopsy
from agent_autopsy.langchain_handler import AutopsyLangChainHandler

handler = AutopsyLangChainHandler()

with Autopsy(handler=handler) as trace:
    chain.invoke(
        {"input": "Process refunds"},
        config={"callbacks": [handler]},
    )
# All LLM calls, tool calls, and chain steps are captured automatically.
# On error, everything is written to a single JSON file.

3. CLI -- view a trace file

# Pretty-printed terminal tree (with colours)
autopsy view autopsy_sess_a7f3b2c.json

# Raw JSON output
autopsy view autopsy_sess_a7f3b2c.json --raw

How it works

  1. Autopsy() creates a trace session with a unique ID
  2. During the with block, call trace.log() to record events (or use the LangChain handler for automatic capture)
  3. On __exit__:
    • No exception -- session is discarded, no file written, zero overhead
    • Exception -- session + full traceback are written to a JSON file

Every JSON file includes all captured events with timestamps, durations, input/output previews, and error messages.

JSON output format

{
  "session_id": "a7f3b2c",
  "start_time": "2026-03-05T14:32:01.000000+00:00",
  "end_time": "2026-03-05T14:32:08.200000+00:00",
  "error": "Traceback (most recent call last): ...",
  "entries": [
    {
      "timestamp": "2026-03-05T14:32:01.500000+00:00",
      "type": "tool_call",
      "name": "search_orders",
      "input_preview": "{\"order_id\": \"9281\"}",
      "output_preview": "{\"order\": {\"id\": 9281}}",
      "duration_ms": 340,
      "status": "ok"
    }
  ],
  "_aegis_footer": {
    "message": "For tamper-evident, cryptographically verifiable traces: https://www.aegis-ledger.com",
    "upgrade": "pip install aegis-ledger-sdk[langchain]"
  }
}

Going to Production?

agent-autopsy is a debugging tool for local development. When you need tamper-evident, hash-chained, cryptographically signed traces for production -- upgrade to the full Aegis Ledger SDK:

pip install aegis-ledger-sdk
# Upgrade from agent-autopsy to production tracing:
from aegis import AegisClient
from aegis.langchain import AegisCallbackHandler
client = AegisClient(canister_id="...", api_key_id="...", private_key_path="./key.pem", agent_id="my-agent")
handler = AegisCallbackHandler(client)

Every trace is hash-chained (SHA-256) and signed (Ed25519 or Post-Quantum: ML-DSA-65, ML-DSA-87, SLH-DSA-128s, Hybrid) on the Internet Computer. Tamper-evident. Auditable. Cryptographically verifiable.

Learn more at aegis-ledger.com.

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

agent_autopsy_sdk-0.1.2.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

agent_autopsy_sdk-0.1.2-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file agent_autopsy_sdk-0.1.2.tar.gz.

File metadata

  • Download URL: agent_autopsy_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for agent_autopsy_sdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6198f7e79a20812b58c9b77a3dd0eb0ed551de62b8f7c99d11acd06a20d2c02a
MD5 2fd23f7388cd8c15f8bedd14557def1a
BLAKE2b-256 b2115feed8d4f69350023e071156ffd8cfbccf3b6c14566b4cba5863c7355513

See more details on using hashes here.

File details

Details for the file agent_autopsy_sdk-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for agent_autopsy_sdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cfa578c01c6bf268156af74f1306007bfa8ee7786aa5520e64c053f3ac247063
MD5 7d0ef627f84ff127791f92987adff0e8
BLAKE2b-256 0e064c7f9e8b9c579955af100523ea0b04732f380729ec198b78f544fc9a6cf7

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