Engine Specification & Architecture

How the engine evaluates agent trajectories in single-digit milliseconds.

A technical deep-dive into the deterministic graph algorithms powering AgentDiff: topological trace normalization, modified LCS alignment, k-gram loop detection, and rule-based root cause isolation in CI.

Zero LLM Judge CallsSub-5ms Execution Latency100% Deterministic CI Block
01 / Trace Ingestion & Normalization

Structural Equivalence Signatures.

Before comparison, raw telemetry traces from LangGraph, CrewAI, OpenAI Agents, and OpenTelemetry are normalized into strongly typed execution DAGs. Every node computes a deterministic structural signature.

Stage 1 · Ingestion

Raw Telemetry Trace

Ingests heterogeneous spans and execution logs containing variable timestamps, ephemeral UUIDs, and tool payloads.

step_type: "tool"
name: "vector_query"
uuid: "4a89-ef12..."
Stage 2 · Masking

Semantic Key Extraction

Drops non-deterministic noise (timestamps, tokens, UUIDs) and sorts input dictionary keys to ensure deterministic ordering.

− Drop volatile UUIDs
+ Sort payload keys
→ ("query", "top_k")
Stage 3 · Signature

Canonical Signature Token

Generates an immutable node tuple token ready for high-speed topological longest common subsequence alignment.

("tool", "vector_query", ("query", "top_k"))

Deterministic Hashing Contract

When strict_tool_signatures = true is enabled, AgentDiff performs recursive value hashing on payload contents while applying user-defined regex exclusion masks in agentdiff.toml.

Sub-50μs Hash LatencyZero Floating Point Drift
normalized_node.json
{ "step_id": "step_89f02c", "parent_id": "step_14a81b", "step_index": 3, "step_type": "tool", "name": "search_vector_database", "input_payload": { "query": "customer ARR", "top_k": 5 }, "output_payload": { "matched_chunks": 3 }, "metrics": { "latency_ms": 218.4, "input_tokens": 420, "output_tokens": 180, "cost_usd": 0.0024 } }
02 / The Alignment Engine

Topological Longest Common Subsequence.

Standard string diff algorithms fail on AI agent executions because tool calls contain causal dependencies and cyclic retries. AgentDiff aligns complex execution DAGs through a high-speed 3-phase graph engine.

Phase 1 · DAG Sort

Topological Dependency Linearization

Linearizes the execution graph via Kahn's algorithm while preserving strict causal dependency edges defined by parent pointers.

O(V + E) Dependency Traversal
Phase 2 · 2D Grid

Dynamic Programming Table

Constructs an optimized dynamic programming matrix scoring exact signature matches, structural insertions, and tool modifications.

Sub-5ms Execution Latency
Phase 3 · Classification

Optimal Path Backtracking

Backtracks the optimal alignment path to mark each step as Matched, Added, Removed, or Modified with sub-cent token delta tracking.

Root Cause Loop Pinpointing
Live Alignment Matrix

Candidate vs Baseline Execution Sequence

Step-by-step alignment path showing exact match points, syntax modifications, and stagnant loop injections.

IndexBaseline StepCandidate StepAlignment VerdictObserved Delta
01planner:intentplanner:intentMatchedIdentical signature
02search_db(query)search_db(query)MatchedIdentical signature
03synthesize_sqlsynthesize_sqlModifiedsyntax_version: 1 → 2
04— (absent in baseline)retry_sql_queryLoop InjectedRepetition 1 (+48% tokens)
05— (absent in baseline)retry_sql_queryLoop InjectedRepetition 2 (+100% tokens)
06execute_db_poolexecute_db_poolMatchedFallback recovery
03 / The 4 Core Metrics

Four deterministic metrics. Zero black-box judges.

Every verdict in AgentDiff is mathematically calculated from graph topology and execution telemetry. No subjective prompts or nondeterministic LLM evaluation latencies.

Metric 01Sequence Divergence

Trajectory Divergence Index

Measures how far the candidate execution drifted from the golden baseline sequence. Computes the ratio of common valid tool steps to total graph size.

Range: 0.0 (Identical)1.0 (Full Divergence)
Sequence Alignment Preview
Baseline:
authsearchfilterexport
Candidate:
authsearchraw_sql (drift)scrape (drift)export (drift)

Calculated via Kahn's topological sort + DP longest common subsequence in < 2ms.

Metric 02Cost & Loop Blocker

Stagnant Loop Detection

Identifies agents trapped in infinite retry cycles with stagnant parameter signatures that fail to make state progress.

