Skip to content

Python: fix(core): rebuild nested Content of image generation and MCP tool results in Content.from_dict - #9304

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 3 commits into
microsoft:mainfrom
shanto462:fix-content-from-dict-nested-outputs
Oct 15, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 3 commits into
microsoft:mainfrom
shanto462:fix-content-from-dict-nested-outputs

Conversation

@shanto462

@shanto462 Md. Shalah Uddin (shanto462) commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Motivation & Context

Content.from_dict did not rebuild two kinds of nested content: the single Content that the OpenAI client stores in an image generation result's outputs, and the Content items that the OpenAI and Anthropic clients store in an MCP server tool result's output list. After saving and restoring messages (for example through AgentSession.to_dict() / from_dict()), these came back as plain dicts, so code that expects Content lost the data. The Responses host, for example, dropped the generated image.

Description & Review Guide

  • What are the major changes? from_dict now also rebuilds a single outputs value and the items of an output list, through a new private helper, Content._from_serialized_value. These fields can also hold plain values such as tool JSON, so a mapping is rebuilt only when its type is a known content type and the rebuilt Content serializes back to the same mapping (with to_dict() or to_dict(exclude_none=False)). Otherwise, including when rebuilding raises, the original value is kept. Regression tests: a round trip of image and MCP results through Message.to_dict(), to_dict(exclude_none=False) and JSON; tool JSON that shares a content type name (kept as it is, also next to real Content in the same list); and other plain values.
  • What is the impact of these changes? Image generation and MCP server tool results keep their nested Content after a round trip. The existing handling of function_call, screenshot, inputs, list outputs and items does not change.
  • What do you want reviewers to focus on? The lossless check that tells serialized Content apart from tool JSON. Serialized Content always includes additional_properties, so tool JSON such as {"type": "text", "text": "x"} or {"type": "text", "value": 1} stays a plain dict. Only a mapping identical to serialized Content (for example the same dict with "additional_properties": {}) is rebuilt, since it cannot be told apart. The helper catches any exception from rebuilding, serializing or comparing, so odd tool JSON is kept instead of failing the whole load.

Related Issue

Fixes #9303

No other open PR covers this issue.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: issue analysis, implementation, tests, and this PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Oct 12, 2026
@eavanvalkenburg

Copy link
Copy Markdown
Member

/review

Comment thread python/packages/core/agent_framework/_types.py Outdated
Merged via the queue into microsoft:main with commit 48b45ac Oct 15, 2026
48 checks passed
@shanto462
Md. Shalah Uddin (shanto462) deleted the fix-content-from-dict-nested-outputs branch October 19, 2026 09:42

This branch was successfully deployed

1 active deployment
github-app-auth — cdfdefff Deployed Oct 14, 2026 by shanto462 via add_label #25334
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Content.from_dict leaves the nested content of image generation and MCP server tool results as plain dicts

3 participants