From b8e9f73e89f1f40a4592ed3f871b73570b9be686 Mon Sep 17 00:00:00 2001 From: goulustis Date: Thu, 29 Jan 2026 18:06:20 +0800 Subject: [PATCH] debugging --- lang_agent/graphs/react.py | 21 ++++++++++----------- lang_agent/graphs/routing.py | 27 +++++++++++++++------------ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lang_agent/graphs/react.py b/lang_agent/graphs/react.py index 439073e..d9a3a4d 100644 --- a/lang_agent/graphs/react.py +++ b/lang_agent/graphs/react.py @@ -146,16 +146,15 @@ if __name__ == "__main__": HumanMessage("use the calculator tool to calculate 92*55 and say the answer")] },{"configurable": {"thread_id": "3"}} - out = route.invoke(*nargs) - assert 0 + # out = route.invoke(*nargs) + # assert 0 - # for chunk, metadata in graph.stream({"inp": nargs}, stream_mode="messages"): - # node = metadata.get("langgraph_node") - # if node not in ("model"): - # print(node) - # continue # skip router or other intermediate nodes + # for mode, data in graph.stream(*nargs, stream_mode=["messages", "values"]): + # print(data) - # # Print only the final message content - # if isinstance(chunk, (BaseMessageChunk, BaseMessage)) and getattr(chunk, "content", None): - # print(chunk.content, end="", flush=True) - \ No newline at end of file + for _, mode, out in graph.stream(*nargs, subgraphs=True, + stream_mode=["messages", "values"]): + if mode == "values": + msgs = out.get("messages") + l = len(msgs) if msgs is not None else -1 + print(type(out), out.keys(), l) \ No newline at end of file diff --git a/lang_agent/graphs/routing.py b/lang_agent/graphs/routing.py index 9d7e158..dd6470a 100644 --- a/lang_agent/graphs/routing.py +++ b/lang_agent/graphs/routing.py @@ -206,8 +206,8 @@ if __name__ == "__main__": from lang_agent.graphs.tool_nodes import AnnotatedToolNode, ToolNodeConfig, ChattyToolNodeConfig load_dotenv() + route:RoutingGraph = RoutingConfig().setup() # route:RoutingGraph = RoutingConfig(tool_node_config=ChattyToolNodeConfig()).setup() - route:RoutingGraph = RoutingConfig(tool_node_config=ChattyToolNodeConfig()).setup() graph = route.workflow nargs = { @@ -215,16 +215,19 @@ if __name__ == "__main__": HumanMessage("use calculator to calculate 926*84")] },{"configurable": {"thread_id": "3"}} - for chunk in route.invoke(*nargs, as_stream=True): - # print(f"\033[92m{chunk}\033[0m", end="", flush=True) - continue + # for chunk in route.invoke(*nargs, as_stream=True): + # # print(f"\033[92m{chunk}\033[0m", end="", flush=True) + # continue - # for chunk, metadata in graph.stream({"inp": nargs}, stream_mode="messages"): - # node = metadata.get("langgraph_node") - # if node not in ("model"): - # continue # skip router or other intermediate nodes - - # # Print only the final message content - # if isinstance(chunk, (BaseMessageChunk, BaseMessage)) and getattr(chunk, "content", None): - # print(chunk.content, end="", flush=True) \ No newline at end of file + for _, mode, out in graph.stream({"inp": nargs}, + subgraphs=True, + stream_mode=["messages", "values"]): + # print(mode) + if mode == "values": + msgs = out.get("messages") + l = len(msgs) if msgs is not None else -1 + print(type(out), out.keys(), l) + else: + print(type(out), mode, "==================================================") + print(out[0].content)