Skip to content

feat(cli): add adk graph command - #7466

Open
BichengWang wants to merge 1 commit into
google:mainfrom
BichengWang:feat/cli-graph-command
Open

BichengWang wants to merge 1 commit into
google:mainfrom
BichengWang:feat/cli-graph-command

Conversation

@BichengWang

Copy link
Copy Markdown
Contributor

Closes #3426

Problem

The agent graph is only available through the dev UI. There is no way to get it from the command line, for example to check the structure of a multi-agent setup in CI or paste it into a doc.

Change

New command adk graph AGENT, built on the existing agent_graph.get_agent_graph:

adk graph path/to/my_agent                       # DOT to stdout
adk graph path/to/my_agent --output agent.dot
adk graph path/to/my_agent --format svg --output agent.svg
adk graph path/to/my_agent --ascii-only          # no emoji in labels
  • --format is dot (default), png or svg. png and svg are rendered by Graphviz and need --output; if the dot executable is missing the command says so instead of printing a traceback.
  • --ascii-only removes the emoji prefix from node labels, so the DOT can be written on consoles that can't encode it. It only touches label="...", so non-ASCII agent names keep distinct nodes.
  • Loading uses AgentLoader the same way adk run does, and an App is unwrapped to its root agent.
  • Load, graph-build, render and file-write failures are reported as ClickExceptions.

The graph is built with the same default palette as the dev UI (dark background). Note that building it resolves the agent's tools, so toolsets such as MCP servers are contacted, as they are when the dev UI draws the graph.

Testing plan

New tests in tests/unittests/cli/utils/test_cli_tools_click.py:

  • DOT output to stdout
  • --ascii-only, including a case with two non-ASCII agent names
  • --output required for png/svg, --ascii-only rejected for png/svg
  • image rendering writes the file (Graphviz mocked)
  • missing Graphviz and unwritable output paths

pytest tests/unittests/cli/utils/test_cli_tools_click.py tests/unittests/cli/test_cli_tools_click_option_mismatch.py gives 143 passed, 1 xfailed. pyink and isort are clean. I also ran the command by hand on a small agent with a sub-agent and a tool (DOT output and --ascii-only); I didn't have Graphviz installed, so the png/svg path is covered by the mocked tests only.

Renders an agent's structure with the existing agent_graph builder, so the
tree can be inspected without starting the dev UI. Prints DOT by default and
can write DOT, PNG or SVG to a file (PNG and SVG need Graphviz). --ascii-only
drops the emoji label prefix for consoles that cannot encode it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add adk graph command and --ascii-only for DOT output

2 participants