.NET: fix: Duplicate CallIds cause Handoff Message Filtering to fail#5359
Open
.NET: fix: Duplicate CallIds cause Handoff Message Filtering to fail#5359
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a .NET handoff-orchestration failure when providers emit non-unique (or missing) tool CallIds (e.g., Gemini via adapters), by reworking how handoff/tool-call messages are filtered before sending history to the next agent.
Changes:
- Rebuild
HandoffMessagesFilterto avoid relying on unique CallIds and retroactive removals. - Add unit tests intended to validate filtering behavior across
None,HandoffOnly, andAll. - Add an internal helper for producing the handoff “Transferred.”
FunctionResultContent.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffMessagesFilter.cs | Replaces dictionary-based matching with a streaming/ordering-based filter and adds a duplicate-CallId check. |
| dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/HandoffMessageFilterTests.cs | Adds coverage for filtering behaviors and CallId uniqueness permutations. |
| dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffAgentExecutor.cs | Adds an internal helper to create the handoff function result content. |
b56f69e to
c25558e
Compare
c25558e to
8be2dfd
Compare
Some providers, e.g. Gemini, do not use the CallId mechanism to disambiguate simultaneous function calls. This can result in message lists containing multiple turn to fail to filter properly. The fix is to take advantage of the expectation that Handoff Orchestration is a "single-speaker" flow, which only has a single active AIAgent per "turn" and an agent's turn is not finished until all outstanding function calls are finished. This allows us to expect that any ambiguous-CallId FunctionCallContent are either in separate turns or will have had a response before the next issued call with the same Id.
8be2dfd to
f082fcb
Compare
SergeyMenshykh
approved these changes
Apr 20, 2026
westey-m
approved these changes
Apr 20, 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
Some providers, e.g. Gemini, do not use the CallId mechanism to disambiguate simultaneous function calls. This can result in message lists containing multiple turn to fail to filter properly.
Description
The fix is to take advantage of the expectation that Handoff Orchestration is a "single-speaker" flow, which only has a single active AIAgent per "turn" and an agent's turn is not finished until all outstanding function calls are finished.
This allows us to expect that any ambiguous-CallId FunctionCallContent are either in separate turns or will have had a response before the next issued call with the same Id.
Contribution Checklist
[ ] Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.