Repository navigation
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 intoOct 15, 2026
Conversation
Md. Shalah Uddin (shanto462)
requested review from
SergeyMenshykh,
Tao Chen (TaoChenOSU),
Eduard van Valkenburg (eavanvalkenburg),
Giles Odigwe (giles17),
Jose Alvarez (jpalvarezl),
Evan Mattson (moonbox3),
Roger Barreto (rogerbarreto),
sophia-ramsey and
westey (westey-m)
as code owners
October 12, 2026 11:04
Md. Shalah Uddin (shanto462)
deployed
to
github-app-auth
October 12, 2026 11:04 — with
GitHub Actions
Active
Md. Shalah Uddin (shanto462)
deployed
to
github-app-auth
October 12, 2026 11:05 — with
GitHub Actions
Active
Member
|
/review |
Md. Shalah Uddin (shanto462)
deployed
to
github-app-auth
October 13, 2026 07:59 — with
GitHub Actions
Active
Md. Shalah Uddin (shanto462)
deployed
to
github-app-auth
October 13, 2026 07:59 — with
GitHub Actions
Active
…ct-nested-outputs
Md. Shalah Uddin (shanto462)
deployed
to
github-app-auth
October 14, 2026 15:51 — with
GitHub Actions
Active
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Oct 15, 2026
Md. Shalah Uddin (shanto462)
deleted the
fix-content-from-dict-nested-outputs
branch
October 19, 2026 09:42
7 tasks
This branch was successfully deployed
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.
Motivation & Context
Content.from_dictdid not rebuild two kinds of nested content: the singleContentthat the OpenAI client stores in an image generation result'soutputs, and theContentitems that the OpenAI and Anthropic clients store in an MCP server tool result'soutputlist. After saving and restoring messages (for example throughAgentSession.to_dict()/from_dict()), these came back as plain dicts, so code that expectsContentlost the data. The Responses host, for example, dropped the generated image.Description & Review Guide
from_dictnow also rebuilds a singleoutputsvalue and the items of anoutputlist, 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 itstypeis a known content type and the rebuiltContentserializes back to the same mapping (withto_dict()orto_dict(exclude_none=False)). Otherwise, including when rebuilding raises, the original value is kept. Regression tests: a round trip of image and MCP results throughMessage.to_dict(),to_dict(exclude_none=False)and JSON; tool JSON that shares a content type name (kept as it is, also next to realContentin the same list); and other plain values.Contentafter a round trip. The existing handling offunction_call,screenshot,inputs, listoutputsanditemsdoes not change.Contentapart from tool JSON. SerializedContentalways includesadditional_properties, so tool JSON such as{"type": "text", "text": "x"}or{"type": "text", "value": 1}stays a plain dict. Only a mapping identical to serializedContent(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
AI assistance details: issue analysis, implementation, tests, and this PR description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.