Skip to content

Commit fa1625d

Browse files
Weather Agent Sample: Only include tool_call_id to chatbot.append if it's set (#771)
Co-authored-by: Sydney Runkle <[email protected]>
1 parent 42c70c0 commit fa1625d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

examples/pydantic_ai_examples/weather_agent_gradio.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ async def stream_from_agent(prompt: str, chatbot: list[dict], past_messages: lis
3838
if hasattr(call.args, 'args_json')
3939
else json.dumps(call.args.args_dict)
4040
)
41+
metadata = {
42+
'title': f'🛠️ Using {TOOL_TO_DISPLAY_NAME[call.tool_name]}',
43+
}
44+
if call.tool_call_id is not None:
45+
metadata['id'] = {call.tool_call_id}
46+
4147
gr_message = {
4248
'role': 'assistant',
4349
'content': 'Parameters: ' + call_args,
44-
'metadata': {
45-
'title': f'🛠️ Using {TOOL_TO_DISPLAY_NAME[call.tool_name]}',
46-
'id': call.tool_call_id,
47-
},
50+
'metadata': metadata,
4851
}
4952
chatbot.append(gr_message)
5053
if isinstance(call, ToolReturnPart):

0 commit comments

Comments
 (0)