MCPcopy Index your code
hub / github.com/openai/openai-agents-python / test_complex_args_function

Function test_complex_args_function

tests/test_function_tool.py:252–300  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

250
251@pytest.mark.asyncio
252async def test_complex_args_function():
253 tool = function_tool(complex_args_function, failure_error_function=None)
254 assert tool.name == "complex_args_function"
255
256 valid_json = json.dumps(
257 {
258 "foo": Foo(a=1).model_dump(),
259 "bar": Bar(x="hello", y=10),
260 }
261 )
262 result = await tool.on_invoke_tool(
263 ToolContext(None, tool_name=tool.name, tool_call_id="1", tool_arguments=valid_json),
264 valid_json,
265 )
266 assert result == "6 hello10 hello"
267
268 valid_json = json.dumps(
269 {
270 "foo": Foo(a=1, b=2).model_dump(),
271 "bar": Bar(x="hello", y=10),
272 }
273 )
274 result = await tool.on_invoke_tool(
275 ToolContext(None, tool_name=tool.name, tool_call_id="1", tool_arguments=valid_json),
276 valid_json,
277 )
278 assert result == "3 hello10 hello"
279
280 valid_json = json.dumps(
281 {
282 "foo": Foo(a=1, b=2).model_dump(),
283 "bar": Bar(x="hello", y=10),
284 "baz": "world",
285 }
286 )
287 result = await tool.on_invoke_tool(
288 ToolContext(None, tool_name=tool.name, tool_call_id="1", tool_arguments=valid_json),
289 valid_json,
290 )
291 assert result == "3 hello10 world"
292
293 # Missing required argument should raise an error
294 with pytest.raises(ModelBehaviorError):
295 await tool.on_invoke_tool(
296 ToolContext(
297 None, tool_name=tool.name, tool_call_id="1", tool_arguments='{"foo": {"a": 1}}'
298 ),
299 '{"foo": {"a": 1}}',
300 )
301
302
303def test_function_config_overrides():

Callers

nothing calls this directly

Calls 5

function_toolFunction · 0.90
ToolContextClass · 0.90
FooClass · 0.70
BarClass · 0.70
model_dumpMethod · 0.45

Tested by

no test coverage detected