Skip to content

Commit 203d7b7

Browse files
wyf7107copybara-github
authored andcommitted
chore: Add a new endpoint to fetch the base agent graph in DOT format
Co-authored-by: Yifan Wang <wanyif@google.com> PiperOrigin-RevId: 893730378
1 parent 064f0d2 commit 203d7b7

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/google/adk/cli/adk_web_server.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,37 @@ async def event_generator():
19061906
media_type="text/event-stream",
19071907
)
19081908

1909+
@app.get(
1910+
"/dev/{app_name}/graph",
1911+
response_model_exclude_none=True,
1912+
tags=[TAG_DEBUG],
1913+
)
1914+
async def get_app_graph_dot(
1915+
app_name: str, dark_mode: bool = False
1916+
) -> GetEventGraphResult | dict:
1917+
"""Returns the base agent graph in DOT format without any highlights.
1918+
1919+
This endpoint allows the frontend to fetch the graph structure once
1920+
and compute highlights client-side for better performance.
1921+
1922+
Args:
1923+
app_name: The name of the agent/app
1924+
dark_mode: Whether to use dark theme background color
1925+
"""
1926+
agent_or_app = self.agent_loader.load_agent(app_name)
1927+
root_agent = self._get_root_agent(agent_or_app)
1928+
1929+
# Get graph with NO highlights (empty list) and specified theme
1930+
dot_graph = await agent_graph.get_agent_graph(
1931+
root_agent, [], dark_mode=dark_mode
1932+
)
1933+
1934+
if dot_graph and isinstance(dot_graph, graphviz.Digraph):
1935+
return GetEventGraphResult(dot_src=dot_graph.source)
1936+
else:
1937+
return {}
1938+
1939+
# TODO: This endpoint can be removed once we update adk web to stop consuming it
19091940
@app.get(
19101941
"/apps/{app_name}/users/{user_id}/sessions/{session_id}/events/{event_id}/graph",
19111942
response_model_exclude_none=True,

src/google/adk/cli/agent_graph.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,12 @@ def draw_edge(from_name, to_name):
282282
draw_edge(agent.name, get_node_name(tool))
283283

284284

285-
async def get_agent_graph(root_agent, highlights_pairs, image=False):
285+
async def get_agent_graph(
286+
root_agent, highlights_pairs, image=False, dark_mode=True
287+
):
288+
bg_color = '#333537' if dark_mode else '#ffffff'
286289
graph = graphviz.Digraph(
287-
graph_attr={'rankdir': 'LR', 'bgcolor': '#333537'}, strict=True
290+
graph_attr={'rankdir': 'LR', 'bgcolor': bg_color}, strict=True
288291
)
289292
await build_graph(graph, root_agent, highlights_pairs)
290293
if image:

0 commit comments

Comments
 (0)