@@ -135,3 +135,76 @@ def __init__(self):
135135 )
136136
137137 assert called_kwargs ["tools" ] is omit
138+
139+
140+ @pytest .mark .allow_call_model_methods
141+ @pytest .mark .asyncio
142+ async def test_prompt_id_omits_tool_choice_when_no_tools_configured ():
143+ called_kwargs : dict [str , Any ] = {}
144+
145+ class DummyResponses :
146+ async def create (self , ** kwargs ):
147+ nonlocal called_kwargs
148+ called_kwargs = kwargs
149+ return get_response_obj ([])
150+
151+ class DummyResponsesClient :
152+ def __init__ (self ):
153+ self .responses = DummyResponses ()
154+
155+ model = OpenAIResponsesModel (
156+ model = "gpt-4" ,
157+ openai_client = DummyResponsesClient (), # type: ignore[arg-type]
158+ model_is_explicit = False ,
159+ )
160+
161+ await model .get_response (
162+ system_instructions = None ,
163+ input = "hi" ,
164+ model_settings = ModelSettings (tool_choice = "web_search_preview" ),
165+ tools = [],
166+ output_schema = None ,
167+ handoffs = [],
168+ tracing = ModelTracing .DISABLED ,
169+ prompt = {"id" : "pmpt_123" },
170+ )
171+
172+ assert called_kwargs ["tools" ] is omit
173+ assert called_kwargs ["tool_choice" ] is omit
174+
175+
176+ @pytest .mark .allow_call_model_methods
177+ @pytest .mark .asyncio
178+ @pytest .mark .parametrize ("tool_choice" , ["none" , "required" ])
179+ async def test_prompt_id_keeps_literal_tool_choice_without_local_tools (tool_choice : str ):
180+ called_kwargs : dict [str , Any ] = {}
181+
182+ class DummyResponses :
183+ async def create (self , ** kwargs ):
184+ nonlocal called_kwargs
185+ called_kwargs = kwargs
186+ return get_response_obj ([])
187+
188+ class DummyResponsesClient :
189+ def __init__ (self ):
190+ self .responses = DummyResponses ()
191+
192+ model = OpenAIResponsesModel (
193+ model = "gpt-4" ,
194+ openai_client = DummyResponsesClient (), # type: ignore[arg-type]
195+ model_is_explicit = False ,
196+ )
197+
198+ await model .get_response (
199+ system_instructions = None ,
200+ input = "hi" ,
201+ model_settings = ModelSettings (tool_choice = tool_choice ),
202+ tools = [],
203+ output_schema = None ,
204+ handoffs = [],
205+ tracing = ModelTracing .DISABLED ,
206+ prompt = {"id" : "pmpt_123" },
207+ )
208+
209+ assert called_kwargs ["tools" ] is omit
210+ assert called_kwargs ["tool_choice" ] == tool_choice
0 commit comments