Python: fix AG-UI tool history replay#5856
Open
he-yufeng wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes AG-UI history replay producing invalid assistant/tool sequences by ensuring any pending assistant tool calls are always followed by tool-result messages, even when the next message is another assistant message or when history replay ends.
Changes:
- Added a
flush_pending_tool_calls()helper in_sanitize_tool_history()and invoked it before new assistant messages and at history end. - Reused the flush helper for the existing “user follow-up while tools pending” case to consolidate logic.
- Added regression tests covering consecutive assistant tool-call replay and end-of-history flushing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/packages/ag-ui/agent_framework_ag_ui/_message_adapters.py | Adds centralized pending-tool-call flushing to inject synthetic tool results before assistant messages and at history end. |
| python/packages/ag-ui/tests/ag_ui/test_message_adapters.py | Adds tests for consecutive assistant tool calls and history-ending pending tool calls. |
| return | ||
|
|
||
| logger.info(f"{reason} with {len(pending_tool_call_ids)} pending tool calls - injecting synthetic results") | ||
| for pending_call_id in pending_tool_call_ids: |
3ccd534 to
2de5dda
Compare
Contributor
Author
|
Rebased onto current Re-ran the focused checks locally:
|
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.
Summary
Fixes #5855.
To verify
uv run pytest packages\ag-ui\tests\ag_ui\test_message_adapters.py -q --basetemp .tmp\pytest -p no:cacheprovideruv run ruff check packages\ag-ui\agent_framework_ag_ui\_message_adapters.py packages\ag-ui\tests\ag_ui\test_message_adapters.pyuv run ruff format --check packages\ag-ui\agent_framework_ag_ui\_message_adapters.py packages\ag-ui\tests\ag_ui\test_message_adapters.pyuv run python -m py_compile packages\ag-ui\agent_framework_ag_ui\_message_adapters.py packages\ag-ui\tests\ag_ui\test_message_adapters.pygit diff --check