Skip to content

Tool call seems problematic with openai sdk 1.99.3 #2529

@ultmaster

Description

@ultmaster

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

I'm experiencing the following issue in multiple agent frameworks --- autogen and OpenAI agent sdk:

/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/agents/run.py:206: in run
    return await runner.run(
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/agents/run.py:434: in run
    turn_result = await self._run_single_turn(
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/agents/run.py:956: in _run_single_turn
    new_response = await cls._get_new_response(
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/agents/run.py:1168: in _get_new_response
    new_response = await model.get_response(
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/agents/models/openai_chatcompletions.py:66: in get_response
    response = await self._fetch_response(
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/agents/models/openai_chatcompletions.py:228: in _fetch_response
    converted_messages = Converter.items_to_messages(input)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/agents/models/chatcmpl_converter.py:443: in items_to_messages
    new_tool_call = ChatCompletionMessageToolCallParam(
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/typing.py:1184: in __call__
    result = self.__origin__(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = typing.Union, args = ()
kwds = {'function': {'arguments': '{"expression":"43*57"}', 'name': 'calculate'}, 'id': 'call_AiUOswhpHBBfEjapoaC5iOe3', 'type': 'function'}

    def __call__(self, *args, **kwds):
>       raise TypeError(f"Cannot instantiate {self!r}")
E       TypeError: Cannot instantiate typing.Union
agentlightning/tracer/base.py:80: in trace_run
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
tests/test_tracer.py:675: in run_one
    asyncio.get_event_loop().run_until_complete(run_agent(agent_func))
uvloop/loop.pyx:1518: in uvloop.loop.Loop.run_until_complete
    ???
tests/test_tracer.py:216: in run_agent
    return await agent_func()
           ^^^^^^^^^^^^^^^^^^
tests/test_tracer.py:425: in agent_autogen_mcp
    response = await agent.run(task="What is 42 * 12?")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/autogen_agentchat/agents/_base_chat_agent.py:149: in run
    response = await self.on_messages(input_messages, cancellation_token)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/autogen_agentchat/agents/_assistant_agent.py:896: in on_messages
    async for message in self.on_messages_stream(messages, cancellation_token):
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/autogen_agentchat/agents/_assistant_agent.py:953: in on_messages_stream
    async for inference_output in self._call_llm(
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/autogen_agentchat/agents/_assistant_agent.py:1107: in _call_llm
    model_result = await model_client.create(
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/autogen_ext/models/openai/_openai_client.py:660: in create
    create_params = self._process_create_args(
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/autogen_ext/models/openai/_openai_client.py:618: in _process_create_args
    converted_tools = convert_tools(tools)
                      ^^^^^^^^^^^^^^^^^^^^
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/autogen_ext/models/openai/_openai_client.py:256: in convert_tools
    ChatCompletionToolParam(
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/typing.py:1184: in __call__
    result = self.__origin__(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = typing.Union, args = ()
kwds = {'function': {'description': 'Calculates/evaluates the given expression.', 'name': 'calculate', 'parameters': {'additi... 'Expression', 'type': 'string'}}, 'required': ['expression'], 'type': 'object'}, 'strict': False}, 'type': 'function'}

    def __call__(self, *args, **kwds):
>       raise TypeError(f"Cannot instantiate {self!r}")
E       TypeError: Cannot instantiate typing.Union

/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/typing.py:501: TypeError

Downgrade to openai 1.99.1 seems to fix the issue.

microsoft/agent-lightning#27

To Reproduce

https://github.com/microsoft/agent-lightning/actions/runs/16818687973/job/47641166265

https://github.com/microsoft/agent-lightning/actions/runs/16822457025/job/47651983069

openai                                   1.99.3
openai-agents                            0.2.5

Code snippets

OS

Linux

Python version

3.12

Library version

1.99.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions