Skip to main content

🔍 AzureAICommunity - Agent - Trace Diff (Python)

Deterministic trace comparison for Microsoft Agent Framework runs.

PyPI Version Python Versions PyPI Downloads License PyPI Status GitHub Follow YouTube Channel LinkedIn

Compare agent runs and inspect what changed.

Getting Started · Configuration · Usage · Contributing


Overview

azureaicommunity-agent-diagnostics-trace-diff captures detached snapshots of Microsoft Agent Framework runs and compares their inputs, responses, and metadata. Use it for prompt regression checks, debugging, and CI.


✨ Features

Feature
🧊 Detached snapshots of input, response, and run metadata
⚖️ Deterministic comparisons with added, removed, modified, and moved changes
🎛️ Configurable comparison of messages, metadata, tool arguments, and results
🔀 Message matching with LCS or greedy strategies
🧾 Built-in renderers for console, JSON, and standalone HTML reports

📦 Installation

Requires Python 3.11 or later.

pip install azureaicommunity-agent-diagnostics-trace-diff

🚀 Quick Start

Compare locally constructed responses without calling a model provider:

import sys

from agent_framework import AgentResponse, Message
from agent_trace_diff import (
    AgentTraceDiffEngine,
    AgentTraceDiffJson,
    AgentTraceSnapshotFactory,
    ConsoleAgentTraceDiffRenderer,
    HtmlAgentTraceDiffRenderer,
)

inputs = [Message("user", ["Find a laptop under $1000."])]
baseline_response = AgentResponse(messages=[Message("assistant", ["Two laptops found."])])
candidate_response = AgentResponse(messages=[Message("assistant", ["Three laptops found."])])

baseline = AgentTraceSnapshotFactory.create("baseline", inputs, baseline_response, model_id="model-a")
candidate = AgentTraceSnapshotFactory.create("candidate", inputs, candidate_response, model_id="model-b")
result = AgentTraceDiffEngine.compare(baseline, candidate)

ConsoleAgentTraceDiffRenderer().render(result, sys.stdout)
print(AgentTraceDiffJson.serialize(result))

html = HtmlAgentTraceDiffRenderer().render_to_string(result)
with open("agent-trace-diff.html", "w", encoding="utf-8") as report:
    report.write(html)

⚙️ Configuration

Use AgentTraceDiffOptions to control which fields are compared and how messages are matched:

from agent_trace_diff import AgentTraceDiffOptions, AgentTraceMessageMatchStrategy

options = AgentTraceDiffOptions(
    ignore_message_ids=True,
    ignore_timestamps=True,
    ignore_whitespace=False,
    compare_input_messages=True,
    compare_response_messages=True,
    compare_tool_arguments=True,
    compare_tool_results=True,
    compare_metadata=True,
    compare_model_id=True,
    message_match_strategy=AgentTraceMessageMatchStrategy.LCS,  # or GREEDY
)
result = AgentTraceDiffEngine.compare(baseline, candidate, options)

🧑‍💻 Usage

For live agents, pass the input messages and each await agent.run(...) response to AgentTraceSnapshotFactory.create(...). A prompt string can be passed instead of input messages. Optional snapshot metadata includes model_id, duration, provider_name, and agent_trace_options.

  • AgentTraceDiffEngine.compare(...) compares two snapshots.
  • AgentTraceDiffComparer supports custom message matcher and metadata differ implementations.
  • ConsoleAgentTraceDiffRenderer.render(...) writes a report to a text stream.
  • AgentTraceDiffJson.serialize(...) serializes a result as JSON.
  • HtmlAgentTraceDiffRenderer.render(...) and render_to_string(...) produce a standalone HTML report.

Snapshots and reports can contain prompts, tool data, responses, and content URIs. Treat them as sensitive data.

Run the Foundry sample

The repository sample compares two Foundry agent runs. Install its additional dependencies, configure the project endpoint and model deployment, then run it from the repository root:

python -m pip install agent-framework agent-framework-foundry azure-identity
$env:AZURE_AI_PROJECT_ENDPOINT = "https://<your-resource>.services.ai.azure.com/api/projects/<your-project>"
$env:AZURE_AI_MODEL_DEPLOYMENT_NAME = "<your-model-deployment>"
python AgentFramework\Python\Sample\trace_diff.py

The sample uses DefaultAzureCredential and writes three HTML reports to the current directory.


🤝 Contributing

Contributions are welcome! Open an issue to discuss proposed changes before submitting a pull request.


👤 Author

Built and maintained by Vinoth Rajendran.


📄 License

MIT, as declared in pyproject.toml.

Metadata

Release files for azureaicommunity-agent-diagnostics-trace-diff 1.0.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 azureaicommunity-agent-diagnostics-trace-diff 1.0.0
File Size Uploaded Provenance Actions
azureaicommunity_agent_diagnostics_trace_diff-1.0.0.tar.gz 13.1 kB Without provenance Details for azureaicommunity_agent_diagnostics_trace_diff-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for azureaicommunity-agent-diagnostics-trace-diff 1.0.0
File Interpreter ABI Platform Actions
azureaicommunity_agent_diagnostics_trace_diff-1.0.0-py3-none-any.whl Python 3 none any Details for azureaicommunity_agent_diagnostics_trace_diff-1.0.0-py3-none-any.whl

Total release size: 25.5 kB

Release files / azureaicommunity_agent_diagnostics_trace_diff-1.0.0.tar.gz

Download URL azureaicommunity_agent_diagnostics_trace_diff-1.0.0.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5107cd60cd519cc5afea7e07900189544cce612fc0857dc02ebce86b92e92d7d
BLAKE2b-256 checksum
How to use checksums
de8d03e1c87c6983f87d779a34756128dabdc11574c7a1d095f4d49413224cc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Release files / azureaicommunity_agent_diagnostics_trace_diff-1.0.0-py3-none-any.whl

Download URL azureaicommunity_agent_diagnostics_trace_diff-1.0.0-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0d618c7b39ff372522aad2e4ac0bf3dc2ce6d1f01796a1d6132a5c3379e7006
BLAKE2b-256 checksum
How to use checksums
a4570083dc30a38f08c6b1812891e48e583372c72634339ac82b599f05cb152c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Security for azureaicommunity-agent-diagnostics-trace-diff 1.0.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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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