Skip to content

Bug: Pydantic Warnings and .final_output Serialization Issue with Code Interpreter File Citations #772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rainfishs opened this issue May 28, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@rainfishs
Copy link

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()).

@rainfishs rainfishs added the bug Something isn't working label May 28, 2025
@grillorafael
Copy link

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
Copy link
Author

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 of Annotation for type='container_file_citation'. Instead, it directly uses the AnnotationFileCitation class, modifies its type attribute, and adds properties such as container_id, end_index, and start_index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants