Skip to main content

CLI tool to generate Mermaid sequence diagrams from A2A protocol traces

Project description

A2A-Mermaid-Tracer

CI Python 3.10+ License: MIT

CLI tool to generate Mermaid.js sequence diagrams from A2A (Agent2Agent) protocol communication traces.

Visualize multi-agent interactions at a glance.

Example diagram

Features

  • Parse JSON-RPC 2.0 trace logs (JSON array or NDJSON format)
  • Generate Mermaid sequence diagrams with:
    • Request arrows (solid)
    • Response arrows (dashed)
    • Error indicators (cross arrows)
    • Timestamp annotations
    • Task ID references
    • Task grouping (--group-by-task for rect blocks)
  • Output to stdout or file (.md with code block, or raw .mmd)
  • Stdin support (--input -) for pipeline usage
  • Strict mode (--strict) to fail on malformed entries

Installation

pip install a2a-mermaid-tracer

Or for development:

git clone https://github.com/matthieu-music/a2a-mermaid-tracer.git
cd a2a-mermaid-tracer
pip install -e ".[dev]"

Quick Start

# From a file
a2a-mermaid-tracer generate --input traces.json --output diagram.md

# From stdin
cat traces.json | a2a-mermaid-tracer generate --input - --title "My Agents"

# With task grouping
a2a-mermaid-tracer generate --input traces.json --group-by-task

# Strict mode (fail on bad entries)
a2a-mermaid-tracer generate --input traces.json --strict

Example output

sequenceDiagram
    participant OrchestratorAgent as OrchestratorAgent
    participant ResearchAgent as ResearchAgent
    participant AnalystAgent as AnalystAgent
    participant WriterAgent as WriterAgent

    OrchestratorAgent ->> ResearchAgent: "Find Q1 2025 earnings for AAPL"
    Note right of OrchestratorAgent: 10:30:00
    ResearchAgent -->> OrchestratorAgent: "AAPL Q1 2025: Revenue $124.3B, EPS $2.40"
    OrchestratorAgent ->> AnalystAgent: "Analyze AAPL earnings vs Q1 2024"
    Note right of OrchestratorAgent: 10:30:04
    AnalystAgent --x OrchestratorAgent: ERROR: Missing Q1 2024 data for comparison
    OrchestratorAgent ->> ResearchAgent: "Find Q1 2024 earnings for AAPL"
    Note right of OrchestratorAgent: 10:30:09
    ResearchAgent -->> OrchestratorAgent: "AAPL Q1 2024: Revenue $119.6B, EPS $2.18"
    OrchestratorAgent ->> AnalystAgent: "Analyze AAPL Q1 2025 vs Q1 2024"
    Note right of OrchestratorAgent: 10:30:12
    AnalystAgent -->> OrchestratorAgent: "Revenue +3.9% YoY, EPS +10.1% YoY"
    OrchestratorAgent ->> WriterAgent: "Write a brief earnings report for AAPL"
    Note right of OrchestratorAgent: 10:30:17
    WriterAgent -->> OrchestratorAgent: "AAPL Q1 2025 Report: Strong growth with"

CLI Reference

Usage: a2a-mermaid-tracer generate [OPTIONS]

Options:
  -i, --input PATH       Path to trace file (JSON array or NDJSON). Use '-' for stdin.  [required]
  -o, --output PATH      Path to write the Mermaid diagram (default: stdout)
  -t, --title TEXT       Optional title for the diagram
  --strict               Fail on malformed entries instead of skipping them
  --group-by-task        Group interactions by task ID in rect blocks
  --help                 Show this message and exit.

Trace format

The input file should contain JSON-RPC 2.0 messages with sender/receiver metadata:

[
  {
    "sender": "AgentA",
    "receiver": "AgentB",
    "timestamp": "2025-06-15T10:30:00Z",
    "message": {
      "jsonrpc": "2.0",
      "id": "req-001",
      "method": "message/send",
      "params": { ... }
    }
  }
]

NDJSON (one JSON object per line) is also supported — see examples/sample_traces.ndjson.

Development

pip install -e ".[dev]"
ruff check src/ tests/
ruff format src/ tests/
pytest

License

MIT

Project details


Download files

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

Source Distribution

a2a_mermaid_tracer-0.2.0.tar.gz (104.7 kB view details)

Uploaded Source

Built Distribution

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

a2a_mermaid_tracer-0.2.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file a2a_mermaid_tracer-0.2.0.tar.gz.

File metadata

  • Download URL: a2a_mermaid_tracer-0.2.0.tar.gz
  • Upload date:
  • Size: 104.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for a2a_mermaid_tracer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 23ffd152560ebce55d0ebbb7ceaa6b1d4d669acee236bca75afcef04a72dc214
MD5 adc904bafd7ed336b127104341b90b75
BLAKE2b-256 3c5f46cf883ca91949e6ccb4774673287af4084546a9430a417d367b916ae5c5

See more details on using hashes here.

File details

Details for the file a2a_mermaid_tracer-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for a2a_mermaid_tracer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c29b176728e59e390c48d90998a13a80a1134a3b9d7a5bbd341bf5e5079068a4
MD5 e1db0e704df72f1ba51fe0c1da164445
BLAKE2b-256 2149b6cc80446c423089376da45dfe5afb7dbbd122e63efc10d27928f153dd72

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page