Skip to content

.NET: fix: HandoffAgentExecutor does not output any response when non-streaming#4745

Open
lokitoth wants to merge 3 commits intomainfrom
dev/dotnet_workflow/handoff_outputs_missing_in_thread
Open

.NET: fix: HandoffAgentExecutor does not output any response when non-streaming#4745
lokitoth wants to merge 3 commits intomainfrom
dev/dotnet_workflow/handoff_outputs_missing_in_thread

Conversation

@lokitoth
Copy link
Member

@lokitoth lokitoth commented Mar 17, 2026

Motivation and Context

Due to needing custom logic and a more delocalized state, the HandoffAgentExecutor is still separate from the general AIAgentHostExecutor. The fixes made to the AIAgentHostExecutor to better support both streaming and non-streaming agent invocation modes and separate configuration for outputs (streaming vs. nonstream, output vs. no output) in PR #3142 did not get ported to HandoffAgentExecutor in hopes of unifying the two.

Description

To better support Handoff workflows running in non-streaming mode (and in particular when hosted as an AIAgent), we change the HandoffAgentExecutor to always emit an AgentRunResponse if it is not configured to emitEvents on the TurnToken, which should be more properly called emitStreamingUpdates now that AgentRunResponseEvent exists.

Fixes #2423

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.

Copilot AI review requested due to automatic review settings March 17, 2026 14:08
@markwallace-microsoft markwallace-microsoft added .NET workflows Related to Workflows in agent-framework labels Mar 17, 2026
@github-actions github-actions bot changed the title fix: HandoffAgentExecutor does not output any reponse when non-streaming .NET: fix: HandoffAgentExecutor does not output any reponse when non-streaming Mar 17, 2026
Copy link
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

Updates the specialized HandoffAgentExecutor to reliably produce workflow output in non-streaming mode (addressing the gap that existed compared to AIAgentHostExecutor improvements), and adds unit coverage to prevent regressions.

Changes:

  • Emit a final AgentResponse output from HandoffAgentExecutor when TurnToken.EmitEvents is not true (i.e., non-streaming).
  • Refactor existing AIAgentHostExecutor unit tests to share common assertions via a new base class.
  • Add a new unit test validating HandoffAgentExecutor output behavior across TurnToken.EmitEvents values.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffAgentExecutor.cs Emits a final AgentResponse output in non-streaming mode while preserving streaming-update behavior when enabled.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AIAgentHostExecutorTests.cs Extracts shared verification helpers into a base class and adds coverage for HandoffAgentExecutor output type selection.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
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 missing agent output in non-streaming Handoff workflows when hosted as an AIAgent, ensuring a final AgentResponse is emitted (vs. only streaming updates), and adds coverage for history persistence.

Changes:

  • Update HandoffAgentExecutor to emit an AgentResponse when TurnToken.EmitEvents is not true (treating the flag as “streaming vs. non-streaming” output selection).
  • Persist merged outgoing messages into the workflow session chat history for both streaming and non-streaming agent runs.
  • Refactor/extend unit tests to cover the expected output type and that outgoing messages are stored in history.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs Adds smoke coverage that outgoing messages are persisted to workflow session history; updates test inheritance.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AIAgentHostExecutorTests.cs Refactors shared assertions into a base class and adds targeted HandoffAgentExecutor output-type tests.
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowHostAgent.cs Persists merged responses into workflow session chat history after running (streaming + non-streaming).
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowChatHistoryProvider.cs Adds an accessor to retrieve all messages from session state (used by tests).
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffAgentExecutor.cs Emits a final AgentResponse in non-streaming mode while continuing to stream updates when configured.

You can also share your feedback on Copilot code review. Take the survey.

@lokitoth lokitoth force-pushed the dev/dotnet_workflow/handoff_outputs_missing_in_thread branch from 45f0d3e to f11fbf0 Compare March 17, 2026 15:12
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/handoff_outputs_missing_in_thread branch from f11fbf0 to 9665b2d Compare March 17, 2026 15:26
@lokitoth lokitoth changed the title .NET: fix: HandoffAgentExecutor does not output any reponse when non-streaming .NET: fix: HandoffAgentExecutor does not output any response when non-streaming Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET workflows Related to Workflows in agent-framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET - Assistant responses are not stored when using Workflow as Agent with Handoff orchestration

4 participants