Python: Preserve MCP Host payloads in AG-UI history - #7971
Conversation
|
likebean HaoFeng Zhao (@ronronner02) Shivani . (@Shivani767) This draft follows the MCP result discussions in #7959 and #7897: it leaves #7866 model-content selection/deduplication to #7897 and adds the orthogonal core-to-AG-UI contract that preserves the full Host payload through live events, |
There was a problem hiding this comment.
Pull request overview
Preserves complete MCP Host payloads across AG-UI events, snapshots, approvals, and history replay while retaining model-facing results separately.
Changes:
- Adds a core MCP Host-payload marker, including error propagation.
- Projects payloads through AG-UI live, snapshot, approval, and replay paths.
- Adds regression tests and documents the transport contract.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
python/packages/core/agent_framework/_mcp.py |
Preserves MCP Host payloads. |
python/packages/core/agent_framework/_tools.py |
Propagates exception metadata. |
python/packages/core/tests/core/test_mcp.py |
Tests payload persistence and errors. |
python/packages/ag-ui/agent_framework_ag_ui/_utils.py |
Adds payload extraction and replay helpers. |
python/packages/ag-ui/agent_framework_ag_ui/_run_common.py |
Projects live and snapshot payloads. |
python/packages/ag-ui/agent_framework_ag_ui/_message_adapters.py |
Converts persisted payloads and model sidecars. |
python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py |
Handles approval-resolved payloads. |
python/packages/ag-ui/tests/ag_ui/test_run_common.py |
Tests events, snapshots, and approvals. |
python/packages/ag-ui/tests/ag_ui/test_message_adapters.py |
Tests history reload and fallback. |
docs/specs/004-python-function-calling-loop.md |
Documents the MCP Host contract. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
9b7426c to
f197df3
Compare
Motivation & Context
MCP Apps need model-visible tool output and Host/UI hydration data to remain separate. Agent Framework currently loses the complete MCP
CallToolResultwhen AG-UI replaces streamed events withMESSAGES_SNAPSHOTor rebuilds persisted history, causing widgets to disappear after a run or reload.This is orthogonal to #7866 and draft PR #7897. That work selects and deduplicates model-visible MCP content; this change preserves the complete Host payload across AG-UI surfaces without exposing UI-only JSON to the model.
Description & Review Guide
CallToolResult, including successful and error payloads, under a private core-ownedadditional_propertiesmarker.TOOL_CALL_RESULTevents,MESSAGES_SNAPSHOT, and persisted history conversion.TOOL_RESULT_DISPLAY_KEYbehavior and compatibility with supported core versions that predate the marker.Related Issue
Fixes #7959
Draft PR #7897 addresses #7866's model-content selection and deduplication; it does not preserve Host/UI payloads and is intentionally not duplicated here.
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.