File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
typescript-sdk/integrations/langgraph/examples/python/agents/tool_based_generative_ui Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1313from langgraph .graph import MessagesState
1414from 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
1753class 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 )
You can’t perform that action at this time.
0 commit comments