Repository navigation
feat: draw agent workflows in the terminal and export them as Mermaid - #179
Merged
Merged
Conversation
`elevenlabs agents workflow diagram <agent>` draws an agent's workflow as box-drawing text, with each edge condition as a numbered key and a legend underneath. `elevenlabs agents workflow export <agent> [--markdown]` prints the same workflow as Mermaid source for docs and PR comments. Both take a config path, agent ID or name, or --all, and read local files only. Closes #170 (the GitHub Action is left for a follow-up). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PaulAsjes
marked this pull request as ready for review
October 27, 2026 10:56
…nal diagram mmdflux ends a round `( )` node at the first `)`, even inside the quoted label, so "Confirm (booking)" failed to draw. In the terminal, a round node's brackets are now same-width lookalikes; export is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
The mermaid chart can be easily panned / zoomed, so I'm curious as to how useful the ASCII / terminal variant would be with a large workflow 🤔 Also - not against, it won't hurt. The word "export" in Would it make sense to overload the "diagram" command and have an option to render it in one of three formats:
And then render to stdout by default and optionally to an |
Steps back end in a stub named in the legend, endings that several paths lead to are drawn once per path, and a fan-out that still tangles is widened or reordered. Long IDs are shortened when the drawing is wider than the terminal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One command for every rendering: --format ascii (the default, drawn in the terminal), mermaid, or mermaid-md (in a ```mermaid fence). "export" suggested a matching import, and the outputs only differ in format. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
@kraenhansen good shouts, we now overload |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Agent workflows are stored as raw node and edge JSON, which is hard to read and harder to review in a diff. A new local-only command,
agents workflow diagram, turns a workflow into a flowchart. By default it draws it in the terminal;--format mermaidprints Mermaid source to save, and--format mermaid-mdwraps it in a fence to paste into docs and PR comments, where GitHub renders it. It needs no API key or network access. Closes #170, apart from the GitHub Action, which is left for a follow-up.Example
A small workflow: an LLM condition leads to a tool, whose result branches to an apology or the end.
elevenlabs agents workflow diagram agent_configs/order-lookup.jsondraws it in the terminal. Each condition is a numbered key on its edge, written out in full underneath:elevenlabs agents workflow diagram agent_configs/order-lookup.json --format mermaidprints Mermaid source (--format mermaid-mdadds a```mermaidfence):which GitHub renders as:
flowchart TD n_apologize("Say · Apologize") n_done(["End (success)"]) n_lookup[["Tool · tool_lookup_order"]] n_start_node(["Start"]) n_lookup -->|"failure"| n_apologize n_lookup -->|"success"| n_done n_start_node -->|"The caller has given an order number"| n_lookup classDef t_start fill:#d1fae5,stroke:#059669,color:#064e3b class n_start_node t_start classDef t_end fill:#fee2e2,stroke:#dc2626,color:#7f1d1d class n_done t_end classDef t_say fill:#e0f2fe,stroke:#0284c7,color:#0c4a6e class n_apologize t_say classDef t_tool fill:#fef3c7,stroke:#d97706,color:#78350f class n_lookup t_toolDetails
diagramtakes a config file path, or an agent ID or name fromagents.json, or--all, which covers every agent and registered branch.--formatisascii(the default; box-drawing characters, so not strictly ASCII),mermaidormermaid-md. This started as a separateexportcommand; it was folded into--formatafter review, since "export" suggested a matching import. Agent lookup reuses the ID-then-name resolution fromagents test, moved into a sharedfind_agentwith no change in behaviour.serde_json::Valuerather than the generated types, so unknown node or condition types render generically instead of failing to deserialize. Each node type gets its own shape and colour. Edges show their condition's label, the LLM condition text,success/failure, orexpression. Backward conditions are drawn as dotted reverse arrows.<b>can't break the diagram. Node IDs are made Mermaid-safe: they are prefixed, which also keepsendfrom clashing with the Mermaid keyword, and colliding IDs get a suffix. An edge pointing at a node that doesn't exist is drawn as amissing:box rather than dropped.mmdflux2.6.1 (MIT, pure Rust,default-features = false). It pulls inpest,psm/stackerand two small Unicode crates, all MIT or MIT/Apache. No existing crate changes version; theCargo.lockdiff also qualifies existingsynreferences, becausepestbrings insyn3. I also trialledmermaid-text0.57.0. It printed entity escapes and quotes literally, so it was rejected.#quot;entities, so labels use plain lookalike characters instead.A --- k_1(["1"]) --> B), which the layout has to keep on that edge's path.6 ↩), and the legend names where it goes (Changes topic (back to 'Ask for the order number')). Drawn in full, back-edges ran up past everything in between.┼,├,┬, ...) and stops at none.COLUMNS), long IDs are shortened (tool_01j…sfb67); if it still doesn't fit, a note on stderr points at--format mermaid. This addsterminal_size0.4 (MIT/Apache).NO_COLORis unset. It comes from the sameclassDefcolours the Mermaid output uses.agent_configs/. It needs a released CLI that includes--format mermaid.Testing
cargo test: all suites pass, including 25 unit tests indiagram.rsand 9 integration tests intests/workflow_diagram_test.rs. The integration tests run the binary with no API key set.#, anendnode ID, a missing node) and the README example. All parsed, and a deliberately broken diagram was rejected.cargo clippy --all-targets: no new warnings.🤖 Generated with Claude Code