Skip to main content

CaseTrace

CI PyPI Python License

A flight recorder for multi-agent AI systems. CaseTrace reads a multi-agent execution trace, builds a deterministic map of agent handoffs and tool dependencies, prunes unreferenced noise, and then asks a structured judge: which agent, at which step, and what kind of error caused this run to fail? It can also answer NO_FAULT on healthy runs and ABSTAIN when the evidence is insufficient.

Status: v0.2.0. This release adds a deterministic 40-trace controlled suite (30 injected faults + 10 clean runs), resumable batch evaluation (casetrace eval), and Markdown/JSON reporting (casetrace report). Public benchmark reproduction on Who&When and Who&When Pro is still not part of this release — see Scope. No benchmark numbers are claimed yet. The project framing is engineering and evaluation quality, not research novelty.

For the plain-language overview see project_overview.md. For the frozen evaluation contract see casetrace_attribution_protocol.md.

Install

Python 3.11+ is required. Install from PyPI:

python -m pip install casetrace

With an optional model provider:

python -m pip install "casetrace[gemini]"
python -m pip install "casetrace[openai]"
python -m pip install "casetrace[anthropic]"

Using uv:

uv tool install casetrace
uv tool install "casetrace[gemini]"

Exact token counting (instead of the built-in estimate) is optional:

python -m pip install "casetrace[tokens]"

Quickstart

The offline demo uses the deterministic stub judge, so it needs no API key and no network:

casetrace demo                 # faulted sample: prints the graph + verdict
casetrace demo --trace clean   # healthy sample: prints NO_FAULT

Run it on your own trace:

casetrace graph path/to/trace.jsonl
casetrace analyze path/to/trace.jsonl --mode structure_first --provider stub

Against a real model:

export GOOGLE_API_KEY="..."
casetrace analyze path/to/trace.jsonl --provider gemini --model gemini-2.5-flash

Append a protocol-shaped JSONL log for later reporting:

casetrace analyze path/to/trace.jsonl --out results/runs.jsonl

Batch-evaluate the bundled controlled suite and build a report:

casetrace eval --dataset controlled_mixed --provider stub --out results/controlled.jsonl
casetrace report --input results/controlled.jsonl

The stub rows are demo-only (see Limitations). Real-provider evaluation uses the same JSON prompt/parse path and resumes automatically if a run is interrupted:

casetrace eval --dataset controlled_mixed --provider gemini \
  --model gemini-2.5-flash --out results/gemini.jsonl
casetrace report --input results/gemini.jsonl --out results/gemini.md

From a source clone:

uv sync
uv run casetrace demo
uv run pytest

How it works

trace JSONL ──▶ normalize ──▶ build handoff/tool graph ──▶ prune unreferenced payloads
                                                              │
                                                              ▼
                                                     structured judge ──▶ verdict
                                                                           (agent, step,
                                                                            error_mode,
                                                                            evidence,
                                                                            confidence)
  1. Normalize the trace into a Trajectory with indexed Steps.
  2. Build a deterministic graph: consecutive-agent handoffs, tool-call → tool-result edges, and explicit references between steps.
  3. Prune tool outputs that no later step references, while preserving every step index, agent, status, and causal edge.
  4. Judge the pruned context (or the full context for the all_at_once baseline) and validate the response into a strict Verdict.

The graph and pruning steps never call a model, so casetrace graph is fully reproducible and free.

Trace format

The generic adapter accepts a single JSON object, a JSON array of objects, or JSONL with one object per line:

{
  "id": "trace-001",
  "dataset": "generic_jsonl",
  "steps": [
    {"index": 0, "agent": "planner", "kind": "plan", "content": "Fetch prices, then total."},
    {"index": 1, "agent": "tool_executor", "kind": "tool_call", "tool_name": "http_get"},
    {"index": 2, "agent": "tool_executor", "kind": "tool_result", "tool_name": "http_get", "tool_output": "{...}", "references": [1]},
    {"index": 3, "agent": "verifier", "kind": "verify", "content": "Checked the total.", "references": [2], "status": "error", "error_type": "invalid_tool_argument"}
  ],
  "final_output": "Total: 100 USD",
  "metadata": {"ground_truth": {"is_clean": false, "agent": "verifier", "step": 3, "error_mode": "invalid_tool_argument"}}
}

references is optional but is what lets the graph recover causal edges from a flat log. metadata.ground_truth is only read by the offline stub and by metric scoring; a real judge never sees it.

CLI reference

Command What it does
casetrace graph TRACE [--json] [--max-chars N] Print the handoff/tool graph and pruning savings. No LLM call.
casetrace analyze TRACE [--mode structure_first|all_at_once] [--provider stub|gemini|openai|anthropic] [--model ID] [--out FILE] [--json] Attribute one trace and optionally append a JSONL run log.
casetrace eval [--dataset controlled_mixed|generic_jsonl] [--traces FILE] [--config structure_first|all_at_once] [--provider stub|gemini|openai|anthropic] [--model ID] [--out FILE] [--limit N] [--resume|--no-resume] [--overwrite] [--json] Batch-evaluate a dataset and append resumable run logs.
casetrace report [--input FILE|DIR] [--out FILE] [--json] Aggregate run logs into Markdown tables or JSON summaries.
casetrace demo [--trace fault|clean] [--json] Run the bundled offline samples with the stub judge.
casetrace version Print the installed version.

