Python: AG-UI deterministic state updates from tool results#5201
Open
moonbox3 wants to merge 2 commits intomicrosoft:mainfrom
Open
Python: AG-UI deterministic state updates from tool results#5201moonbox3 wants to merge 2 commits intomicrosoft:mainfrom
moonbox3 wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Contributor
Author
Python Test Coverage Report •
Python Unit Test Overview
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opt-in mechanism for AG-UI tools to emit deterministic state snapshots derived from the tool’s actual return value (vs. optimistic predict_state_config based on predicted args), addressing agent-framework issue #3167.
Changes:
- Introduces a public
state_update(text, state=...)helper that encodes a state snapshot intoContent.additional_properties. - Extracts tool-result state markers during AG-UI emission, merges into
FlowState.current_state, and emitsSTATE_SNAPSHOTafter tool results (including MCP tool results). - Adds unit + end-to-end + golden tests and an examples endpoint demonstrating deterministic tool-driven state.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| python/packages/core/agent_framework/ag_ui/init.pyi | Exposes state_update in the core AG-UI typing surface. |
| python/packages/core/agent_framework/ag_ui/init.py | Adds state_update to lazy exports (but still has export-list mismatches vs stub). |
| python/packages/ag-ui/agent_framework_ag_ui/_state.py | New helper + reserved marker key for deterministic state updates. |
| python/packages/ag-ui/agent_framework_ag_ui/_run_common.py | Extracts/merges tool-result state and emits STATE_SNAPSHOT events. |
| python/packages/ag-ui/agent_framework_ag_ui/init.py | Re-exports state_update from the runtime package. |
| python/packages/ag-ui/agent_framework_ag_ui_examples/server/main.py | Registers a new /deterministic_state example endpoint. |
| python/packages/ag-ui/agent_framework_ag_ui_examples/agents/weather_state_agent.py | New example agent showing tool-driven deterministic state. |
| python/packages/ag-ui/tests/ag_ui/test_run_common.py | Adds focused tests for helper, extraction, and emission behavior. |
| python/packages/ag-ui/tests/ag_ui/test_public_exports.py | Verifies state_update is exported publicly. |
| python/packages/ag-ui/tests/ag_ui/test_agent_wrapper_comprehensive.py | End-to-end regression coverage through real tool invocation. |
| python/packages/ag-ui/tests/ag_ui/golden/test_scenario_deterministic_state.py | Golden stream tests pinning user-visible event ordering/content. |
1. Add missing AGUIEventConverter, AGUIHttpService, __version__ to _IMPORTS in core ag_ui lazy-export list to match the .pyi stub. 2. Coalesce predictive and deterministic state snapshots into a single StateSnapshotEvent when both mechanisms are active on the same tool result, reducing redundant snapshot traffic. 3. Update state_update() docstring to clarify that a predictive snapshot may be emitted before the deterministic one when predict_state_config is active. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
eavanvalkenburg
approved these changes
Apr 10, 2026
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 and Context
predict_state_config, is driven optimistically by LLM-predicted tool arguments, which is wrong when the real state depends on what the tool actually computes (e.g.get_weatherneeds to fetch data and put that in state).state_update(text, state=...)helper inagent_framework_ag_ui. Tools return it as aContent; the snapshot rides inadditional_propertiesunder a reserved key, survivesparse_result/from_function_resultround-tripping, and is extracted by the AG-UI emitter which merges it intoFlowState.current_stateand emits aStateSnapshotEventright after theToolCallResultevent.predict_state_config— both mechanisms can fire on the same tool result, with predictive state applied first.state_update().Description
Contribution Checklist