Skip to content

.NET: fix: Duplicate CallIds cause Handoff Message Filtering to fail#5359

Open
lokitoth wants to merge 1 commit intomainfrom
dev/dotnet_workflow/fix_gemini_handoff_filter
Open

.NET: fix: Duplicate CallIds cause Handoff Message Filtering to fail#5359
lokitoth wants to merge 1 commit intomainfrom
dev/dotnet_workflow/fix_gemini_handoff_filter

Conversation

@lokitoth
Copy link
Copy Markdown
Member

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

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • [ ] Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@lokitoth lokitoth self-assigned this Apr 20, 2026
Copilot AI review requested due to automatic review settings April 20, 2026 11:37
@lokitoth lokitoth added .NET agent orchestration Issues related to agent orchestration workflows Related to Workflows in agent-framework labels Apr 20, 2026
@lokitoth lokitoth moved this to In Review in Agent Framework Apr 20, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 HandoffMessagesFilter to avoid relying on unique CallIds and retroactive removals.
  • Add unit tests intended to validate filtering behavior across None, HandoffOnly, and All.
  • 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.

Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffMessagesFilter.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffAgentExecutor.cs Outdated
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/fix_gemini_handoff_filter branch from b56f69e to c25558e Compare April 20, 2026 11:52
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/fix_gemini_handoff_filter branch from c25558e to 8be2dfd Compare April 20, 2026 11:54
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.
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/fix_gemini_handoff_filter branch from 8be2dfd to f082fcb Compare April 20, 2026 12:09
@lokitoth lokitoth added this pull request to the merge queue Apr 20, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@lokitoth lokitoth added this pull request to the merge queue Apr 20, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@lokitoth lokitoth added this pull request to the merge queue Apr 20, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@lokitoth lokitoth added this pull request to the merge queue Apr 20, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@lokitoth lokitoth added this pull request to the merge queue Apr 20, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@lokitoth lokitoth added this pull request to the merge queue Apr 20, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@lokitoth lokitoth added this pull request to the merge queue Apr 20, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent orchestration Issues related to agent orchestration .NET workflows Related to Workflows in agent-framework

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: HandoffMessagesFilter.FilterMessages NullReferenceException with non-unique CallIds (Gemini/Vertex AI)

4 participants