--provider stub is the default and is deterministic. Real providers are experimental in v0.2.0 and are not exercised by CI.

Controlled suite

casetrace eval --dataset controlled_mixed uses a committed 40-trace suite generated deterministically by python -m casetrace.controlled_suite:

  • 10 clean runs,
  • 10 planner faults (bad routing at step 0),
  • 10 tool-executor faults (stale tool output at step 3),
  • 10 verifier faults (broken verification at step 4).

The suite is synthetic, zero-ambiguity, and designed to exercise the graph, pruning, logging, and reporting pipeline — not to stand in for a public benchmark. It ships inside the wheel at casetrace/data/controlled_mixed.jsonl.

Run log

--out appends one JSON line per run, matching section 5 of the frozen protocol (run_id, dataset, config, model, trace_*, ground_truth, prediction, metrics, systems_cost). Metrics include agent match, exact and within-1 step match, error-mode match, joint match, false alarm, and abstention.

Scope of v0.2.0

Included:

  • Deterministic handoff/tool-dependency graph and token-budgeted pruning.
  • Generic JSONL/JSON adapter.
  • structure_first judge and all_at_once baseline.
  • Offline stub judge, optional Gemini/OpenAI/Anthropic providers.
  • Metrics and protocol-shaped run logs.
  • Deterministic 40-trace controlled fault/clean suite.
  • Resumable batch evaluation (eval) and Markdown/JSON reporting (report).
  • graph, analyze, eval, report, demo, version CLI commands.

Deferred to later releases:

  • Who&When v1 and Who&When Pro adapters and benchmark reproduction.
  • Published benchmark numbers.
  • Calibrated abstention and split-conformal ablation.
  • binary_search and step_by_step baselines.

Limitations

  • The stub judge is not a real judge. It reads an explicit error flag, then a clean-run marker, and otherwise abstains. It exists for offline demos and tests, never as an evaluation baseline. Reports label model=stub rows as demo-only.
  • The controlled suite is synthetic. It has zero-ambiguity ground truth and is meant to exercise the pipeline. High stub scores on it are not evidence of attribution quality.
  • Token counts are estimates (~4 characters/token) unless the optional [tokens] extra is installed. README and CLI output label them as token counts, not exact tokenizer totals, unless tiktoken is active.
  • No benchmark numbers in v0.2.0. Published Who&When/Pro results are planned; none are claimed here.
  • Real providers are experimental. They share one JSON-parsing path and are not run in CI because that would require live keys and network access.
  • No calibrated abstention yet. ABSTAIN is a valid verdict but its confidence threshold is not calibrated on a dev split in this release.
  • Best-effort generic adapter only; framework-specific adapters (OpenTelemetry, LangGraph) are planned.

Prior art

CaseTrace is an applied engineering and evaluation toolkit, not a novel method. It builds on and must credit: Who&When, Who&When Pro, FALAT, FAMAS, TraceElephant, Aegis, AgenTracer, AgentDebugX, and conformal agent error attribution work.

Development

uv sync
uv run ruff check .
uv run mypy src
uv run pytest
uv run casetrace demo
uv run casetrace graph examples/sample_fault_trace.jsonl
uv run casetrace eval --dataset controlled_mixed --provider stub --out results/demo.jsonl
uv run casetrace report --input results/demo.jsonl

CI runs lint, strict type checking, a dependency audit, tests, and an offline smoke test on Python 3.11 and 3.13. Releases are published to PyPI from a protected environment using PyPI Trusted Publishing with PEP 740 attestations; no token is stored in the repository.

License

Apache-2.0. See LICENSE.

Metadata

Release files for casetrace 0.2.0

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

Source distribution (sdist)

Source distribution for casetrace 0.2.0
File Size Uploaded Provenance Actions
casetrace-0.2.0.tar.gz 187.0 kB With provenance Details for casetrace-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 232.8 kB

Release files / casetrace-0.2.0.tar.gz

Download URL casetrace-0.2.0.tar.gz
Size 187.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d32a1b181c3bb8f05100efb643219ff7e44fd8ee36e79d8bdd6912f2af6ef965
BLAKE2b-256 checksum
How to use checksums
a3abc5f70ee8670ad302c1c95dec22ab1681fbaaaaca8cc1a9d98c22b4e1c7f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.

Transparency log

Release files / casetrace-0.2.0-py3-none-any.whl

Download URL casetrace-0.2.0-py3-none-any.whl
Size 45.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d8e8eacb6ccca69dd720f83e39d55bc545a40c8902a9ed8bb3ec59ae667ef904
BLAKE2b-256 checksum
How to use checksums
5999f7818ea33deca6d698e4fefca44ffe9d9d85cafbb29b0fff32523e4edcc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.

Transparency log

Security for casetrace 0.2.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for casetrace-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.

Transparency log

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