Skip to main content

TraceDojo for Python

Chaos testing for AI agent tools.

The booking succeeded. The response timed out. Your agent booked it again.

TraceDojo runs your agent against tools you simulate in memory, makes a tool call fail on purpose, and checks what actually changed in your application's state. Every test runs a no-fault control first, a fault the agent never reaches is reported as inconclusive instead of passing, and compare gates pull requests on regressions against the base commit.

This is the Python SDK. It writes the same report format as the JavaScript SDK (@tracedojo/sdk), so the TraceDojo dashboard, compare, and the CI gate accept reports from either language, and a Python report compares cleanly against a JavaScript one for the same workflow.

Python 3.10 or later. No runtime dependencies.

pip install tracedojo
pip install "tracedojo[langgraph]"  # with the LangGraph adapter

See a failure and its fix

tracedojo demo

It runs a scripted booking agent twice against a lost confirmation. The version that makes a new operation key per retry books twice and fails; the version that reuses its key passes. Both reports are saved in a new directory under .tracedojo/.

Test your agent

A workflow (workflow.json) holds the task, the starting state, outcome checks, and fault scenarios. It is the same workflow/1 file the JavaScript SDK reads; see docs/WORKFLOWS.md for every field. An adapter module defines the simulated tools and a factory for your agent:

# dojo/adapter.py
from tracedojo import tool


@tool("write")
def reserve_slot(args, state, context):
    """Only successful writes commit. Mutate the state draft, return a result."""
    key = args.get("operationKey")
    if not key:
        return {"ok": False, "error": {"code": "INVALID_ARGUMENTS", "message": "Provide operationKey.", "retryable": False}}
    if key in state["operations"]:
        return {"ok": True, "data": state["operations"][key]}
    booking = {"id": f"booking_{len(state['bookings']) + 1}", "customerId": args["customerId"], "slot": args["slot"]}
    state["bookings"].append(booking)
    state["operations"][key] = booking
    return {"ok": True, "data": booking}


tools = {"reserve_slot": reserve_slot}


class BookingAgent:
    id = "booking-agent"
    version = "1"

    async def run(self, context):
        for _attempt in range(3):
            # Route every tool call through context.call and always await it.
            # Reuse one operation key so a retry cannot book twice.
            result = await context.call(
                "reserve_slot", {"customerId": "customer_7", "slot": "slot_42", "operationKey": "one-booking"}
            )
            if isinstance(result, dict) and result["ok"]:
                return {"status": "completed", "message": "Meeting booked.", "output": {"bookingId": result["data"]["id"]}}
            if isinstance(result, dict) and not result["error"]["retryable"]:
                return {"status": "blocked", "message": result["error"]["message"]}
        return {"status": "blocked", "message": "The booking could not be confirmed."}


def create_agent():
    return BookingAgent()  # a fresh agent, with fresh conversation state, per trial
tracedojo test --config dojo/workflow.json --adapter dojo/adapter.py --trials 3 --out .tracedojo/report.json

The complete booking starter ships inside the package. Copy it to dojo/ to start from it (the Python CLI has no init):

cp -r "$(python -c 'import os, tracedojo.templates.booking as t; print(os.path.dirname(t.__file__))')" dojo

init, the service simulations, matrix, and proxy are in the JavaScript SDK only for now.

Or from Python:

from tracedojo import run_workflow, run_workflow_sync, workflow_exit_code

batch = run_workflow_sync(workflow_dict, adapter_module, trials=3, commit_sha=None)
# inside an event loop: batch = await run_workflow(workflow_dict, adapter_module)

Faults and checks

Faults: timeout_before, timeout_after, unavailable, malformed, permission_revoked, duplicate_delivery, stale_read, prompt_injection, each with occurrence and repeat. Checks: count, equals (state or completion), unchanged, forbidden_tool, tool_calls, tool_order. Semantics, limits, and statuses are identical to the JavaScript SDK.

Model faults (rate_limited, server_error, model_timeout, stream_cut, stream_stall, with target: "model") sit between an agent process and its model API, so only the JavaScript proxy runner (npx tracedojo proxy) injects them. run_workflow rejects them, as the JavaScript runWorkflow does. The Python SDK reads, validates, compares, summarizes, and uploads proxy reports that contain them.

The agent context

Member Purpose
await context.call(tool, args) Simulated tool call. Returns {"ok": True, "data": ...}, {"ok": False, "error": {...}}, or a string for a malformed response.
context.record_model(detail, payload=None) Evaluator-only model telemetry. Never include credentials or private reasoning.
context.clock.now(), await context.clock.sleep(ms) Real time, or virtual time when the workflow sets "clock": {"mode": "virtual"}.
context.signal Cancellation flag: aborted, throw_if_aborted().
context.task The workflow task text.
context.with_call(fn) A copy whose call is wrapped, for retry or backoff wrappers.

Tools and run may be sync or async. context.call starts the call immediately and returns an awaitable; a call still pending when the agent finishes is recorded as unawaited_calls. Use context.clock.sleep (not asyncio.sleep) so virtual time applies. Deadlines are cooperative: a synchronous handler that blocks the event loop cannot be interrupted, and adapters are trusted code, not sandboxed.

Compare, gate, and upload

tracedojo compare --base base-report.json --candidate pr-report.json --out comparison.json --summary comparison.md
TRACEDOJO_UPLOAD_TOKEN=... tracedojo upload report.json --url https://tracedojo.com --project PROJECT_UUID

Exit codes: 0 passed, 1 failed checks or regressions, 2 invalid input, 3 incomplete or inconclusive evidence. Output files must be new; existing evidence is never overwritten. Reports are redacted with the same patterns as the JavaScript SDK before they are written.

The base and candidate reports can come from either SDK. The JavaScript npx tracedojo compare and this tracedojo compare produce identical results.

LangGraph

from tracedojo.langgraph import LangGraphAgent

def create_agent():
    return LangGraphAgent(
        "support-agent",
        "2026-11-15",
        [reserve_slot_tool],          # your real LangChain tools; only name, description, and schema are used
        build_graph=lambda tools: my_graph_builder(model, tools),  # returns a compiled graph
        to_completion=lambda state: {"status": "completed", "message": state["messages"][-1].text},
    )

create_tools(context, tools) returns simulated stand-ins for your LangChain tools that route through context.call; the live tool functions are never invoked. Invoke graphs asynchronously (ainvoke). Model requests made by your graph use your provider account and may incur charges.

How parity is tested

tests/test_parity.py runs 38 workflow cases through both SDKs (the booking starter, all eight faults, every check type, run limits, protocol violations, and virtual time) and requires byte-identical reports after removing random IDs and timings. It also checks that each SDK's schema accepts the other's batches and rejects the same tampered ones, that compare gives identical results on mixed pairs, and that fingerprints, imported report IDs, redaction, workflow parsing, and Markdown summaries match. It needs Node and the built JavaScript SDK:

npm ci && npm run build            # repository root
cd packages/python && pip install -e ".[langgraph]" pytest && pytest

License

Apache-2.0. See LICENSE and NOTICE.

Metadata

Release files for tracedojo 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tracedojo 0.1.2
File Size Uploaded Provenance Actions
tracedojo-0.1.2.tar.gz 63.3 kB Without provenance Details for tracedojo-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tracedojo 0.1.2
File Interpreter ABI Platform Actions
tracedojo-0.1.2-py3-none-any.whl Python 3 none any Details for tracedojo-0.1.2-py3-none-any.whl

Total release size: 115.8 kB

Release files / tracedojo-0.1.2.tar.gz

Download URL tracedojo-0.1.2.tar.gz
Size 63.3 kB
Tags Source
SHA-256 checksum
How to use checksums
70f074815897101124a538d61d868cc94ee647219ea236a1e4e505c5ca35f6a9
BLAKE2b-256 checksum
How to use checksums
e4fd3faf159317af0af9a85c01b4296d245ccaf283b6b0eeb00b4bdd42b9d0c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.20

Release files / tracedojo-0.1.2-py3-none-any.whl

Download URL tracedojo-0.1.2-py3-none-any.whl
Size 52.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f66f3c955646b30b0918708adf7871cc842f5f621036b0a9885b6beb7b681f27
BLAKE2b-256 checksum
How to use checksums
2fb05dc5ef6cd1b642ffdbf7128f13896183ddd7e6afd1770a7acd77780067d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.20

Security for tracedojo 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page