Please read this first
- Have you read the docs? Yes.
- Have you searched for related issues? Yes. I searched existing issues and PRs for
AgentOutputSchema Literal name and did not find a matching report or fix.
Describe the bug
AgentOutputSchema.name() crashes for output types that include typing.Literal values. The schema itself can be built, but the name formatter recursively assumes every typing argument has __name__. Literal arguments are plain values such as strings, so the run can fail while starting the agent trace for an otherwise valid structured output type.
I also checked the adjacent structured output paths. Pydantic models, plain dict, generic dict, and generic list output types keep working; the issue is with typing constructs whose arguments are not Python types, such as Literal["ok"].
Debug information
- Agents SDK version:
0.17.1, reproduced on main at 92e014a4
- Python version: Python 3.12.1
Repro steps
Run this minimal script:
from typing import Any, Literal, cast
from agents import AgentOutputSchema
schema = AgentOutputSchema(cast(type[Any], Literal["ok"]))
print(schema.json_schema())
print(schema.name())
Actual result:
{'properties': {'response': {'const': 'ok', 'title': 'Response', 'type': 'string'}}, 'required': ['response'], 'title': 'OutputType', 'type': 'object', 'additionalProperties': False}
Traceback (most recent call last):
File "<stdin>", line 7, in <module>
File "/tmp/openai-agents-3347-edit/src/agents/agent_output.py", line 168, in name
return _type_to_str(self.output_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/openai-agents-3347-edit/src/agents/agent_output.py", line 191, in _type_to_str
args_str = ", ".join(_type_to_str(arg) for arg in args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/openai-agents-3347-edit/src/agents/agent_output.py", line 191, in <genexpr>
args_str = ", ".join(_type_to_str(arg) for arg in args)
^^^^^^^^^^^^^^^^^
File "/tmp/openai-agents-3347-edit/src/agents/agent_output.py", line 189, in _type_to_str
return t.__name__
^^^^^^^^^^
AttributeError: 'str' object has no attribute '__name__'. Did you mean: '__ne__'?
Expected behavior
AgentOutputSchema.name() should return a stable string for valid output types that include literal values, for example Literal['ok'], instead of crashing. Nested forms such as list[Literal["ok", "done"]] should also format without raising.
Please read this first
AgentOutputSchema Literal nameand did not find a matching report or fix.Describe the bug
AgentOutputSchema.name()crashes for output types that includetyping.Literalvalues. The schema itself can be built, but the name formatter recursively assumes every typing argument has__name__. Literal arguments are plain values such as strings, so the run can fail while starting the agent trace for an otherwise valid structured output type.I also checked the adjacent structured output paths. Pydantic models, plain
dict, genericdict, and genericlistoutput types keep working; the issue is with typing constructs whose arguments are not Python types, such asLiteral["ok"].Debug information
0.17.1, reproduced onmainat92e014a4Repro steps
Run this minimal script:
Actual result:
Expected behavior
AgentOutputSchema.name()should return a stable string for valid output types that include literal values, for exampleLiteral['ok'], instead of crashing. Nested forms such aslist[Literal["ok", "done"]]should also format without raising.