Metadata-Version: 2.4
Name: azureaicommunity-agent-diagnostics-trace-diff
Version: 1.0.0
Summary: Deterministic trace comparison for Microsoft Agent Framework runs
License-Expression: MIT
Project-URL: Repository, https://github.com/rvinothrajendran/AgentFramework
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: agent-framework

<div align="center">

# 🔍 AzureAICommunity - Agent - Trace Diff (Python)

Deterministic trace comparison for **Microsoft Agent Framework** runs.

[![PyPI Version](https://img.shields.io/pypi/v/azureaicommunity-agent-diagnostics-trace-diff)](https://pypi.org/project/azureaicommunity-agent-diagnostics-trace-diff/)
[![Python Versions](https://img.shields.io/pypi/pyversions/azureaicommunity-agent-diagnostics-trace-diff)](https://pypi.org/project/azureaicommunity-agent-diagnostics-trace-diff/)
![PyPI Downloads](https://static.pepy.tech/badge/azureaicommunity-agent-diagnostics-trace-diff)
[![License](https://img.shields.io/pypi/l/azureaicommunity-agent-diagnostics-trace-diff)](https://pypi.org/project/azureaicommunity-agent-diagnostics-trace-diff/)
[![PyPI Status](https://img.shields.io/pypi/status/azureaicommunity-agent-diagnostics-trace-diff)](https://pypi.org/project/azureaicommunity-agent-diagnostics-trace-diff/)
[![GitHub Follow](https://img.shields.io/github/followers/rvinothrajendran?label=Follow%20%40rvinothrajendran&style=social)](https://github.com/rvinothrajendran)
[![YouTube Channel](https://img.shields.io/badge/YouTube-VinothRajendran-FF0000?logo=youtube&logoColor=white)](https://www.youtube.com/@VinothRajendran)
[![LinkedIn](https://img.shields.io/badge/LinkedIn-rvinothrajendran-0A66C2?logo=linkedin&logoColor=white)](https://www.linkedin.com/in/rvinothrajendran/)

**Compare agent runs and inspect what changed.**

[Getting Started](#-installation) · [Configuration](#️-configuration) · [Usage](#-usage) · [Contributing](#-contributing)

</div>

---

## 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.

```bash
pip install azureaicommunity-agent-diagnostics-trace-diff
```

---

## 🚀 Quick Start

Compare locally constructed responses without calling a model provider:

```python
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:

```python
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](../../Sample/trace_diff.py) compares two Foundry agent runs. Install its additional dependencies, configure the project endpoint and model deployment, then run it from the repository root:

```powershell
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**.

- 🐙 GitHub: [github.com/rvinothrajendran](https://github.com/rvinothrajendran)
- 📺 YouTube: [youtube.com/@VinothRajendran](https://www.youtube.com/@VinothRajendran)
- 💼 LinkedIn: [linkedin.com/in/rvinothrajendran](https://www.linkedin.com/in/rvinothrajendran/)

---

## 📄 License

MIT, as declared in [pyproject.toml](pyproject.toml).
