-
Notifications
You must be signed in to change notification settings - Fork 1.2k
.NET: feat: Implement return-to-previous routing in handoff workflow #4356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||
| // Copyright (c) Microsoft. All rights reserved. | ||||||
|
|
||||||
| using System; | ||||||
| using System.Collections.Generic; | ||||||
| using System.Linq; | ||||||
| using Microsoft.Agents.AI.Workflows.Specialized; | ||||||
|
|
@@ -8,22 +9,34 @@ | |||||
|
|
||||||
| namespace Microsoft.Agents.AI.Workflows; | ||||||
|
|
||||||
| /// <inheritdoc/> | ||||||
| [Obsolete("Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.")] | ||||||
|
||||||
| [Obsolete("Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.")] | |
| [Obsolete("Prefer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed in a future release before GA.")] |
Check failure on line 39 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net9.0, windows-latest, Debug)
Method must have a return type
Check failure on line 39 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net9.0, windows-latest, Debug)
Method must have a return type
Check failure on line 39 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net8.0, ubuntu-latest, Release)
Method must have a return type
Check failure on line 39 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net8.0, ubuntu-latest, Release)
Method must have a return type
Check failure on line 39 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net472, windows-latest, Release, true, integration)
Method must have a return type
Check failure on line 39 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net472, windows-latest, Release, true, integration)
Method must have a return type
Check failure on line 39 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net10.0, ubuntu-latest, Release, true, integration)
Method must have a return type
Check failure on line 67 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net9.0, windows-latest, Debug)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 67 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net8.0, ubuntu-latest, Release)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 67 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net472, windows-latest, Release, true, integration)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 67 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net10.0, ubuntu-latest, Release, true, integration)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 78 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net9.0, windows-latest, Debug)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 78 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net8.0, ubuntu-latest, Release)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 78 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net472, windows-latest, Release, true, integration)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 78 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net10.0, ubuntu-latest, Release, true, integration)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 89 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net9.0, windows-latest, Debug)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 89 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net8.0, ubuntu-latest, Release)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 89 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net472, windows-latest, Release, true, integration)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 89 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net10.0, ubuntu-latest, Release, true, integration)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 102 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net9.0, windows-latest, Debug)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 102 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net8.0, ubuntu-latest, Release)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 102 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net472, windows-latest, Release, true, integration)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 102 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net10.0, ubuntu-latest, Release, true, integration)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 130 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net9.0, windows-latest, Debug)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 130 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net8.0, ubuntu-latest, Release)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 130 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net472, windows-latest, Release, true, integration)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 130 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net10.0, ubuntu-latest, Release, true, integration)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 158 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net9.0, windows-latest, Debug)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 158 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net8.0, ubuntu-latest, Release)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 158 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net472, windows-latest, Release, true, integration)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Check failure on line 158 in dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs
GitHub Actions / dotnet-build-and-test (net10.0, ubuntu-latest, Release, true, integration)
'HandoffsWorkflowBuilder' is obsolete: 'Perfer HandoffWorkflowBuilder (no 's') instead, which has the same API but the preferred name. This will be removed if a future release before GA.'
Copilot
AI
Feb 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The HandoffsCurrentAgentTracker is created once per workflow and will be shared if the same workflow instance is reused across multiple sessions. This means the last active agent from one session could become the starting agent for a different session. This is likely fine for the common use case (one workflow instance per conversation session), but could cause unexpected behavior if workflows are reused. Consider documenting that workflows built with EnableReturnToPrevious should not be reused across different conversation sessions, or making the tracker session-scoped.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| namespace Microsoft.Agents.AI.Workflows.Specialized; | ||
|
|
||
| /// <summary>Tracks the current agent ID across turns when return-to-previous routing is enabled.</summary> | ||
| internal sealed class HandoffsCurrentAgentTracker | ||
| { | ||
| public string? CurrentAgentId { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,31 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Extensions.AI; | ||
|
|
||
| namespace Microsoft.Agents.AI.Workflows.Specialized; | ||
|
|
||
| /// <summary>Executor used at the end of a handoff workflow to raise a final completed event.</summary> | ||
| internal sealed class HandoffsEndExecutor() : Executor(ExecutorId, declareCrossRunShareable: true), IResettableExecutor | ||
| internal sealed class HandoffsEndExecutor(HandoffsCurrentAgentTracker? tracker = null) : Executor(ExecutorId, declareCrossRunShareable: true), IResettableExecutor | ||
| { | ||
| public const string ExecutorId = "HandoffEnd"; | ||
|
|
||
| protected override ProtocolBuilder ConfigureProtocol(ProtocolBuilder protocolBuilder) => | ||
| protocolBuilder.ConfigureRoutes(routeBuilder => routeBuilder.AddHandler<HandoffState>((handoff, context, cancellationToken) => | ||
| context.YieldOutputAsync(handoff.Messages, cancellationToken))) | ||
| this.HandleAsync(handoff, context, cancellationToken))) | ||
| .YieldsOutput<List<ChatMessage>>(); | ||
|
|
||
| private async ValueTask HandleAsync(HandoffState handoff, IWorkflowContext context, CancellationToken cancellationToken) | ||
| { | ||
| if (tracker is not null && handoff.CurrentAgentId is not null) | ||
| { | ||
| tracker.CurrentAgentId = handoff.CurrentAgentId; | ||
| } | ||
|
|
||
| await context.YieldOutputAsync(handoff.Messages, cancellationToken).ConfigureAwait(false); | ||
| } | ||
|
|
||
| public ValueTask ResetAsync() => default; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling error: "Perfer" should be "Prefer" in the obsolescence message.