Python: Improve AG-UI tool call argument protocol conformance#6342
Open
White-Mouse wants to merge 2 commits into
Open
Python: Improve AG-UI tool call argument protocol conformance#6342White-Mouse wants to merge 2 commits into
White-Mouse wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds safeguards to prevent TOOL_CALL_ARGS events from being incorrectly associated with the “current” tool call when IDs mismatch, with regression tests covering the expected behavior.
Changes:
- Ignore
TOOL_CALL_ARGSwhentoolCallIddoesn’t match the active tool call ID (and log a warning). - Update tool-call end handling to conditionally clear current tool state based on matching IDs.
- Add tests to ensure mismatched IDs don’t rebind arguments or execute the wrong client tool.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| python/packages/ag-ui/agent_framework_ag_ui/_event_converters.py | Adds toolCallId mismatch checks for TOOL_CALL_ARGS and conditional state reset on TOOL_CALL_END. |
| python/packages/ag-ui/tests/ag_ui/test_event_converters.py | Adds regression test ensuring mismatched TOOL_CALL_ARGS don’t attach to the wrong tool call. |
| python/packages/ag-ui/tests/ag_ui/test_ag_ui_client.py | Adds client-level regression test ensuring mismatched args don’t cause execution of the current tool. |
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
TOOL_CALL_ARGShandling check the eventtoolCallIdagainst the active tool callTOOL_CALL_ENDarrivesDetails
This is a robustness and AG-UI protocol conformance fix.
TOOL_CALL_ARGSevents carry a tool-call identifier, and the client-side converter should keep streamed argument fragments bound to that identifier while it buildsFunctionCallContent.With this change, malformed or out-of-order argument fragments no longer get attached to the currently active tool call when their
toolCallIdpoints at a different call.Validation
From
python/:uv run --group dev pytest -q --disable-warnings packages/ag-ui/tests/ag_ui/test_event_converters.py::TestAGUIEventConverter::test_tool_call_args_must_match_current_tool_call_id packages/ag-ui/tests/ag_ui/test_ag_ui_client.py::TestAGUIChatClient::test_tool_call_args_id_mismatch_does_not_execute_current_client_tooluv run --group dev pytest -q --disable-warnings packages/ag-ui/tests/ag_ui/test_event_converters.py packages/ag-ui/tests/ag_ui/test_ag_ui_client.pyuv run --group dev pytest -q --disable-warnings packages/ag-ui/tests/ag_uiuv run --group dev python -m py_compile packages/ag-ui/agent_framework_ag_ui/_event_converters.py packages/ag-ui/tests/ag_ui/test_event_converters.py packages/ag-ui/tests/ag_ui/test_ag_ui_client.pyuv run --group dev ruff check packages/ag-ui/agent_framework_ag_ui/_event_converters.py packages/ag-ui/tests/ag_ui/test_event_converters.py packages/ag-ui/tests/ag_ui/test_ag_ui_client.pygit diff --check