Skip to content

Commit 6507868

Browse files
committed
add graph png generator script
1 parent 478e3cd commit 6507868

File tree

5 files changed

+70
-20
lines changed

5 files changed

+70
-20
lines changed

docs/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ uv run python -m template_langgraph.tasks.run_kabuto_helpdesk_agent "KABUTOの
2626
uv run python -m template_langgraph.tasks.run_kabuto_helpdesk_agent "KABUTOのマニュアルから禅モードに関する情報を教えて下さい"
2727

2828
# ChatWithToolsAgent
29-
uv run python -m template_langgraph.tasks.draw_chat_with_tools_agent_mermaid_png "data/chat_with_tools_agent.png"
3029
uv run python -m template_langgraph.tasks.run_chat_with_tools_agent
3130
# KABUTOの起動時に、画面全体が紫色に点滅し、システムがフリーズします。KABUTO のマニュアルから、関連する情報を取得したり過去のシステムのトラブルシュート事例が蓄積されたデータベースから、関連する情報を取得して質問に答えてください
3231
# 天狗のいたずら という現象について KABUTO のマニュアルから、関連する情報を取得したり過去のシステムのトラブルシュート事例が蓄積されたデータベースから、関連する情報を取得して質問に答えてください
@@ -35,6 +34,11 @@ uv run python -m template_langgraph.tasks.run_chat_with_tools_agent
3534
uv run python -m template_langgraph.tasks.run_issue_formatter_agent
3635
# KABUTOにログインできない!パスワードは合ってるはずなのに…若手社員である山田太郎は、Windows 11 を立ち上げ、日課のように自社の業務システムKABUTOのログイン画面を開きます。しかし、そこには、意味をなさない「虚無」という文字だけがただひっそりと表示されていたのです。これは質問でもあり不具合の報告でもあります。岡本太郎さんに本件調査依頼します。
3736

37+
# Draw mermaid diagram for Agents
38+
AGENT_NAME=chat_with_tools_agent
39+
uv run python scripts/draw_mermaid_png.py \
40+
--name $AGENT_NAME \
41+
--output data/$AGENT_NAME.png
3842
```
3943

4044
## References

scripts/draw_mermaid_png.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import logging
2+
3+
import typer
4+
from dotenv import load_dotenv
5+
6+
from template_langgraph.loggers import get_logger
7+
8+
# Initialize the Typer application
9+
app = typer.Typer(
10+
add_completion=False,
11+
help="template-langgraph CLI",
12+
)
13+
14+
# Set up logging
15+
logger = get_logger(__name__)
16+
17+
18+
@app.command()
19+
def png(
20+
name: str = typer.Option(
21+
"chat_with_tools_agent",
22+
"--name",
23+
"-n",
24+
help="Name of the agent to draw",
25+
),
26+
output_file_path: str = typer.Option(
27+
"output.png",
28+
"--output",
29+
"-o",
30+
help="Path to the output PNG file",
31+
),
32+
verbose: bool = typer.Option(
33+
False,
34+
"--verbose",
35+
"-v",
36+
help="Enable verbose output",
37+
),
38+
):
39+
# Set up logging
40+
if verbose:
41+
logger.setLevel(logging.DEBUG)
42+
43+
logger.debug(f"This is a debug message with name: {name}")
44+
if name == "chat_with_tools_agent":
45+
from template_langgraph.agents.chat_with_tools_agent.agent import graph
46+
if name == "issue_formatter_agent":
47+
from template_langgraph.agents.issue_formatter_agent.agent import graph
48+
if name == "task_decomposer_agent":
49+
from template_langgraph.agents.task_decomposer_agent.agent import graph
50+
if name == "kabuto_helpdesk_agent":
51+
from template_langgraph.agents.kabuto_helpdesk_agent import graph
52+
53+
typer.echo(f"Drawing agent: {name}")
54+
graph.get_graph().draw_mermaid_png(
55+
output_file_path=output_file_path,
56+
)
57+
typer.echo(f"Graph saved to {output_file_path}")
58+
59+
60+
if __name__ == "__main__":
61+
load_dotenv(
62+
override=True,
63+
verbose=True,
64+
)
65+
app()

template_langgraph/agents/issue_formatter_agent/agent.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,5 @@ def analyze(self, state: AgentState) -> AgentState:
3737
state["issue"] = issue
3838
return state
3939

40-
def draw_mermaid_png(self) -> bytes:
41-
"""Draw the graph in Mermaid format."""
42-
return self.create_graph().get_graph().draw_mermaid_png()
43-
4440

4541
graph = IssueFormatterAgent().create_graph()

template_langgraph/agents/task_decomposer_agent/agent.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,5 @@ def route_human_feedback(
7474
logger.info("Looping back to chat for further processing.")
7575
return "loopback"
7676

77-
def draw_mermaid_png(self) -> bytes:
78-
"""Draw the graph in Mermaid format."""
79-
return self.create_graph().get_graph().draw_mermaid_png()
80-
8177

8278
graph = TaskDecomposerAgent().create_graph()

template_langgraph/tasks/draw_chat_with_tools_agent_mermaid_png.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)