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 13
13
from langgraph .graph import MessagesState
14
14
from langgraph .prebuilt import ToolNode
15
15
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
+ }
16
52
17
53
class AgentState (MessagesState ):
18
54
"""
@@ -37,6 +73,7 @@ async def chat_node(state: AgentState, config: RunnableConfig) -> Command[Litera
37
73
model_with_tools = model .bind_tools (
38
74
[
39
75
* state .get ("tools" , []), # bind tools defined by ag-ui
76
+ GENERATE_HAIKU_TOOL ,
40
77
],
41
78
parallel_tool_calls = False ,
42
79
)
You can’t perform that action at this time.
0 commit comments