To accurately and effectively upload a file to the Code Interpreter during an active agent run, it’s important to understand the current limitations and supported workflows within the OpenAI SDK. Previously, developers could use the agents.runs.update() method to inject tool_resources, such as file IDs, directly into an ongoing run. However, this capability has been deprecated, and attempting to use tool_resources in this way now results in an error like Session.request() got an unexpected keyword argument 'tool_resources'. This confirms that the SDK no longer supports updating a run with tool resources dynamically.
The correct and supported approach now involves leveraging the thread and message architecture. Specifically, your tool (e.g., an SQL extractor) should return the file ID(s) of the uploaded .csv file as part of its output payload. These file IDs must then be attached to the thread using the threads.messages.create() method. This method allows you to associate the file with a message in the thread, which the Code Interpreter can then access in subsequent steps of the run.
For example, after your tool uploads the file and returns the file ID, your agent loop should create a message like: client.beta.threads.messages.create(thread_id=..., role="user", content="Here is the CSV file.", file_ids=["file-abc123"]). This ensures the file is properly linked to the thread and available to the Code Interpreter.Files cannot be attached directly to an active run or injected mid-run using deprecated methods. Instead, the tool should return file IDs, and the agent loop must create a new message in the thread using threads.messages.create() to attach those files. This ensures the Code Interpreter can access them and keeps the workflow aligned with OpenAI’s current architecture.
Hope it Helps!
Thank you