Hello cheng victor,
Thank you for mentioning that the case being looked for is to attach the file dynamically in each conversation instead of uploading the file to agent as a fixed file tool.
The issue is likely caused by mixing three similar but different file‑handling mechanisms in Foundry, which leads to confusing the code interpreter execution.
Below are the execution patterns
1. Model context files (input_file in conversation items)
2. Agent-tool files (tool_resources bound to Code Interpreter)
3. Message attachments (classic Assistants pattern)
In the current implementation, the CSV file is added using conversations.items.create with content type set to input_file. This method only injects the file into the model context window, which allows the language model to read the file as text. However, files added this way are not mounted into the code interpreter runtime filesystem, so python code executed by the agent is unable to access the CSV during data analysis.
Use Code Interpreter with Microsoft Foundry agents - Microsoft Foundry | Microsoft Learn
Attempting to pass attachments during responses.create did not work because the Responses API does not modify conversation state. It only runs the agent against the existing conversation, and therefore does not support adding files or attachments at that stage. As a result, attachments passed to responses.create got ignored by design.
https://learn.microsoft.com/en-us/answers/questions/5789844/how-to-attach-files-to-code-interpreter-in-new-fou
So , please consider using the following approac for the usecase - dynamic, conversation‑scoped CSV usage with code interpreter :
- Please upload the CSV file normally using the Files API.
- Then , attach the file to the conversation message using a message attachment that explicitly references the Code Interpreter tool.
- Run the agent using responses.create against the same conversation.
Following this approach:
- The file is mounted into the Code Interpreter sandbox.
- The file is scoped only to that conversation.
- No agent updates or new agent versions are required.
- The file is accessible to all sub‑agents in a multi‑agent workflow.
How to use Foundry Agent Service Code Interpreter (classic) - Microsoft Foundry (classic) | Microsoft Learn
The recommended approach for new Foundry (multi-agent + Responses) is per-conversation file binding. If using classic please use the threads/messages approach where attachments are supported on message creation.
As a final check, please ensure that the agent has the code interpreter tool is enabled. Without this, the attached files will not be executed even if they are correctly added to the conversation.
Thank you!