Python: [Bug]: Content.from_dict leaves the nested content of image generation and MCP server tool results as plain dicts
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 77/100
Direzione di ricerca
Inizia in agent_framework/_types.py, da Content.from_dict, dove vengono ricostruiti i valori annidati di outputs e output. Trova i test esistenti per Content.from_dict e aggiungi casi di regressione per una singola mappatura outputs di generazione di immagini, elementi MCP output e output JSON semplici. Il lavoro è completato quando le mappature di contenuto riconosciute vengono ripristinate come Content, mentre i valori MCP semplici restano invariati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Observed Behavior
After a to_dict() / from_dict() round trip, two kinds of nested content come back as plain dicts instead of Content:
- the
outputsof animage_generation_tool_result. The OpenAI chat client sets it to a singleContent(the generated image as a data URI). - the items of the
outputlist of anmcp_server_tool_result. The OpenAI and Anthropic chat clients set it to a list ofContent.
This happens wherever messages are saved and loaded, for example when an AgentSession with its history is serialized with to_dict() and restored with AgentSession.from_dict(), or with Message.from_dict() directly. Code that expects Content then loses the data. For example, the Responses host reads the generated image with _image_generation_result(), which returns None for the restored result, so the image is dropped from the output item.
from_dict already rebuilds other nested content (function_call, screenshot, the inputs and outputs lists, items), but not a single outputs value or the output list.
Expected Behavior
The nested image and MCP output content comes back as Content, the same as before saving. MCP outputs that are plain JSON values stay unchanged.
Steps to Reproduce
- Build a message with an image generation result and an MCP server tool result, as the OpenAI chat client does.
- Save and restore it (here through an
AgentSession). - Check the type of the nested values.
Minimal Reproduction
from agent_framework import AgentSession, Content, Message
from agent_framework_hosting_responses._parsing import _image_generation_result
message = Message("assistant", [
Content.from_image_generation_tool_result(
image_id="ig_1", outputs=Content.from_uri("data:image/png;base64,iVBORw0KGgo=")
),
Content.from_mcp_server_tool_result("mcp_1", output=[Content.from_text("42")]),
])
session = AgentSession()
session.state["history"] = {"messages": [message]}
restored = AgentSession.from_dict(session.to_dict()).state["history"]["messages"][0]
print(type(restored.contents[0].outputs).__name__) # dict (expected Content)
print(type(restored.contents[1].output[0]).__name__) # dict (expected Content)
print(_image_generation_result(message.contents[0].outputs)) # iVBORw0KGgo=
print(_image_generation_result(restored.contents[0].outputs)) # None
The cause is in Content.from_dict in agent_framework/_types.py: it rebuilds outputs only when it is a list, and it does not look at output at all.
Error Messages and Stack Traces
No error. The restored values are plain dicts, so the image or tool output is silently lost where Content is expected.
Package Versions
agent-framework-core: 1.21.0 (main at a75e803ef), agent-framework-hosting-responses: 1.0.0a261008
Python Version
Python 3.12
Additional Context
I'd like to fix this. In Content.from_dict, also rebuild a single outputs mapping and the items of an output list, but only mappings whose type is a known content type, so plain MCP outputs stay as they are. Plus regression tests.
AI assistance: I used an AI coding assistant for the analysis and to draft this report. I reproduced and verified the behavior myself.
- Lingua principale
- Python
- Stelle
- 14k
- Fork
- 2.5k
- Merge medio
- 2g 2h
- PR unite (30g)
- 389
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/agent-framework
-
Python: [Bug]: Out-of-range Cosmos memory search parameters silently disable retrievalForse già presa @Lesereingrape l’ha presa 1 giorno fa. Apertapython triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
microsoft/agent-framework#9317 ·
I maintainer di solito rispondono entro 1 giorno
-
Python: [Bug]: A non-positive MCP request timeout silently disables the timeoutForse già presa @Lesereingrape l’ha presa 1 giorno fa. Apertapython triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
microsoft/agent-framework#9313 ·
I maintainer di solito rispondono entro 1 giorno
-
.NET: Python: [Bug]: Two switch-case branches cannot route to the same executor (EdgeDuplicationError)Forse già presa @shanto462 l’ha presa 1 giorno fa. Aperta.NET python triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
microsoft/agent-framework#9297 ·
I maintainer di solito rispondono entro 1 giorno
-
.NET python triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
microsoft/agent-framework#9092 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Python: raw-data content mappings lose annotations and attachment metadataForse già presa @moonbox3 l’ha presa 13 giorni fa. Apertapython triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
microsoft/agent-framework#8632 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di microsoft/agent-framework
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
aws-samples/sample-per-model-bedrock#191 ·
I maintainer di solito rispondono entro 1 giorno
-
Docs viewer: inverted grey colormap, Phantom CT window -20 to 35 HU, smoothing up to 40 mmForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaarea: docs enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
PyTomography/PyTomography#331 ·
I maintainer di solito rispondono entro 1 giorno
-
effort: low prio: low ready
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
digitalfabrik/integreat-cms#4616 ·
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
FuRongJun-1999/dsh-memory#226 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug difficulty:2 good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
MakazhanAlpamys/Soup#1865 ·
I maintainer di solito rispondono entro 1 giorno