Skip to content

Commit 5f7815a

Browse files
committed
update example to use ToolNode
1 parent 61054a7 commit 5f7815a

File tree

2 files changed

+3467
-1
lines changed
  • typescript-sdk/integrations/langgraph/examples

2 files changed

+3467
-1
lines changed

typescript-sdk/integrations/langgraph/examples/agents/tool_based_generative_ui/agent.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from langgraph.graph import StateGraph, END, START
1111
from langgraph.types import Command
1212
from langgraph.graph import MessagesState
13-
from langgraph.checkpoint.memory import MemorySaver
13+
from langgraph.prebuilt import ToolNode
1414

1515
@tool
1616
def generate_haiku(
@@ -64,6 +64,13 @@ async def chat_node(state: AgentState, config: Optional[RunnableConfig] = None):
6464
*state["messages"],
6565
], config)
6666

67+
if response.tool_calls:
68+
return Command(
69+
goto="tool_node",
70+
update={
71+
"messages": state["messages"] + [response]
72+
}
73+
)
6774
# Return Command to end with updated messages
6875
return Command(
6976
goto=END,
@@ -77,11 +84,14 @@ async def chat_node(state: AgentState, config: Optional[RunnableConfig] = None):
7784

7885
# Add nodes
7986
workflow.add_node("chat_node", chat_node)
87+
workflow.add_node("tool_node", ToolNode([generate_haiku]))
8088

8189
# Add edges
8290
workflow.set_entry_point("chat_node")
8391
workflow.add_edge(START, "chat_node")
8492
workflow.add_edge("chat_node", END)
93+
workflow.add_edge("tool_node", END)
94+
8595

8696
# Compile the graph
8797
tool_based_generative_ui_graph = workflow.compile()

0 commit comments

Comments
 (0)