.NET: feat: Implement return-to-previous routing in handoff workflow#4356
Merged
lokitoth merged 7 commits intoMar 26, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements return-to-previous routing in handoff workflows, allowing subsequent user turns to route directly back to the specialist agent that handled the previous turn, rather than always routing through the initial coordinator agent. The PR also deprecates HandoffsWorkflowBuilder in favor of HandoffWorkflowBuilder (without the 's').
Changes:
- Added
EnableReturnToPrevious()method to configure return-to-previous routing behavior - Introduced
HandoffsCurrentAgentTrackerto track the active agent across turns - Modified
HandoffStateto includeCurrentAgentIdfor routing decisions - Deprecated
HandoffsWorkflowBuilderand introducedHandoffWorkflowBuilderas the preferred name
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| HandoffsWorkflowBuilder.cs | Adds class hierarchy with obsolete HandoffsWorkflowBuilder and new HandoffWorkflowBuilder; implements EnableReturnToPrevious() method and dynamic routing logic |
| HandoffsCurrentAgentTracker.cs | New simple tracker class to maintain current agent ID across workflow turns |
| HandoffState.cs | Adds optional CurrentAgentId parameter to track active agent |
| HandoffsStartExecutor.cs | Updated to accept tracker and pass current agent ID to HandoffState |
| HandoffsEndExecutor.cs | Updated to accept tracker and update current agent ID at workflow completion |
| HandoffAgentExecutor.cs | Determines current agent ID based on handoff target and stores mapping |
| AgentWorkflowBuilderTests.cs | Comprehensive tests covering default behavior, enabled return-to-previous, and edge cases |
Comments suppressed due to low confidence (1)
dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs:39
- The constructor parameter name in the XML documentation incorrectly refers to
HandoffsWorkflowBuilder(with 's'), but this is now in the base classHandoffWorkflowBuilderCore. The documentation should be updated to refer to the correct class name or remain generic.
/// <summary>
/// Initializes a new instance of the <see cref="HandoffsWorkflowBuilder"/> class with no handoff relationships.
/// </summary>
/// <param name="initialAgent">The first agent to be invoked (prior to any handoff).</param>
internal HandoffsWorkflowBuilder(AIAgent initialAgent)
9fab1ea to
155372a
Compare
155372a to
5fce20d
Compare
5fce20d to
eab0951
Compare
eab0951 to
5f4f700
Compare
5f4f700 to
670f7ea
Compare
3f62312 to
2e9a164
Compare
- Also obsoletes HandoffsWorkflowBuilder => HandoffWorkflowBuilder (no "s")
Because the tracker was instance-shared between the start and end executors, it would be shared between all sessions, resulting in incorrect behaviour. The corect way to do this is to keep the data in a shared executor scope, which is per-session.
2e9a164 to
3d6fa76
Compare
westey-m
approved these changes
Mar 26, 2026
peibekwe
reviewed
Mar 26, 2026
peibekwe
approved these changes
Mar 26, 2026
Merged
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
It is often desirable to return control to the user in a handoff orchestration session without losing the context of which Agent is active (and returning to the original starting agent).
Description
EnableReturnToPrevious()toHandoffsWorkflowBuilderin .NET SDK #2504Contribution Checklist