Description
Please read this first
- Have you read the docs?Agents SDK docs
yes - Have you searched for related issues? Others may have faced similar issues.
yes
Describe the bug
When I use await Runner.run()
, I want to access the output file from the codeInterpreterTool
. I've found that there isn't an elegant way to get it (using .final_output
). (I understand I can get it through Hooks, or using .raw_responses
, etc.).
Furthermore, when the codeInterpreterTool
outputs files, Pydantic shows some warnings like this:
.venv\lib\site-packages\pydantic\main.py:463: UserWarning: Pydantic serializer warnings:
PydanticSerializationUnexpectedValue(PydanticSerializationUnexpectedValue: Expected `literal['file_citation']` - serialized value may not be as expected [input_value='container_file_citation', input_type=str]
PydanticSerializationUnexpectedValue: Expected `AnnotationURLCitation` - serialized value may not be as expected [input_value=AnnotationFileCitation(fi...lt.txt', start_index=88), input_type=AnnotationFileCitation]
PydanticSerializationUnexpectedValue: Expected `AnnotationFilePath` - serialized value may not be as expected [input_value=AnnotationFileCitation(fi...lt.txt', start_index=88), input_type=AnnotationFileCitation])
PydanticSerializationUnexpectedValue(Expected `ResponseOutputRefusal` - serialized value may not be as expected [input_value=ResponseOutputText(annota...t)', type='output_text'), input_type=ResponseOutputText])
PydanticSerializationUnexpectedValue(Expected `literal['file_citation']` - serialized value may not be as expected [input_value='container_file_citation', input_type=str])
PydanticSerializationUnexpectedValue(Expected `AnnotationURLCitation` - serialized value may not be as expected [input_value=AnnotationFileCitation(fi...lt.txt', start_index=88), input_type=AnnotationFileCitation])
PydanticSerializationUnexpectedValue(Expected `AnnotationFilePath` - serialized value may not be as expected [input_value=AnnotationFileCitation(fi...lt.txt', start_index=88), input_type=AnnotationFileCitation])
return self.__pydantic_serializer__.to_python(
I believe this should be fixed.
My guess is that there's an issue with the conversion from .raw_responses[0].output[-1].content[0]
to .final_output
(possibly caused when using the ResponseOutputText.to_dict()
function for conversion), or it's happening around that point.
Debug information
- Agents SDK version: 0.0.16
- Python version Python 3.10.11
Repro steps
import asyncio
from agents import Agent, CodeInterpreterTool, Runner
async def main():
agent = Agent(
"form_definition_agent",
"You are an useful agent that helps users generate some text files based on their input. ",
tools=[
CodeInterpreterTool(tool_config={
"type": "code_interpreter",
"container": {
"type": "auto",
}
})
],
model="gpt-4.1-mini")
result = await Runner.run(
agent,
"Calculate the sum of 1 and 2. Write the result to a file named 'result.txt'."
)
print(result.final_output)
# print(result.raw_responses[0].output[-1].content[0].to_dict()) # Using this code will repeatedly trigger the same warning
if __name__ == "__main__":
asyncio.run(main())
Expected behavior
I expect that when I use result.final_output, I should get the ResponseOutputText class from result.raw_responses[0].output[-1].content[0], or its dictionary form (.to_dict()).
Activity
grillorafael commentedon May 28, 2025
facing a similar issue. On my end I'm just iterating over the output looking for a thing with file_id and container_id output
rainfishs commentedon May 29, 2025
Upon closer inspection, I've found that this doesn't seem to be solely an issue with the Agent SDK. Instead, it appears that
openai-python
hasn't independently implemented a subclass ofAnnotation
fortype='container_file_citation'
. Instead, it directly uses theAnnotationFileCitation
class, modifies itstype
attribute, and adds properties such ascontainer_id
,end_index
, andstart_index
.