Closed
Description
Please read this first
- Have you read the docs?Agents SDK docs Yes
- Have you searched for related issues? Others may have had similar requests Yes
Question
Hi, I was trying to run the following command:
python -m examples.customer_service.main
I'm using Python 3.9.13, and when I run the script this way, I get the following error:
Traceback (most recent call last):
File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 466, in _eval_type_backport
return _eval_type(value, globalns, localns, type_params)
File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 500, in _eval_type
return typing._eval_type( # type: ignore
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 292, in _eval_type
return t._evaluate(globalns, localns, recursive_guard)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 554, in _evaluate
eval(self.__forward_code__, globalns, localns),
File "<string>", line 1, in <module>
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/kimmeoungjun/openai-agents-python/examples/customer_service/main.py", line 28, in <module>
class AirlineAgentContext(BaseModel):
File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_model_construction.py", line 221, in __new__
set_model_fields(cls, config_wrapper=config_wrapper, ns_resolver=ns_resolver)
File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_model_construction.py", line 544, in set_model_fields
fields, class_vars = collect_model_fields(cls, config_wrapper, ns_resolver, typevars_map=typevars_map)
File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_fields.py", line 118, in collect_model_fields
type_hints = _typing_extra.get_model_type_hints(cls, ns_resolver=ns_resolver)
File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 329, in get_model_type_hints
hints[name] = try_eval_type(value, globalns, localns)
File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 378, in try_eval_type
return eval_type_backport(value, globalns, localns), True
File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 429, in eval_type_backport
return _eval_type_backport(value, globalns, localns, type_params)
File "/Users/kimmeoungjun/openai-agents-python/env/lib/python3.9/site-packages/pydantic/_internal/_typing_extra.py", line 474, in _eval_type_backport
raise TypeError(
TypeError: Unable to evaluate type annotation 'str | None'. If you are making use of the new typing syntax (unions using `|` since Python 3.10 or builtins subscripting since Python 3.9), you should either replace the use of new syntax with the existing `typing` constructs or install the `eval_type_backport` package.
It seems like the code is using the |
operator for union types (e.g., str | None
), which is only supported in Python 3.10 and above. Since I'm running 3.9, this results in a TypeError
.
From what I can tell, switching to Optional[str]
(or Union[str, None]
) instead of using the |
operator would resolve the issue and make it compatible with Python 3.9.
I was wondering—would it make sense to either:
- update the code to support 3.9, or
- clarify somewhere (like in the
README
orpyproject.toml
) that Python 3.10+ is required?
Either approach would work, but having a clear guideline on the expected Python version might help others avoid this kind of confusion. Thanks!