Visualizing Workflow Graphs: Exporting Topologies to Mermaid and Graphviz
Inspect ADK workflow graphs in the developer Web UI and Visual Builder, then generate Mermaid flowcharts and Graphviz DOT from your edge declarations for docs and code review.
Published on • December 2, 2026
AI Assistant

A Workflow(edges=[...]) declaration with eight nodes, two routers, and a fan-out/join is perfectly readable to Python — and completely opaque to the reviewer who has to approve it, the engineer onboarding next month, or the reader of your design doc. Worse, the diagram you drew on a whiteboard six weeks ago now lies about the code: a route was added, a branch was renamed, nobody updated the picture.
ADK gives you two complementary ways to see your graph: an interactive view inside the developer tooling, and — because your topology is just data — a straight shot to standard diagram formats like Mermaid and Graphviz that live next to your code and can be regenerated whenever the edges change. This post covers both.
Prerequisites
- ADK 2.0 graph workflows (
Workflow, node objects, routed edges). Start with the graph workflows intro if not. - For the export section: plain Python 3.10+ and either a Mermaid renderer (GitHub, GitLab, MkDocs, Notion all render Mermaid natively) or Graphviz (
pip install graphviz, or the systemdotbinary).
1. Inspect the graph in the ADK developer Web UI
The fastest way to look at a graph is the built-in web interface:
adk web
The server prints its URL (default http://localhost:8000); open it in your browser. Beyond plain chat testing, the interface ships the pieces you need for topology work:
- Agent structure graph view — a visual panel of your agent’s structure. (The UI’s telemetry settings even list “clicking the agent structure graph view” as a tracked interaction, so you can find it in the top-level navigation.)
- Visual Builder (Python only) — a drag-and-drop workflow editor with an AI-powered assistant, for designing graphs visually rather than editing
edgesby hand. - Event history — every event generated during execution, which is how you verify which branches actually fired at runtime, not just which ones exist statically.
- State inspection — view and modify session state during development.
Useful flags:
| Option | Purpose | Default |
|---|---|---|
--port | Server port | 8000 |
--host | Bind address | 127.0.0.1 |
--reload / --no-reload | Auto-reload on code changes | true |
--session_service_uri | Custom session storage | Per-agent SQLite in .adk/ |
Two honest caveats:
- ADK Web is a development tool, not a production surface. The docs are explicit: do not deploy it.
- Resuming workflows from the Web UI is not currently supported — fine for inspection, but not for exercising your resume paths.
In Go, the graph panel is served by the REST API’s debug endpoints (the -include_debug_api flag on the api subcommand serves the trace and agent-structure endpoints the panels need) — keep that flag off in production.
2. Why export at all?
The Web UI shows you a graph at a moment. Docs need something different:
- Reviewable in a pull request. A Mermaid block in the PR diff shows exactly which edges changed.
- Rendered everywhere. GitHub/GitLab render
```mermaidnatively; Graphviz renders to SVG/PDF for print-quality docs. - Refreshable. Generated from source, the diagram cannot drift — as long as you regenerate it.
- Tool-independent. DOT and Mermaid are lingua franca; anyone can open them without ADK installed.
3. The trick: your edges are already data
ADK does not currently document a built-in “export topology” API — so don’t wait for one. The edges list you pass to Workflow(...) is the topology: a declarative structure of sequences, routed branch dicts, and join references. If you keep that declaration as a module-level constant instead of an inline literal, you can walk it to emit any diagram format you like.
Here is a complete, dependency-free exporter. It handles the three edge shapes ADK graphs use: START sequences, (source, {route: target}) dispatch dicts, and multi-row fan-out/join patterns.
# topology.py — single source of truth for the graph's edges
from google.adk import Workflow
# Keep the edge list as data; the Workflow just consumes it.
edges = [
("START", process_message, router),
(router, {
"BUG": handle_bug,
"SUPPORT": handle_support,
"LOGISTICS": handle_logistics,
DEFAULT_ROUTE: handle_unknown,
}),
(handle_bug, file_ticket),
(handle_support, file_ticket),
(handle_logistics, file_ticket),
(file_ticket, finalize),
]
triage_workflow = Workflow(name="triage_workflow", edges=edges)
# export_topology.py — turns an edges list into Mermaid or DOT
def _name(node) -> str:
"""Stable display name for a node-like value."""
return getattr(node, "name", None) or getattr(node, "__name__", None) or str(node)
def iter_edges(edge_rows):
"""Yield (source, target, label) triples from a Workflow edges list."""
for row in edge_rows:
source = row[0]
if source == "START":
# ("START", a, b, c) → sequential chain
chain = row[1:]
src = "START"
for tgt in chain:
yield src, _name(tgt), ""
src = _name(tgt)
continue
if isinstance(row[1], dict):
# (router, {"ROUTE": target, ...}) → one labeled edge per route
for route, target in row[1].items():
yield _name(source), _name(target), str(route)
continue
# (a, b) plain edge
yield _name(source), _name(row[1]), ""
def to_mermaid(edges) -> str:
lines = ["flowchart TD"]
for src, tgt, label in edges:
arrow = f"-- {label} -->" if label else "-->"
lines.append(f" {src} {arrow} {tgt}")
return "\n".join(lines)
def to_dot(edges, title="workflow") -> str:
lines = [f'digraph "{title}" {{', " rankdir=TB;", ' node [shape=box, style="rounded"];']
for src, tgt, label in edges:
if label:
lines.append(f' "{src}" -> "{tgt}" [label="{label}"];')
else:
lines.append(f' "{src}" -> "{tgt}";')
lines.append("}")
return "\n".join(lines)
Generate and drop the output straight into your docs:
exported = list(iter_edges(edges))
print(to_mermaid(exported))
which produces:
flowchart TD
START --> process_message
process_message --> router
router -- BUG --> handle_bug
router -- SUPPORT --> handle_support
router -- LOGISTICS --> handle_logistics
router -- DEFAULT_ROUTE --> handle_unknown
handle_bug --> file_ticket
handle_support --> file_ticket
handle_logistics --> file_ticket
file_ticket --> finalize
The DOT variant feeds straight into Graphviz:
python export_topology.py > workflow.dot
dot -Tsvg workflow.dot -o workflow.svg
A few notes on fidelity:
- Route labels are the interesting part. Always emit them — an unlabeled branch diagram hides exactly the decision logic you drew it to explain.
STARTis a real node in the diagram (a circle or a double-circle in Graphviz distinguishes it nicely:START [shape=ellipse]).- Fan-out rows (multiple
("START", ...)or(join_node, ...)rows) naturally produce several edges into one node — Mermaid and DOT both lay that out as a join without extra syntax. - If your exporter chokes on a node type (an
LlmAgenthas.name, a plain function has__name__, aWorkflowhas.name), extend_namerather than special-casing the graph — the point of the helper is that call sites never think about node types.
4. Keeping diagrams readable
A generated diagram of a 30-node graph is technically correct and practically useless. Practical rules:
- Cluster sub-processes. Nested workflows are natural Mermaid
subgraph/ Graphvizclusterboundaries — draw the parent graph with the child collapsed to one box, and give each child its own diagram. - Direction follows execution.
flowchart TD(top-down) for long sequences; switch toLRwhen the graph is wide and shallow (fan-out heavy). - One diagram per audience. Reviewers want every route label; a blog post or onboarding doc wants the five happy-path nodes. Generate both from the same edges with a label filter.
- Subgraph per branch. Group
BUG/SUPPORT/LOGISTICShandlers into subgraphs so the router’s fan-out reads as three lanes, not six scattered boxes. - Regenerate in CI. Add a check that the committed
.mmd/.dotmatches the exporter’s output — the same idea as a format check, applied to diagrams. A stale diagram is worse than none. - Prefer stable names. Node display names come from
.name/__name__; renaming a function silently changes diagram labels, so pin names explicitly on nodes you document (@node(name="file_ticket")).
5. A sanity-check loop
Use the visual views to verify what the static diagram only claims:
adk web, open the agent structure graph — confirm the static topology matches what you intended.- Run a message through a routed branch; check the event history to confirm the expected route value fired and the expected handler ran.
- Export the topology; diff it in the PR. If the code review shows a new edge, the reviewer sees the new arrow.
Static diagram + runtime event history together cover the two failure modes: “the graph is not what we think” and “the graph is right but the data took a different path.”
Checklist
-
edgeslives in one importable place, not inline in a constructor you can’t inspect. - Exporter emits route labels and
START. - Mermaid committed to docs renders on your platform (GitHub/MkDocs/Notion test link).
- DOT→SVG step works on a clean machine (
dot -Tsvg). - Sub-workflows are collapsed to single boxes at the top level.
- Diagram regeneration runs in CI (or at minimum, in your release script).
-
adk webis used for development only, never exposed.
Topology is the one part of a workflow that cannot be inferred from reading node bodies — which is exactly why it deserves to be drawn, generated, and diffed like code.