Skip to content

Conversation

HareeshBahuleyan
Copy link
Contributor

When running the code example to use agents sdk with LiteLLM: https://openai.github.io/openai-agents-python/models/litellm/

I get the following error:

File "/Users/hareeshbahuleyan/Desktop/mzai_github/openai-agents-python/src/agents/extensions/models/litellm_model.py", line 99, in get_response
    response = await self._fetch_response(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hareeshbahuleyan/Desktop/mzai_github/openai-agents-python/src/agents/extensions/models/litellm_model.py", line 345, in _fetch_response
    ret = await litellm.acompletion(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hareeshbahuleyan/Desktop/mzai_github/openai-agents-python/.venv/lib/python3.11/site-packages/litellm/utils.py", line 1586, in wrapper_async
    raise e
  File "/Users/hareeshbahuleyan/Desktop/mzai_github/openai-agents-python/.venv/lib/python3.11/site-packages/litellm/utils.py", line 1437, in wrapper_async
    result = await original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hareeshbahuleyan/Desktop/mzai_github/openai-agents-python/.venv/lib/python3.11/site-packages/litellm/main.py", line 563, in acompletion
    raise exception_type(
          ^^^^^^^^^^^^^^^
  File "/Users/hareeshbahuleyan/Desktop/mzai_github/openai-agents-python/.venv/lib/python3.11/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2306, in exception_type
    raise e  # it's already mapped
    ^^^^^^^
  File "/Users/hareeshbahuleyan/Desktop/mzai_github/openai-agents-python/.venv/lib/python3.11/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 539, in exception_type
    raise APIConnectionError(
litellm.exceptions.APIConnectionError: litellm.APIConnectionError: APIConnectionError: OpenAIException - Invalid tool choice, tool_choice=<openai.Omit object at 0x104a97c90>. Got=<class 'openai.Omit'>. Expecting str, or dict.

This PR attempts to handle the error thrown, in particular:

OpenAIException - Invalid tool choice, tool_choice=<openai.Omit object at 0x104a97c90>. Got=<class 'openai.Omit'>. Expecting str, or dict.

Co-authored-by: Kazuhiro Sera <seratch@openai.com>
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@seratch seratch merged commit f7711af into openai:main Oct 14, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants