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 is in src/tracedojo/templates/booking.

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.1

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.1
File Size Uploaded Provenance Actions
tracedojo-0.1.1.tar.gz 63.2 kB Without provenance Details for tracedojo-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 115.4 kB

Release files / tracedojo-0.1.1.tar.gz

Download URL tracedojo-0.1.1.tar.gz
Size 63.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f7c93fda89da7918a77bec0420cbcae1d4e049d43db4594e180c326b0d6ca78b
BLAKE2b-256 checksum
How to use checksums
0634b69a71ed813a11ed6e291f1c0bb1d3414b4567f250693ad939917c278b34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.0

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

Download URL tracedojo-0.1.1-py3-none-any.whl
Size 52.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f575b0ebd0e27e9e2cc85943215b351be78d24f697de42b1488d68f7ad6251cc
BLAKE2b-256 checksum
How to use checksums
a12980fc556e09b9307a72ff87e0d6537e0e3343dab2ef27fd9968684490d7da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.0

Security for tracedojo 0.1.1

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