support graph showing

This commit is contained in:
2025-10-22 18:19:24 +08:00
parent a26e42fdf5
commit 21ca1be80c
2 changed files with 23 additions and 7 deletions

View File

@@ -3,6 +3,9 @@ from typing import Type, TypedDict, Literal, Dict, List, Tuple
import tyro
from pydantic import BaseModel, Field
from loguru import logger
from PIL import Image
from io import BytesIO
import matplotlib.pyplot as plt
from lang_agent.config import KeyConfig
from lang_agent.tool_manager import ToolManager, ToolManagerConfig
@@ -130,7 +133,9 @@ class RoutingGraph(GraphBase):
inp = {"messages":[
SystemMessage(
"You must use tool to complete the possible task"
),self._get_human_msg(state)
),
# self._get_human_msg(state)
*state["inp"][0][1:]
]}, state["inp"][1]
out = self.tool_model.invoke(*inp)
@@ -160,4 +165,9 @@ class RoutingGraph(GraphBase):
workflow = builder.compile()
return workflow
return workflow
def show_graph(self):
img = Image.open(BytesIO(self.workflow.get_graph().draw_mermaid_png()))
plt.imshow(img)
plt.show()