11from typing import Any , Dict , List , Optional
22
3+ from agno .models .base import MessageData
34from agno .models .message import Message
45from agno .models .openai .responses import OpenAIResponses
56from agno .models .response import ModelResponse
6- from agno .models .base import MessageData
77
88
99class _FakeError :
@@ -47,7 +47,15 @@ def __init__(self, *, _id: str, call_id: Optional[str], name: str, arguments: st
4747
4848
4949class _FakeStreamEvent :
50- def __init__ (self , * , type : str , item : Optional [_FakeStreamItem ] = None , delta : str = "" , response : Any = None , annotation : Any = None ):
50+ def __init__ (
51+ self ,
52+ * ,
53+ type : str ,
54+ item : Optional [_FakeStreamItem ] = None ,
55+ delta : str = "" ,
56+ response : Any = None ,
57+ annotation : Any = None ,
58+ ):
5159 self .type = type
5260 self .item = item
5361 self .delta = delta
@@ -66,15 +74,22 @@ def test_format_messages_maps_tool_output_fc_to_call_id():
6674 "id" : "fc_abc123" ,
6775 "call_id" : "call_def456" ,
6876 "type" : "function" ,
69- "function" : {"name" : "execute_shell_command" , "arguments" : "{ \ " command\ " : \ " ls -la\" }" },
77+ "function" : {"name" : "execute_shell_command" , "arguments" : '{ "command": "ls -la"}' },
7078 }
7179 ],
7280 )
7381
7482 # Tool output referring to the fc_* id should be normalized to call_*
7583 tool_output = Message (role = "tool" , tool_call_id = "fc_abc123" , content = "ok" )
7684
77- fm = model ._format_messages (messages = [Message (role = "system" , content = "s" ), Message (role = "user" , content = "u" ), assistant_with_tool_call , tool_output ])
85+ fm = model ._format_messages (
86+ messages = [
87+ Message (role = "system" , content = "s" ),
88+ Message (role = "user" , content = "u" ),
89+ assistant_with_tool_call ,
90+ tool_output ,
91+ ]
92+ )
7893
7994 # Expect one function_call and one function_call_output normalized
8095 fc_items = [x for x in fm if x .get ("type" ) == "function_call" ]
@@ -114,7 +129,10 @@ def test_process_stream_response_builds_tool_calls():
114129 stream_data = MessageData ()
115130
116131 # Simulate function_call added and then completed
117- added = _FakeStreamEvent (type = "response.output_item.added" , item = _FakeStreamItem (_id = "fc_abc123" , call_id = "call_def456" , name = "execute" , arguments = "{}" ))
132+ added = _FakeStreamEvent (
133+ type = "response.output_item.added" ,
134+ item = _FakeStreamItem (_id = "fc_abc123" , call_id = "call_def456" , name = "execute" , arguments = "{}" ),
135+ )
118136 mr , tool_use = model ._process_stream_response (added , assistant_message , stream_data , {})
119137 assert mr is None
120138
@@ -155,9 +173,14 @@ def test_reasoning_previous_response_skips_prior_function_call_items(monkeypatch
155173 ],
156174 )
157175
158- fm = model ._format_messages (messages = [Message (role = "system" , content = "s" ), Message (role = "user" , content = "u" ), assistant_with_prev , assistant_with_tool_call ])
176+ fm = model ._format_messages (
177+ messages = [
178+ Message (role = "system" , content = "s" ),
179+ Message (role = "user" , content = "u" ),
180+ assistant_with_prev ,
181+ assistant_with_tool_call ,
182+ ]
183+ )
159184
160185 # Expect no re-sent function_call when previous_response_id is present for reasoning models
161186 assert all (x .get ("type" ) != "function_call" for x in fm )
162-
163-
0 commit comments