Hello Leon OuChen,
To ensure CSV files remain isolated per thread in Azure AI Agents, it's essential to tightly couple each file with the specific thread it belongs to.
The current issue where uploaded files are accessible across all threads likely stems from shared file contexts or improperly scoped tool resources.
When uploading a CSV using upload_file_and_poll
, assign a purpose like FilePurpose.AGENTS
, but more importantly, encapsulate this file within a CodeInterpreterTool
that is initialized with only that file's ID.
This tool should then be passed explicitly to the create_thread
call, ensuring that the thread's resources are confined to its specific context. Proper thread-specific resource association ensures that each agent session has access only to its designated data, preventing cross-thread file leakage.
To implement this, consider refining your method as follows:
def create_thread_and_upload_csv(self, file_path: str):
file = self.project_client.agents.upload_file_and_poll(
file_path=file_path,
purpose=FilePurpose.AGENTS
)
code_interpreter = CodeInterpreterTool(file_ids=[file.id])
thread = self.project_client.agents.create_thread(
tool_resources=code_interpreter.resources
)
return thread, file
This setup ensures each thread uses an isolated code interpreter tied to its specific file, maintaining data separation. Also, verify that any vector stores or attachments created during the thread initialization are scoped locally to avoid inadvertent sharing across sessions.
Please refer this Azure AI Agent Service Code Interpreter (code-example)
Azure AI Agent Service file search tool (upload-files-code-examples)
I Hope this helps. Do let me know if you have any further queries.
Thank you!