CI Gate: allow_loops = false (Instant 0/1 Fail)
Cycle Identification Pattern
1. query_db(id=402, page=1)500 Server Error
↻ 2. query_db(id=402, page=1) [stagnant args]Loop Trapped

Distinguishes valid progressive pagination from non-productive retry spirals.

Metric 03Compute Efficiency

Wasted Effort Index

Calculates the exact percentage of compute time, steps, and token spend allocated to non-productive execution branches.

Efficiency Target: WEI < 0.10 (under 10% waste)
Compute Allocation Breakdown
75% Productive Execution (6 steps)25% Wasted Retries (2 steps)

Quantifies whether prompt updates actually streamline execution or silently bloat costs.

Metric 04Self-Healing Resilience

Recovery Step Ratio

Evaluates how quickly your agent recovers from intermediate tool errors compared to the golden baseline.

Resolution Ratio: 1.0 (Optimal Recovery)
Error Recovery Comparison
Baseline:Error1 fallback step (380ms)
Candidate:ErrorRetry 1Retry 23 steps (1,420ms)

Ensures prompt refactors don't quietly degrade error-handling resilience.

04 / Root Cause Synthesis

Know the exact culprit step in plain English.

When a merge gate fails, developers shouldn't spend hours parsing massive JSON telemetry traces. AgentDiff runs a deterministic rules cascade that isolates the culpable tool step and failure mechanism automatically.

Priority 1 · Critical

Loop Attribution

Identifies the exact cycle length, repeating function name, and stagnant parameter payload that caused the failure.

→ Culprit: retry_sql_query (k=1)
Priority 2 · Drift

Fork Point Discovery

Pins the exact step index where the candidate execution graph diverged from the golden baseline DAG.

→ Fork Index: Step 03 diverged
Priority 3 · Delta

Resource Attribution

Calculates exact token delta percentages and sub-cent USD cost spikes directly attributed to the culprit node.

→ Cost Spike: +170% on Step 04
Deterministic Explanation Engine

Instant root-cause isolation in your terminal and PR comments.

No guessing whether a regression was caused by prompt drift, tool schema changes, or database timeouts. AgentDiff renders the entire execution hierarchy with actionable blame lines.

0ms LLM LatencyPure AST Graph Evaluation
$ agentdiff diff baseline.json candidate.json --treeExit Code 1
baseline [4 steps] vs candidate [6 steps]
  1 · planner:task_intent
  2 · search_vector_db
  3 ~ synthesize_sql            (changed)
  4 + retry_sql_query           (added — culprit loop)
  5 + retry_sql_query           (added — stagnant cycle)
  6 · execute_db_pool
Root Cause Finding:'retry_sql_query' entered an infinite loop repeating 2 times with identical arguments after a 500 SQL syntax error.
05 / Config as Code

Declarative governance in agentdiff.toml.

Thresholds and masking rules live directly in your Git repository. Every engineer, branch, and CI runner shares the exact same single source of truth.

01 · Version Controlled

Tracked in Git

Gate rules sit right next to your agent code. Changes to tolerance thresholds require PR approval and code review.

02 · Masking Engine

Semantic Regex Masks

Automatically strip non-deterministic tokens, ephemeral session IDs, and UUIDs to prevent false-positive CI failures.

03 · CI Automation

Deterministic Exit Codes

Emits clean 0/1 exit codes that instantly integrate into GitHub Actions, GitLab CI, and custom test runners.

Production Configuration

Complete TOML Schema Specification

Drop this file at your repository root to configure assertion thresholds, semantic masks, and governance policies.

agentdiff.toml
# agentdiff.toml — Committed repository configuration [compare] detect_loops = true strict_tool_signatures = false [assertions] max_divergence = 0.25 # Fails CI if TDI > 0.25 max_wasted_effort = 0.10 # Fails CI if > 10% compute is wasted allow_loops = false # Fails CI on any tool repetition max_cost_increase_pct = 5.0 # Fails CI if cost delta > +5% max_recovery_step_ratio = 1.5 # Fails CI if error recovery degrades > 1.5x [masking] ignore_keys = ["timestamp", "session_id", "trace_id", "auth_token"] regex_patterns = ["^uuid_[0-9a-f-]+$", "^Bearer\\s+.*$"] [governance] warn_stale_baseline_days = 30 # Warns when golden baseline exceeds 30 days flag_threshold_changes = true # Flags PRs that lower gate rigor
Start In Minutes

Ready to catch regressions before they hit production?

Install the Python package, record your first golden baseline, and guard your CI pipeline in under 5 minutes.