Skip to content

Python: Add per-message file attachment (MessageAttachment) support for AzureAIAgentClient #4352

@giles17

Description

@giles17

Summary

Add per-message file attachment support to AzureAIAgentClient (V1) via MessageAttachment in _prepare_messages().

Problem

The Azure AI Agents SDK supports per-message file scoping via MessageAttachment, which attaches a file to a specific message rather than the agent/thread. This is important for multi-user scenarios where the same agent is shared across users but files should be isolated per-request.

Currently, AzureAIAgentClient._prepare_messages() has no hosted_file case, so Content.from_hosted_file() is silently dropped when used in message contents.

Expected Behavior

Users should be able to attach files per-message like this:

file_content = Content.from_hosted_file(file_id=uploaded.id)
message = Message(role="user", contents=["Analyze the CSV.", file_content])
response = await agent.run(message)

This should be converted to a MessageAttachment on the ThreadMessageOptions sent to the API.

Design Considerations

The MessageAttachment requires a tools parameter specifying which tools can use the file (CodeInterpreterTool, FileSearchTool, or both). The challenge is determining which tool definitions to include:

  • Content.from_hosted_file() is a framework-level concept with no tool type info
  • _prepare_messages() currently has no access to the agent's configured tools
  • Hardcoding one tool type (e.g., CodeInterpreterTool) would break for other tool types
  • Passing tool definitions into _prepare_messages() would deviate from the existing pattern across all clients

Options to consider:

  1. Pass tool definitions into _prepare_messages() and filter for attachment-compatible types
  2. Include both CodeInterpreterTool and FileSearchTool on every attachment (needs API validation)
  3. Add tool type info to Content.from_hosted_file() (couples framework to Azure SDK concepts)

References

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions