Skip to content

Commit 017da0b

Browse files
Add missing tool
Signed-off-by: Luis Valdes <[email protected]>
1 parent 8df85fe commit 017da0b

File tree

1 file changed

+37
-0
lines changed
  • typescript-sdk/integrations/langgraph/examples/python/agents/tool_based_generative_ui

1 file changed

+37
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,42 @@
1313
from langgraph.graph import MessagesState
1414
from langgraph.prebuilt import ToolNode
1515

16+
# This tool generates a haiku on the server.
17+
# The tool call will be streamed to the frontend as it is being generated.
18+
GENERATE_HAIKU_TOOL = {
19+
"type": "function",
20+
"function": {
21+
"name": "generate_haiku",
22+
"description": "Generate a haiku in Japanese and its English translation",
23+
"parameters": {
24+
"type": "object",
25+
"properties": {
26+
"japanese": {
27+
"type": "array",
28+
"items": {
29+
"type": "string"
30+
},
31+
"description": "An array of three lines of the haiku in Japanese"
32+
},
33+
"english": {
34+
"type": "array",
35+
"items": {
36+
"type": "string"
37+
},
38+
"description": "An array of three lines of the haiku in English"
39+
},
40+
"image_names": {
41+
"type": "array",
42+
"items": {
43+
"type": "string"
44+
},
45+
"description": "Names of 3 relevant images from the provided list"
46+
}
47+
},
48+
"required": ["japanese", "english", "image_names"]
49+
}
50+
}
51+
}
1652

1753
class AgentState(MessagesState):
1854
"""
@@ -37,6 +73,7 @@ async def chat_node(state: AgentState, config: RunnableConfig) -> Command[Litera
3773
model_with_tools = model.bind_tools(
3874
[
3975
*state.get("tools", []), # bind tools defined by ag-ui
76+
GENERATE_HAIKU_TOOL,
4077
],
4178
parallel_tool_calls=False,
4279
)

0 commit comments

Comments
 (0)