AgentDiff
AgentDiff is a developer-first Python library and CLI designed to solve the hardest problem in agent engineering: regression testing multi-turn, tool-using AI agents by comparing execution paths (trajectories) head-to-head.
What AgentDiff Is
- A Trajectory Diff Engine: Compares Run A (Baseline) against Run B (Candidate) across their execution Directed Acyclic Graphs (DAGs).
- A Local-First CI/CD Gate: Runs locally in your terminal or inside
pytestand GitHub Actions, raising errors or exit codes on regression violations. - A Universal Comparator: Ingests telemetry run files from DeepEval, OpenInference/OTel, Langfuse, or raw/custom JSON.
Installation
Install via pip:
pip install agentdiff
Or using uv:
uv add agentdiff
Quickstart
1. CLI Usage
Compare two trajectory JSON traces from your terminal:
agentdiff diff baseline_run.json candidate_run.json --fail-on-regression --max-divergence 0.25
Options:
--adapter: Telemetry parser to use (auto,generic,deepeval,openinference,langfuse).--format: Format for the output (terminal,json,markdown).--fail-on-regression: Return exit code1if thresholds are violated.--max-loops: Maximum loops allowed.--max-divergence: Maximum Trajectory Divergence Index (TDI) allowed.--max-cost-delta: Maximum cost increase percentage allowed.
2. Python SDK & Pytest Integration
Catch agent loop regressions or token cost spikes in your test suites:
import pytest
from agentdiff import load_trace, compare
from agentdiff.testing import assert_no_regressions
def test_agent_refactor_efficiency():
# Load traces from disk (auto-detects formats like DeepEval)
baseline = load_trace("tests/traces/baseline.json")
candidate = load_trace("tests/traces/candidate.json")
# Run the comparison
report = compare(baseline, candidate)
# Expressive assertion helper that raises detailed error messages on regression
assert_no_regressions(
report,
max_divergence=0.25, # TDI threshold [0.0 - 1.0]
max_cost_increase_pct=5.0, # Max cost increase allowed
allow_loops=False, # Reject if tool loops are detected
max_wasted_effort=0.10 # Max Wasted Effort Index (WEI) allowed
)
Core Metrics
| Metric | Target / Range | Algorithmic Definition |
|---|---|---|
| Trajectory Divergence Index (TDI) | 0.0 (Identical) to 1.0 (Divergent) |
$$1.0 - \frac{2 \times \vert{}\text{LCS}(\text{Steps}_A, \text{Steps}_B)\vert{}}{\vert{}\text{Steps}_A\vert{} + \vert{}\text{Steps}_B\vert{}}$$ |
| Wasted Effort Index (WEI) | 0.0 (Optimal) to 1.0 (Total Waste) |
$$\frac{\text{Count}(\text{Steps with status} \in {\text{ERROR, RETRY, ABANDONED}})}{\text{Total Execution Steps}}$$ |
| Loop Buster Index (LBI) | Integer ($\ge 0$) | Detects consecutive repeating sequences of tools with stagnant state changes. |
| Resource Deltas ($\Delta\text{Res}$) | Percentage ($\pm%$) | Standard deltas for $\Delta\text{Tokens}$, $\Delta\text{Cost}$, and $\Delta\text{Latency}$. |
Development & Operations
This project utilizes uv to manage environments and dependencies. Automation tasks are defined in the Makefile:
make lint/make format: Run Ruff linter checks and formatter.make test: Run pytest suite (including style & formatting assertions).make build: Package the library into source and wheel distributions indist/.make website-dev: Start the Next.js landing and documentation site local server.make website-build: Build the Next.js static output inwebsite/out/.
Repository Layout
src/: Python source code package modules.tests/: Quality assurance unit tests.website/: Next.js web application and documentation pages.
Metadata
Release files for agent-trajectory-diff 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| agent_trajectory_diff-0.1.0.tar.gz | 26.7 kB | Without provenance | Details for agent_trajectory_diff-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| agent_trajectory_diff-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for agent_trajectory_diff-0.1.0-py3-none-any.whl |
Total release size: 62.7 kB
Release files / agent_trajectory_diff-0.1.0.tar.gz
| Download URL | agent_trajectory_diff-0.1.0.tar.gz |
|---|---|
| Size | 26.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1ae534ab2eb4db4dd7f52f999e2bcd84c5ff8c1438971041ccd13800f0c4db36
|
|
BLAKE2b-256 checksum How to use checksums |
b017f5a5394e11441b5902fb7fc9ec50c4221f7f7008fe1ad5516af35a754707
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / agent_trajectory_diff-0.1.0-py3-none-any.whl
| Download URL | agent_trajectory_diff-0.1.0-py3-none-any.whl |
|---|---|
| Size | 36.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a53920b2a9859181018741c5fbf156eee3b13755fad89ecdef023d5fd28a9017
|
|
BLAKE2b-256 checksum How to use checksums |
1b27bef877f1c0d4f71779f8398a6a2770c8c4e19ff1ac62b50ec76293700774
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for agent-trajectory-diff 0.1.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.
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.