Skip to content

Python: Fix broken Content API imports in Python samples#3639

Merged
moonbox3 merged 2 commits intomainfrom
copilot/fix-import-paths-image-analysis
Feb 3, 2026
Merged

Python: Fix broken Content API imports in Python samples#3639
moonbox3 merged 2 commits intomainfrom
copilot/fix-import-paths-image-analysis

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

Motivation and Context

Python samples were using deprecated TextContent, UriContent, and DataContent classes that are no longer exported. The framework consolidated these into a unified Content class with factory methods (Content.from_text(), Content.from_uri(), etc.) but 11 sample files were not updated, causing ImportError for users.

Description

Updated all affected samples to use the current Content API:

Import changes:

  • TextContent, UriContent, DataContentContent

Constructor changes:

  • TextContent(text="...")Content.from_text(text="...")
  • UriContent(uri="...", media_type="...")Content.from_uri(uri="...", media_type="...")

Type checks:

  • isinstance(content, TextContent)content.type == "text"

Affected files (11):

  • agents/azure_openai/azure_responses_client_image_analysis.py
  • agents/openai/openai_responses_client_image_analysis.py
  • agents/openai/openai_responses_client_image_generation.py
  • agents/openai/openai_responses_client_streaming_image_generation.py
  • agents/openai/openai_responses_client_with_code_interpreter.py
  • agents/azure_ai/azure_ai_with_code_interpreter_file_download.py
  • agents/custom/custom_agent.py
  • agents/custom/custom_chat_client.py
  • devui/weather_agent_azure/agent.py
  • middleware/override_result_with_middleware.py
  • workflows/orchestration/handoff_with_code_interpreter_file.py

Example change:

# Before
from agent_framework import TextContent, UriContent
contents=[
    TextContent(text="What do you see?"),
    UriContent(uri="https://...", media_type="image/jpeg"),
]

# After
from agent_framework import Content
contents=[
    Content.from_text(text="What do you see?"),
    Content.from_uri(uri="https://...", media_type="image/jpeg"),
]

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.
Original prompt

This section details on the original issue you should resolve

<issue_title>Python: [Bug]: Broken import paths for image analysis fields</issue_title>
<issue_description>### Description

I am currently using the latest beta versions of agent-framework-core and agent-framework (v1.0.0b260130).

I am encountering an issue with importing the necessary fields for image analysis. Specifically, I am unable to import TextContent and DataContent. It seems the import paths might have changed and I do not find it.

Could you please clarify the correct import statements for these components?

Code Sample

from agent_framework import TextContent, DataContent

Error Messages / Stack Traces

ImportError: cannot import name 'TextContent' from 'agent_framework' (...\dok-agent-research\.venv\Lib\site-packages\agent_framework\__init__.py)

Package Versions

agent-framework-core 1.0.0b260130

Python Version

Python 3.11

Additional Context

No response</issue_description>

<agent_instructions>Create a PR to fix the issues with these files still references things like TextContent(text=...). It should be Content.from_text(...) or similar, based on what is defined in _types.py</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@moonbox3 @AlPashy can you let us know which sample is showing `from agent_framework import TextContent, DataContent`? The code has been updated to use `from agent_framework import Content` and then there are class methods on Content, like `Content.from_text(...)`. @moonbox3 Can you link to it, please, so we can fix it? Thanks. @moonbox3 I can see these files have issues: - agent-framework/python/samples/getting_started/agents/azure_openai/azure_responses_client_image_analysis.py - agent-framework/python/samples/getting_started/agents/custom/custom_agent.py - agent-framework/python/samples/getting_started/agents/custom/custom_chat_client.py - agent-framework/python/samples/getting_started/agents/openai/openai_responses_client_image_analysis.py - agent-framework/python/samples/getting_started/devui/weather_agent_azure/agent.py - agent-framework/python/samples/getting_started/middleware/override_result_with_middleware.py

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: moonbox3 <35585003+moonbox3@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix broken import paths for image analysis fields Fix broken Content API imports in Python samples Feb 3, 2026
Copilot AI requested a review from moonbox3 February 3, 2026 10:32
@github-actions github-actions bot changed the title Fix broken Content API imports in Python samples Python: Fix broken Content API imports in Python samples Feb 3, 2026
@moonbox3 moonbox3 marked this pull request as ready for review February 3, 2026 10:33
Copilot AI review requested due to automatic review settings February 3, 2026 10:33
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 broken imports in 11 Python sample files that were using deprecated Content API classes. The samples were attempting to import TextContent, UriContent, and DataContent classes that have been consolidated into a unified Content class with factory methods.

Changes:

  • Updated all affected samples to import the unified Content class instead of deprecated content type classes
  • Replaced constructor calls with factory methods (Content.from_text(), Content.from_uri())
  • Converted isinstance() type checks to property-based checks using content.type

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
handoff_with_code_interpreter_file.py Updated import and replaced isinstance(content, TextContent) with content.type == "text"
override_result_with_middleware.py Changed TextContent(text=...) to Content.from_text(text=...)
devui/weather_agent_azure/agent.py Changed TextContent(text=...) to Content.from_text(text=...)
openai_responses_client_with_code_interpreter.py Replaced isinstance() checks with content.type == "text"
openai_responses_client_streaming_image_generation.py Updated import and replaced isinstance(content, DataContent) with content.type == "data"
openai_responses_client_image_generation.py Updated import and replaced isinstance() checks with output.type in ("data", "uri")
openai_responses_client_image_analysis.py Replaced TextContent() and UriContent() with Content.from_text() and Content.from_uri()
custom_chat_client.py Changed TextContent(text=...) to Content.from_text(text=...)
custom_agent.py Changed TextContent(text=...) to Content.from_text(text=...) in multiple locations
azure_responses_client_image_analysis.py Replaced TextContent() and UriContent() with Content.from_text() and Content.from_uri()
azure_ai_with_code_interpreter_file_download.py Replaced isinstance(content, TextContent) checks with content.type == "text"

@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Feb 3, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 3, 2026
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Feb 3, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 3, 2026
@moonbox3 moonbox3 added this pull request to the merge queue Feb 3, 2026
Merged via the queue into main with commit 96d3f2a Feb 3, 2026
29 checks passed
@crickman crickman deleted the copilot/fix-import-paths-image-analysis branch February 4, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Broken import paths for image analysis fields

4 participants