.NET: fix: HandoffAgentExecutor does not output any response when non-streaming#4745
.NET: fix: HandoffAgentExecutor does not output any response when non-streaming#4745
Conversation
There was a problem hiding this comment.
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
AgentResponseoutput fromHandoffAgentExecutorwhenTurnToken.EmitEventsis nottrue(i.e., non-streaming). - Refactor existing
AIAgentHostExecutorunit tests to share common assertions via a new base class. - Add a new unit test validating
HandoffAgentExecutoroutput behavior acrossTurnToken.EmitEventsvalues.
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.
There was a problem hiding this comment.
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
HandoffAgentExecutorto emit anAgentResponsewhenTurnToken.EmitEventsis nottrue(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.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs
Show resolved
Hide resolved
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs
Outdated
Show resolved
Hide resolved
45f0d3e to
f11fbf0
Compare
f11fbf0 to
9665b2d
Compare
Motivation and Context
Due to needing custom logic and a more delocalized state, the
HandoffAgentExecutoris still separate from the generalAIAgentHostExecutor. The fixes made to theAIAgentHostExecutorto 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 toHandoffAgentExecutorin 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
HandoffAgentExecutorto always emit anAgentRunResponseif it is not configured toemitEventson theTurnToken, which should be more properly calledemitStreamingUpdatesnow thatAgentRunResponseEventexists.Fixes #2423
Contribution Checklist
Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.