Skip to main content

handoffmap

English | 한국어

handoffmap folds an OpenTelemetry trace of a multi-agent run (OTel GenAI semantic conventions or OpenInference) into a Mermaid sequence diagram plus a per-agent table: who handed off to whom, who called whom as a tool, what ran in parallel, and how many tokens each agent used. It replaces reading dozens of span-tree lines by eye; paste the result into a PR, issue or README and GitHub renders it as a diagram. It reads an OTLP JSON/JSONL file, needs no server and has zero runtime dependencies. Try it: uv tool install git+https://github.com/LeeGyeongPil/handoffmap && handoffmap --sample pydantic-ai.

handoffmap showcase: raw Mermaid output Mermaid output (raw text; GitHub renders it as a diagram) of a sample trace built with Pydantic AI. A single par block shows that the orchestrator called the researcher and the writer as tools at the same time.

What is handoffmap

It is like receiving one page with an org chart plus a timeline instead of reading the meeting minutes (the span tree) from start to finish. A trace is a record that lists, as pieces called spans, "this work started and ended at such and such a time". As agents multiply, the pieces become dozens or hundreds, and what you actually want to know are questions like these.

  • Did this agent receive its work by a handoff, or was it called like a tool (as tool)?
  • Is the same delegation being repeated?
  • Where did work happen at the same time?
  • How many tokens did each agent use?

It suits you if:

  • You build multi-agent apps with Pydantic AI or the OpenAI Agents SDK (+ OpenInference instrumentation) and want to see why a run behaves oddly
  • You want to explain a single run to a colleague or paste it into a PR
  • You want to check per-agent tokens in CI (--format json)

Quick start

Installation

Until it is published to PyPI, install from GitHub.

curl -LsSf https://astral.sh/uv/install.sh | sh      # if you do not have uv (macOS: brew install uv)
uv tool install git+https://github.com/LeeGyeongPil/handoffmap
# after it is on PyPI: pipx install handoffmap

Run

Run it right away with the built-in sample (no file, key or network needed).

handoffmap --sample pydantic-ai
## Agent flow: trace 4dc50229 (otel-genai, 11 spans)

```mermaid
sequenceDiagram
    participant a1 as orchestrator
    participant a2 as researcher
    participant a3 as writer
    Note over a1: start
    par concurrent
        a1->>a2: as_tool via ask_researcher (55.0 ms)
        a2->>a2: tool search (51.8 ms)
    and
        a1->>a3: as_tool via ask_writer (1.5 ms)
    end
```

### Agents

| agent | runs | LLM calls | tools | input tokens | output tokens | time |
|---|---:|---:|---:|---:|---:|---:|
| orchestrator | 1 | 2 | 2 | 106 | 21 | 67.8 ms |
| researcher | 1 | 2 | 1 | 105 | 11 | 55.0 ms |
| writer | 1 | 1 | 0 | 51 | 1 | 1.5 ms |
| **total** | 3 | 5 | 3 | 262 | 33 | 124.3 ms |

_Tokens are summed from LLM spans only. `time` is the wall time of each run, including work it delegated. `–` means the trace does not contain the value._

_Sample trace: recorded from practice (mock) models, so token counts and timings are made up._

If you paste the ```mermaid block of the output above into a place like GitHub, it is drawn as a diagram. How to read these lines is in "How to read it" below.

This sample was made with practice (mock) models. The token counts and times are mock values. See "About the sample traces" for details.

Making your own trace file

handoffmap reads an OTLP JSON file (the JSON form of ExportTraceServiceRequest) or a JSONL with one request per line.

  1. If you use the OpenTelemetry Collector: it reads the JSONL written by the file exporter as it is.
  2. If it is a Python app: the Python SDK has no OTLP JSON file exporter (related PR #4996, checked 2026-11-11). So a short example is provided that collects spans in memory and encodes them itself: examples/save_otlp_json.py. Just copy the marked part into your app.
  3. If you want to try generating a trace: there is an example that builds one with mock models and no keys. The required packages are pinned inside the script, so uv run installs them for you (there is a lot to download, so the first run may be slow).
uv run examples/make_pydantic_trace.py trace.json
handoffmap trace.json

It can also read traces made with real models (OpenAI and others), but that needs keys, fees and response time, so it is optional. All the examples in this repository use mock models.

How to read it

Read a line of the Mermaid sequence diagram through three kinds of arrows and the par block.

What you see Meaning Control flow
a1->>a2: as_tool via ask_researcher a1 called a2 through the tool ask_researcher The result returns to the caller
a1->>a2: call Another agent is run directly inside an agent, without a tool The result returns to the caller
a1-)a2: handoff a1 handed off to a2 (an open arrow) It does not return
par concurrent … and … end A group of activities that overlap in time Run at the same time
a2->>a2: tool search The agent calls an ordinary tool (can be hidden with --no-tools)

The difference between handoff and as_tool is visible at a glance in the OpenInference sample.

handoffmap --sample openinference --format mermaid
sequenceDiagram
    participant a1 as triage
    participant a2 as billing
    participant a3 as summarizer
    Note over a1: start
    a1-)a2: handoff (4.5 ms)
    par concurrent
        a2->>a2: tool lookup (1.2 ms)
    and
        a2->>a3: as_tool via summarize (1.0 ms)
    end

Sequence diagram output where triage hands off to billing and billing calls summarizer as a tool triage -) billing is a handoff that does not return, and billing ->> summarizer is an as_tool that returns.

Seen as a span tree (Agent workflow is an unnamed wrapper span), the same trace is 17 lines like this. billing appears only as a sibling of triage, so it is hard to notice that it is a handoff.

Agent workflow
  Agent workflow
    triage
      turn
        generation
        handoff to billing
    billing
      turn
        generation
        lookup
        summarize
          Agent workflow
            summarizer
              turn
                generation
      turn
        generation

The table columns are as follows.

Column Meaning
runs How many times that agent ran (each run is counted separately even under the same name)
LLM calls Number of LLM spans under that agent
tools Number of ordinary tool calls (handoff marker tools are excluded)
input / output tokens Tokens summed from LLM spans only. – if the trace has no value
time The wall-clock time of that run (including delegated work)
handoffmap --sample pydantic-ai --format table

Per-agent table of LLM calls, tools, tokens and time Total row: 262 input and 33 output tokens.

Usage

handoffmap [FILE | --sample NAME] [--format md|mermaid|table|json] [--explain]
           [--trace TRACE_ID] [--max-parallel N] [--repeat-threshold N] [--no-tools] [-o OUT]
           [--lang en|ko]
Option What it does Example
FILE An OTLP JSON or JSONL file handoffmap run.json
--sample NAME A built-in practice trace (pydantic-ai, pydantic-ai-v2, pydantic-ai-v6, openinference) handoffmap --sample openinference
--format, -f Output format: md (default), mermaid, table, json handoffmap run.json -f json
--explain The detected convention, the grounds for each edge judgment, and the ignored wrappers handoffmap run.json --explain
--trace ID Only one trace from a file with several mixed (the full ID or a non-ambiguous prefix) --trace 4dc5
--max-parallel N A wide-parallel warning if one parallel group has more than N simultaneous activities (default 8) --max-parallel 1
--repeat-threshold N A repeated-delegation warning if the same delegation happens N times (default 3) --repeat-threshold 2
--no-tools Hides ordinary tool-call lines --no-tools
-o, --output OUT Save to a file -o flow.md
--lang LANG Output language: en or ko. Applies to help, errors, and the md, table and --explain text (see "Output language") --lang ko
--version Show the version

Exit codes: 0 normal / 1 no agent spans / 2 input error (not OTLP, or file missing).

$ handoffmap not-otlp.json --lang en
handoffmap: not an OTLP trace: expected a JSON object with a 'resourceSpans' list
$ echo $?
2

Output language

The help text, error messages, and the md, table and --explain text come in English and Korean. The language is chosen in this order, and the first one set wins: --lang en|ko > the HANDOFFMAP_LANG environment variable > LC_ALL > LC_MESSAGES > LANG. A value that starts with ko (for example ko_KR.UTF-8) means Korean; anything else, or nothing set, means English.

handoffmap --sample pydantic-ai --lang ko        # one run in Korean
HANDOFFMAP_LANG=ko handoffmap --help             # help text in Korean
LANG=fr_FR.UTF-8 handoffmap --help               # not Korean, so English

Machine-readable output does not change with the language: --format json and --format mermaid are byte-identical for en and ko (warning message fields in the JSON stay English), and so are the exit codes. The Python API (render_markdown, render_table, render_explain) defaults to lang="en" and never reads the environment; pass lang="ko" to get Korean text.

The screenshots of the table, --explain and warning output below are in English; README.ko.md shows the same screens in Korean.

Scenario 1 - Paste into a PR

handoffmap run.json > flow.md

If you paste the contents of flow.md into the PR description, the Mermaid block is drawn as a diagram and the table appears with it.

Scenario 2 - Check the grounds

handoffmap --sample openinference --explain
trace: c9c642518c7203aee90e7f8c52f974ad
convention: openinference
size: 17 spans, 3 agent runs, 3 agents
agents: triage, billing, summarizer
edges:
  (none) -> triage: root  [no agent above it and no handoff source: it started the run]
  triage -> billing: handoff  [no agent ancestor; the span is a sibling and names its predecessor (graph.node.parent_id)]
  billing -> summarizer: as_tool via summarize  [a tool span sits between the caller and this agent (agent used as a tool)]
ignored wrappers (AGENT span without agent.name, not counted as agents): 'Agent workflow' x1
tokens: none of the LLM spans carry token counts

(The normal report follows this.) You can see the detected convention, the number of spans accepted as agents, and the ignored wrappers. This sample has empty token values, so the token cells of the table are –.

--explain output The first part of the --explain output.

Scenario 3 - Repeated-delegation warning

handoffmap tests/fixtures/synthetic_loop.otlp.json

Output where planner delegates to coder the same way 3 times and a repeated-delegation warning appears A synthetic trace made by hand (not measured). The same delegation repeated 3 times, so a warning was attached, and coder's runs is 3.

### Warnings

- **repeated-delegation**: planner -> coder happened 3 times (threshold 3); check for a loop or a missing stop condition

Scenario 4 - Check tokens in CI

handoffmap --sample pydantic-ai --format json

The JSON contains trace_id, convention, span_count, agents, totals, edges, parallel and warnings. An agents entry has name, runs, llm_calls, tool_calls, input_tokens, output_tokens, cost and duration_ms. You can filter it like jq '.agents[] | {name, input_tokens}' (jq is installed separately).

Python API

import handoffmap

trace = handoffmap.load("src/handoffmap/samples/pydantic_ai_v5.otlp.json")[0]
flow = handoffmap.analyze(trace)
for e in flow.edges:
    print(e.caller, "->", e.callee, e.kind, e.via)
print(handoffmap.render_table(flow))
None -> orchestrator root None
orchestrator -> researcher as_tool ask_researcher
orchestrator -> writer as_tool ask_writer
| agent | runs | LLM calls | tools | input tokens | output tokens | time |
|---|---:|---:|---:|---:|---:|---:|
| orchestrator | 1 | 2 | 2 | 106 | 21 | 67.8 ms |
| researcher | 1 | 2 | 1 | 105 | 11 | 55.0 ms |
| writer | 1 | 1 | 0 | 51 | 1 | 1.5 ms |
| **total** | 3 | 5 | 3 | 262 | 33 | 124.3 ms |

Installation: to use it as a library, add it to your project with uv add git+https://github.com/LeeGyeongPil/handoffmap (or pip install git+https://github.com/LeeGyeongPil/handoffmap). uv tool install is an isolated environment, so import handoffmap does not work there. The sample path in the example above (src/handoffmap/samples/...) is correct only when run from the root of a cloned repository.

Public names: load, parse, analyze, render_mermaid, render_table, render_markdown, render_explain, to_dict, the exception HandoffmapError (NotOtlpError, NoAgentSpansError) and the data types (Trace, Flow, Edge, etc.). The same code is in examples/api_demo.py (run uv run python examples/api_demo.py from the repository root).

Message contents (prompt and response bodies such as gen_ai.input.messages) are never included in any output format.

Configuration

There are no configuration files or API keys. The tool only reads files and does not use the network. The only things you can adjust are the options above (--max-parallel, --repeat-threshold, --lang) and one optional environment variable, HANDOFFMAP_LANG (en or ko), which sets the output language when --lang is not given (see "Output language").

How it decides

flowchart LR
  F[OTLP JSON / JSONL] --> L[otlp.py]
  S[--sample] --> L
  L --> D{"Detect convention"}
  D -->|gen_ai.operation.name| G[OTel GenAI]
  D -->|openinference.span.kind| O[OpenInference]
  G --> N[normalize.py]
  O --> N
  N --> P["Parallel groups"]
  N --> U["Token totals"]
  N --> C["Warning rules"]
  P --> R[md / mermaid / table / json]
  U --> R
  C --> R
  1. Reading: IDs are accepted as both hex and base64, and span kinds as both integers and SPAN_KIND_* names. If several traces are mixed, they are split per trace.
  2. Convention detection: it decides by attributes, not by span name. This is because the convention is still at the Development stage, so span names differ by framework and version (Pydantic AI instrumentation v2 uses agent run, v5 and v6 use invoke_agent name). For OTel GenAI it looks at gen_ai.operation.name (invoke_agent, execute_tool, chat, etc.), and for OpenInference at openinference.span.kind (AGENT, TOOL, LLM) and agent.name. An AGENT span with no name (a wrapper) is not counted as an agent.
  3. Edge kind decided by ancestor search: from an agent run, it walks up the parent chain.
    • If it meets a tool span while climbing, it is as_tool; if it reaches an agent ancestor without meeting one, it is call.
    • If there is no agent ancestor and graph.node.parent_id exists, it is a handoff (sibling span).
    • If neither, it is root.
    • If the chain is broken because a parent span was not exported, it looks instead by time containment.
  4. Parallel detection: parallelism is not visible in the tree, so it is found by time. If the time intervals of activities under the same agent run (sub-agents and ordinary tools) overlap, they form one group. If an end time equals a start time, it is not an overlap.
  5. Tokens are summed from LLM spans only: agent spans can also carry total attributes (gen_ai.usage.*, gen_ai.aggregated_usage.*), but adding them would count sub-calls twice (double counting) or drop the sub-calls. Only the smallest unit, the LLM call, is added once and attributed to the nearest agent run. That is why the sample gives 262/33. The total attributes are used only as cross-check values in --explain.
  6. Warnings: repeated-delegation if the same caller→target delegation happens N or more times, and wide-parallel if the simultaneous activities of one group exceed the limit.

Supported convention snapshot

Conventions can change, so the reference date is given (checked 2026-11-11).

Target Reference
OTel GenAI semantic conventions The semantic-conventions-genai repository, Development status
OpenInference semantic conventions spec, 0.1.43
Versions the samples were made with pydantic-ai-slim 2.67.0, openai-agents 0.24.0, openinference-instrumentation-openai-agents 2.7.1
Pydantic AI instrumentation version Span names handoffmap result
v2 agent run, running tool Same structure (time values differ)
v5 invoke_agent name, execute_tool name Reference
v6 Same as v5 (only retry-message handling differs) Same structure (time values differ)

About the sample traces

The 4 built-in samples are traces made with practice mock models. They are real spans produced by real framework instrumentation, but the model responses are predetermined, so the token counts and times are mock values. How they differ from traces made with real models: tokens and times are real values (OpenInference's llm.token_count.* could not be confirmed through a real-model path), and response times take longer.

To recreate them (the script fetches and installs the required packages by itself; the first run may be slow):

uv run examples/make_pydantic_trace.py trace.json
uv run examples/make_openai_agents_trace.py trace.json

The sample sources and the versions used to make them are in src/handoffmap/samples/SOURCES.md.

Comparison with existing tools (when to use it)

  • Use it when: you want to take one file and make Markdown/Mermaid to paste into a PR or issue, you want to see things folded by agent (kind of delegation, parallelism, tokens), or you want to run it in CI without a server.
  • Use another tool when: for a dashboard that continuously monitors a running service → Langfuse, Arize Phoenix. To explore the whole span tree in a web UI → agent-prism, otel-desktop-viewer, otel-tui. For what each tool supports, check its own documentation.

Limits and roadmap

  • Input is only OTLP JSON/JSONL (not gRPC or protobuf). Prompt and response contents are not shown.
  • Cost is shown only when the trace has llm.cost.total (– otherwise). There is no model price table yet.
  • OpenInference's handoff detection relies on graph.node.parent_id, so with other instrumentation it may appear as root (check the grounds with --explain).
  • The Mermaid output's syntax structure (participant aliases, par/end balance, special-character escaping) is verified by tests, and the built-in sample outputs passed syntax validation with the mermaid 11 parser (11.17.2). Please check the actual diagram rendering once on GitHub.
  • Very deep nesting (about 500 or more levels of agents) fails in md/mermaid drawing with the recursion limit (RecursionError). In that case use --format table or json.
  • The time in the total row simply sums each run's time, so overlapping delegated sub-work can make it larger than the real wall clock (it does not affect the token and call-count totals). The same goes for totals.duration_ms in the JSON.
  • If a file with several traces is output with --format table/mermaid, they are printed one after another without a trace-separating header. Use the md format, or pick one with --trace.
  • The in-memory exporter in examples/save_otlp_json.py keeps accumulating spans, so it is not suited to long-running apps.
  • With very large traces (thousands of spans), the diagram gets long. You can shorten it with --no-tools.
  • Plans: a single-HTML lane diagram with no external resources, coding-agent CLI trace support, a model price table and a local OTLP receiver and file exporter. No schedule is set.

Common problems

Symptom Cause Fix
not an OTLP trace (exit code 2) Not an OTLP JSON that has resourceSpans Use the Collector file exporter output or a file saved with examples/save_otlp_json.py
no agent spans found (exit code 1) The trace has no agent spans, or the convention attributes are missing Check the detection result with --explain, and check that the instrumentation emits gen_ai.operation.name or openinference.span.kind
The token cells are – The LLM spans have no token attributes Check whether the instrumentation emits tokens (the openinference sample is this case)
An agent name does not show Unnamed wrapper spans are not counted Check "ignored wrappers" in --explain
file not found A path error Check the path

Development and tests

git clone https://github.com/LeeGyeongPil/handoffmap && cd handoffmap
uv sync
uv run pytest -q

150 tests run with no keys or network, using only the built-in samples and synthetic fixtures (tests/fixtures/README.md distinguishes measured from synthetic). Please leave bugs and suggestions as issues. The change log is CHANGELOG.md.

Learn more

License and sources

MIT. From the OpenTelemetry and OpenInference conventions it references (Apache-2.0), only attribute names are used. The built-in samples are data made by this project's scripts.

Metadata

Release files for handoffmap 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for handoffmap 0.2.2
File Size Uploaded Provenance Actions
handoffmap-0.2.2.tar.gz 47.7 kB Without provenance Details for handoffmap-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for handoffmap 0.2.2
File Interpreter ABI Platform Actions
handoffmap-0.2.2-py3-none-any.whl Python 3 none any Details for handoffmap-0.2.2-py3-none-any.whl

Total release size: 96.6 kB

Release files / handoffmap-0.2.2.tar.gz

Download URL handoffmap-0.2.2.tar.gz
Size 47.7 kB
Tags Source
SHA-256 checksum
How to use checksums
eaa03af7f2c1ebbb26e10bf9aa664a8ea2fc8d9d8e5233bf8055ff98e83f1ace
BLAKE2b-256 checksum
How to use checksums
5996e7eabc7b1164c303c9b13bbce5ea671489a9e337b9ceeada9464b9047e4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","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}

Release files / handoffmap-0.2.2-py3-none-any.whl

Download URL handoffmap-0.2.2-py3-none-any.whl
Size 48.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d711baae8eeb2d119302e3b4ae7bb292c81179e95ad79ca6236771d035026938
BLAKE2b-256 checksum
How to use checksums
54bfd491acb4b133d2c29b0c9bd00a64ff8514556078f862af9287436e31f30b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","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}

Security for handoffmap 0.2.2

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

0.2.2 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