Skip to main content

AgentDiff

License: GPL v3 Python Version

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 pytest and 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 code 1 if 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 in dist/.
  • make website-dev: Start the Next.js landing and documentation site local server.
  • make website-build: Build the Next.js static output in website/out/.

Repository Layout

  • src/: Python source code package modules.
  • tests/: Quality assurance unit tests.
  • website/: Next.js web application and documentation pages.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agent_trajectory_diff-0.1.0.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

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

agent_trajectory_diff-0.1.0-py3-none-any.whl (36.0 kB view details)

Uploaded Python 3

File details

Details for the file agent_trajectory_diff-0.1.0.tar.gz.

File metadata

  • Download URL: agent_trajectory_diff-0.1.0.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for agent_trajectory_diff-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1ae534ab2eb4db4dd7f52f999e2bcd84c5ff8c1438971041ccd13800f0c4db36
MD5 e1340a8a8f61961de6fe322953cc8f09
BLAKE2b-256 b017f5a5394e11441b5902fb7fc9ec50c4221f7f7008fe1ad5516af35a754707

See more details on using hashes here.

File details

Details for the file agent_trajectory_diff-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: agent_trajectory_diff-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 36.0 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for agent_trajectory_diff-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a53920b2a9859181018741c5fbf156eee3b13755fad89ecdef023d5fd28a9017
MD5 96ee9fbec47c9b2070c9244f052ed356
BLAKE2b-256 1b27bef877f1c0d4f71779f8398a6a2770c8c4e19ff1ac62b50ec76293700774

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.0

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

This release

0.1.0 This release

2 files

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