Skip to content

Commit a808639

Browse files
committed
send tool result
1 parent 5f7815a commit a808639

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

typescript-sdk/integrations/server-starter-all-features/server/python/example_server/tool_based_generative_ui.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ async def event_generator():
3838
if input_data.messages and len(input_data.messages) > 0:
3939
last_message = input_data.messages[-1]
4040

41+
result_message = None
42+
4143
# Determine what type of message to send
42-
if last_message and getattr(last_message, 'role', None) == "tool":
44+
if last_message and getattr(last_message, 'content', None) == "thanks":
4345
# Send text message for tool result
4446
message_id = str(uuid.uuid4())
4547
new_message = {
@@ -51,7 +53,7 @@ async def event_generator():
5153
# Send tool call message
5254
tool_call_id = str(uuid.uuid4())
5355
message_id = str(uuid.uuid4())
54-
56+
5557
# Prepare haiku arguments
5658
haiku_args = {
5759
"japanese": ["エーアイの", "橋つなぐ道", "コパキット"],
@@ -78,9 +80,19 @@ async def event_generator():
7880
]
7981
}
8082

83+
result_message = {
84+
"id": str(uuid.uuid4()),
85+
"role": "tool",
86+
"tool_call_id": tool_call_id,
87+
"content": "Haiku created"
88+
}
89+
8190
# Create messages list with input messages plus the new message
8291
all_messages = list(input_data.messages) + [new_message]
8392

93+
if result_message:
94+
all_messages.append(result_message)
95+
8496
# Send messages snapshot event
8597
yield encoder.encode(
8698
MessagesSnapshotEvent(

0 commit comments

Comments
 (0)