Python: Add file_ids support and per-message file attachment for Azure AI code interpreter#4201
Open
giles17 wants to merge 10 commits intomicrosoft:mainfrom
Open
Python: Add file_ids support and per-message file attachment for Azure AI code interpreter#4201giles17 wants to merge 10 commits intomicrosoft:mainfrom
giles17 wants to merge 10 commits intomicrosoft:mainfrom
Conversation
…et_code_interpreter_tool() Update the factory method to accept file_ids and data_sources keyword arguments, matching the underlying azure.ai.agents SDK CodeInterpreterTool constructor. This enables users to attach uploaded files for code interpreter analysis. Fixes microsoft#4050 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
file_ids support to AzureAIAgentClient.get_code_interpreter_tool()
Member
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds file_ids and data_sources support to AzureAIAgentClient.get_code_interpreter_tool(), enabling users to attach uploaded files to the code interpreter for analysis. This addresses issue #4050 where users couldn't provide file attachments through the framework's factory method.
Changes:
- Extended
get_code_interpreter_tool()to acceptfile_idsanddata_sourceskeyword arguments that are forwarded to the Azure Agents SDK'sCodeInterpreterTool - Added
VectorStoreDataSourceimport to support the new parameter type - Added comprehensive test coverage for basic instantiation, file_ids forwarding, and integration with the tool preparation pipeline
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
python/packages/azure-ai/agent_framework_azure_ai/_chat_client.py |
Added file_ids and data_sources parameters to get_code_interpreter_tool() method with updated docstring and examples; imported VectorStoreDataSource type |
python/packages/azure-ai/tests/test_azure_ai_agent_client.py |
Added three test cases: basic tool creation, file_ids parameter forwarding, and tool_resources population in run options |
python/packages/azure-ai/agent_framework_azure_ai/_chat_client.py
Outdated
Show resolved
Hide resolved
Add hosted_file handling in _prepare_messages() to convert Content.from_hosted_file() into MessageAttachment on ThreadMessageOptions. This enables per-message file scoping for code interpreter, matching the underlying Azure AI Agents SDK MessageAttachment pattern. - Add hosted_file case in _prepare_messages() match statement - Import MessageAttachment from azure.ai.agents.models - Add sample for per-message CSV file attachment with code interpreter - Add employees.csv test data file - Add 3 unit tests for hosted_file attachment conversion Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
file_ids support to AzureAIAgentClient.get_code_interpreter_tool()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
file_idsanddata_sourcessupport toget_code_interpreter_tool()on both V1 (AzureAIAgentClient) and V2 (AzureAIClient) clients, and adds per-message file attachment support viaContent.from_hosted_file()for the V1 client.Problem
get_code_interpreter_tool()accepted no parameters on either client — users had no way to attach files for code interpreter analysis through the framework's factory method.AzureAIAgentClient._prepare_messages()had nohosted_filehandling, soContent.from_hosted_file()was silently dropped. This meant per-message file scoping (viaMessageAttachment) was not possible.Changes
Tool-level file_ids (both clients)
_chat_client.py(V1):get_code_interpreter_tool()now acceptsfile_ids: list[str | Content]anddata_sources: list[VectorStoreDataSource], forwarding to the SDK'sCodeInterpreterTool._client.py(V2): Samefile_ids: list[str | Content]widening, usingCodeInterpreterToolAuto(file_ids=...)._shared.py: Addedresolve_file_ids()helper to extract file IDs from bothstrandContent.from_hosted_file()objects.file_idsacceptsContent.from_hosted_file()objects alongside plain strings for ergonomic usage.Per-message file attachment (V1 client)
_chat_client.py: Addedhosted_filecase in_prepare_messages()that convertsContent.from_hosted_file()intoMessageAttachmentonThreadMessageOptions. This matches the underlying Azure AI Agents SDKMessageAttachmentpattern for per-message file scoping.Tests
test_azure_ai_agent_client.py: Added tests for file_ids, data_sources, mutual exclusivity, Content objects, mixed types, unsupported Content types, and 3 tests for hosted_file → MessageAttachment conversion.test_azure_ai_client.py: Added Content tests for V2 client.test_agent_provider.py: Added tests for tool_resources flow.Sample
azure_ai_with_code_interpreter_file_upload.py: New sample demonstrating per-message CSV file attachment with V1 client usingContent.from_hosted_file().employees.csv: Test data for the sample.Usage
Tool-level (file shared across thread)
Per-message (file scoped to single message)
Fixes #4050