Skip to content

Python: fixed image handling in anthropic and added convenience method on datacontent#2083

Merged
eavanvalkenburg merged 6 commits intomicrosoft:mainfrom
eavanvalkenburg:fix_2041
Nov 12, 2025
Merged

Python: fixed image handling in anthropic and added convenience method on datacontent#2083
eavanvalkenburg merged 6 commits intomicrosoft:mainfrom
eavanvalkenburg:fix_2041

Conversation

@eavanvalkenburg
Copy link
Member

@eavanvalkenburg eavanvalkenburg commented Nov 11, 2025

Motivation and Context

Fixes #2041
Adds handling of data content with an image in the right way.
added integration test

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes image handling in the Anthropic integration by properly converting DataContent images to Anthropic's expected base64 format and adds convenience methods for extracting data from data URIs.

  • Added get_data_bytes() and get_data_bytes_as_str() methods to DataContent for extracting base64 data from data URIs
  • Updated Anthropic client to correctly format image DataContent with base64 source type
  • Added integration test for image handling with the Anthropic API

Reviewed Changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
python/packages/core/agent_framework/_types.py Added convenience methods to DataContent class for extracting base64 data from data URIs
python/packages/anthropic/agent_framework_anthropic/_chat_client.py Fixed image handling by using the new convenience method to properly format image data in Anthropic's expected format with base64 source type, and added debug logging for unsupported media types
python/packages/anthropic/tests/test_anthropic_client.py Added integration test for image description functionality using a sample JPEG image
python/packages/anthropic/tests/assets/sample_image.jpg Added sample image file for testing image handling
python/packages/anthropic/pyproject.toml Added local development configuration for anthropic package (should not be committed)
python/uv.lock Updated lock file with dependency changes

@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Nov 11, 2025

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _types.py9199589%130–131, 149–150, 287, 289, 296, 315, 355, 401–402, 438, 588, 702–703, 705, 730, 737, 754–756, 829, 834–835, 837, 844–845, 847, 869, 876, 879–881, 886–887, 893–895, 1019, 1106–1109, 1117–1118, 1209, 1390, 1396, 1640–1642, 1648–1649, 1817, 1948, 1953, 1957, 1961, 2138, 2189–2193, 2203, 2208, 2667, 2753–2755, 2828, 2839–2840, 3014, 3018, 3030–3032, 3133–3135, 3137–3139, 3142, 3146, 3149, 3154, 3208–3210, 3225, 3241, 3269, 3276
TOTAL13489196285% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
1802 109 💤 0 ❌ 0 🔥 36.461s ⏱️

@moonbox3
Copy link
Contributor

@eavanvalkenburg looks like there are some conflicts we should resolve.

@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation .NET lab Agent Framework Lab labels Nov 12, 2025
@github-actions github-actions bot changed the title Python: fixed image handling in anthropic and added convenience method on datacontent .NET: Python: fixed image handling in anthropic and added convenience method on datacontent Nov 12, 2025
@eavanvalkenburg eavanvalkenburg changed the title .NET: Python: fixed image handling in anthropic and added convenience method on datacontent Python: fixed image handling in anthropic and added convenience method on datacontent Nov 12, 2025
@eavanvalkenburg eavanvalkenburg removed documentation Improvements or additions to documentation .NET lab Agent Framework Lab labels Nov 12, 2025
@markwallace-microsoft markwallace-microsoft added the lab Agent Framework Lab label Nov 12, 2025
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Nov 12, 2025
Merged via the queue into microsoft:main with commit ef60f38 Nov 12, 2025
35 checks passed
arisng pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
…d on datacontent (microsoft#2083)

* fixed image handling in anthropic and added convenience method on datacontent

* remove wheel path

* updated docstrings

* fixed image handling in anthropic and added convenience method on datacontent

* remove wheel path

* updated lock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lab Agent Framework Lab python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Can't upload images with AnthropicClient due to missing type field + URI header

6 participants