-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Description
When using the latest openai
Python package with the openai-agents
SDK, calling Runner.run_sync()
fails with:
TypeError: Cannot instantiate typing.Union
This happens because the ChatCompletionMessageToolCallParam
type in openai
is now a typing.Union
instead of a concrete class, and the openai-agents
code still attempts to instantiate it directly.
Environment
- Python: 3.12.11
- openai: 1.99.3 (also tested with 1.99.4)
- openai-agents: latest from PyPI
- OS: Windows 10 / 11
Steps to Reproduce
- Install latest packages:
pip install --upgrade openai openai-agents
Root Cause Analysis
In recent openai
releases (>=1.99.2
), ChatCompletionMessageToolCallParam
is no longer a concrete Pydantic model — it’s now defined as a typing.Union
of multiple tool call param types, e.g.:
ChatCompletionMessageFunctionToolCallParam | ChatCompletionMessageCustomToolCallParam
The openai-agents
SDK still attempts to instantiate ChatCompletionMessageToolCallParam(...)
directly in chatcmpl_converter.py
.
In Python, typing.Union
is not callable, so this raises:
TypeError: Cannot instantiate typing.Union
Workarounds
- Pin
openai
to 1.99.1:pip install "openai==1.99.1"
- Modify
chatcmpl_converter.py
to:
- Build a plain
dict
, or - Instantiate a specific member of the union, e.g.:
ChatCompletionMessageFunctionToolCallParam(...)
instead of calling the union type alias.