Skip to content

.NET: fix: Add session support for Handoff-hosted Agents#5280

Merged
lokitoth merged 9 commits intomainfrom
dev/dotnet_workflow/fix_handoff_agent_session_handling
Apr 17, 2026
Merged

.NET: fix: Add session support for Handoff-hosted Agents#5280
lokitoth merged 9 commits intomainfrom
dev/dotnet_workflow/fix_handoff_agent_session_handling

Conversation

@lokitoth
Copy link
Copy Markdown
Member

Motivation and Context

In order to better support using Workflows hosted as AIAgents inside of Handoff workflows, we need to make proper use of AgentSession. This causes potential issues around checkpointing and making sure that we properly compute only the new incoming messages for each agent invocation.

Description

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 15, 2026
@lokitoth lokitoth added .NET agent orchestration Issues related to agent orchestration workflows Related to Workflows in agent-framework labels Apr 15, 2026
Copilot AI review requested due to automatic review settings April 15, 2026 18:13
@lokitoth lokitoth moved this to In Review in Agent Framework Apr 15, 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

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates the .NET handoff orchestration to use shared state + bookmarking and to keep a single AgentSession per workflow session, improving checkpointing behavior and ensuring only new messages are sent to underlying agents.

Changes:

  • Move handoff message accumulation into shared orchestration state (HandoffSharedState + MultiPartyConversation).
  • Add bookmarking support so each agent processes only new messages per invocation.
  • Introduce message filtering extraction and expand/adjust unit tests for handoff orchestration behavior.

Reviewed changes

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

Show a summary per file
File Description
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestRunContext.cs Adds a StateManager to test contexts and wires state operations to it.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/SampleSmokeTest.cs Updates Step12 expected-output computation to reflect bookmarking/session behavior.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/12_HandOff_HostAsAgent.cs Minor formatting adjustment in the Step12 sample.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/HandoffAgentExecutorTests.cs Initializes shared state for tests and adds a new HITL/subworkflow composition test.
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/MultiPartyConversation.cs New shared conversation buffer with bookmarking support.
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffState.cs Removes per-message payload from HandoffState (messages now live in shared state).
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffStartExecutor.cs Initializes/updates shared orchestration state and emits bookmark-driven HandoffState.
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffMessagesFilter.cs Extracts tool-call filtering logic into a dedicated type.
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffEndExecutor.cs Reads from shared state and yields the accumulated conversation at workflow end.
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffAgentExecutor.cs Adds agent-session use, bookmarking, and shared-state persistence for conversation messages.
dotnet/src/Microsoft.Agents.AI.Workflows/AIAgentsAbstractionsExtensions.cs Broadens role-changing helper to accept IEnumerable<ChatMessage>.

Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/MultiPartyConversation.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffAgentExecutor.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffAgentExecutor.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffAgentExecutor.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffAgentExecutor.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffEndExecutor.cs Outdated
Comment thread dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/SampleSmokeTest.cs Outdated
Comment thread dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/HandoffAgentExecutorTests.cs Outdated
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/fix_handoff_agent_session_handling branch from eefa1af to 8e28117 Compare April 16, 2026 13:28
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/fix_handoff_agent_session_handling branch from 8e28117 to 068f4b3 Compare April 16, 2026 13:43
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/fix_handoff_agent_session_handling branch from b6f0458 to f69b9b2 Compare April 16, 2026 14:32
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/fix_handoff_agent_session_handling branch from 1801d89 to f684fde Compare April 16, 2026 17:37
In order to better support using `Workflows` hosted as `AIAgents` inside of Handoff workflows, we need to make proper use of AgentSession. This causes potential issues around checkpointing and making sure that we properly compute only the new incoming messages for each agent invocation.
… methods

We cannot rely on implicit serialization through `HandoffHostState` because we are missing type information.
@lokitoth lokitoth force-pushed the dev/dotnet_workflow/fix_handoff_agent_session_handling branch from f684fde to 70d5aca Compare April 16, 2026 18:06
@lokitoth lokitoth added this pull request to the merge queue Apr 17, 2026
Merged via the queue into main with commit 5777ed2 Apr 17, 2026
21 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in Agent Framework Apr 17, 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: Done

Development

Successfully merging this pull request may close these issues.

.NET Workflows: RequestPort in Subworkflow (AsAgent) included in Parentworkflow (Handoff) never receives SendResponseAsync response

5 participants