-
Notifications
You must be signed in to change notification settings - Fork 2.2k
.NET: feat: adds the executorId as an additional property when running the workflow as agent in dotnet #7934
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
Open
Vincent Biret (baywet)
wants to merge
9
commits into
main
Choose a base branch
from
feat/workflow-as-agent-executor-id-dotnet
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2022e83
feat: adds the executorId as an additional property when running the …
baywet 5366f35
chore: linting
baywet 50606c7
feat: adds the executor id to the response event to match behaviour a…
baywet 5b418c4
tests: adds a regression test to avoid value being wrong because of p…
baywet a96df63
tests: adds unit tests to cover AgentResponseEvent executor id mapping
baywet f975eab
feat: sets the executor id on the workflow session code path
baywet edf6435
chore: revert changes on failure paths
baywet 70b38a4
chore: reverts executorId on parts code path since it's never used
baywet acffd27
feat: adds executor id additional property on observability update
baywet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
14 changes: 14 additions & 0 deletions
14
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowAgentAdditionalProperties.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| namespace Microsoft.Agents.AI.Workflows; | ||
|
|
||
| /// <summary> | ||
| /// Defines additional property keys used by workflow-hosted agents. | ||
| /// </summary> | ||
| public static class WorkflowAgentAdditionalProperties | ||
| { | ||
| /// <summary> | ||
| /// The key for the workflow executor identifier that produced an agent response update. | ||
| /// </summary> | ||
| public const string ExecutorId = "executorId"; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -186,18 +186,27 @@ public AgentResponseUpdate CreateUpdate(string responseId, object raw, params AI | |
| }; | ||
| } | ||
|
|
||
| public AgentResponseUpdate CreateUpdate(string responseId, object raw, ChatMessage message) | ||
| public AgentResponseUpdate CreateUpdate(string responseId, object raw, ChatMessage message, string? executorId = default) | ||
| { | ||
| Throw.IfNull(message); | ||
|
|
||
| return new(message.Role, message.Contents) | ||
| return SetExecutorId(new(message.Role, message.Contents) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The behaviour pre-existed this change, Tao Chen (@TaoChenOSU) to confirm whether we should fix that or not |
||
| { | ||
| AuthorName = message.AuthorName, | ||
| CreatedAt = message.CreatedAt ?? DateTimeOffset.UtcNow, | ||
| MessageId = message.MessageId ?? Guid.NewGuid().ToString("N"), | ||
| ResponseId = responseId, | ||
| RawRepresentation = raw | ||
| }; | ||
| }, executorId); | ||
| } | ||
| private static AgentResponseUpdate SetExecutorId(AgentResponseUpdate update, string? executorId) | ||
| { | ||
| if (!string.IsNullOrEmpty(executorId)) | ||
| { | ||
| update.AdditionalProperties ??= []; | ||
| update.AdditionalProperties[WorkflowAgentAdditionalProperties.ExecutorId] = executorId; | ||
| } | ||
| return update; | ||
| } | ||
|
|
||
| private async ValueTask<ResumeRunResult> CreateOrResumeRunAsync(List<ChatMessage> messages, CancellationToken cancellationToken = default) | ||
|
|
@@ -499,15 +508,15 @@ IAsyncEnumerable<AgentResponseUpdate> InvokeStageAsync( | |
| await run.TrySendMessageAsync(new TurnToken(emitEvents: true)).ConfigureAwait(false); | ||
| } | ||
|
|
||
| AgentResponseUpdate CreateObservabilityUpdate(WorkflowEvent evt) | ||
| => new(ChatRole.Assistant, []) | ||
| AgentResponseUpdate CreateObservabilityUpdate(WorkflowEvent evt, string? executorId = default) | ||
| => SetExecutorId(new(ChatRole.Assistant, []) | ||
| { | ||
| CreatedAt = DateTimeOffset.UtcNow, | ||
| MessageId = Guid.NewGuid().ToString("N"), | ||
| Role = ChatRole.Assistant, | ||
| ResponseId = this.LastResponseId, | ||
| RawRepresentation = evt | ||
| }; | ||
| }, executorId); | ||
|
|
||
| await foreach (WorkflowEvent evt in run.WatchStreamAsync(blockOnPendingRequest: false, cancellationToken) | ||
| .ConfigureAwait(false) | ||
|
|
@@ -586,7 +595,7 @@ AgentResponseUpdate CreateObservabilityUpdate(WorkflowEvent evt) | |
| // the legacy default, keep today's behavior — gated by the include flag. | ||
| if (!Futures.EnableAgentResponseOutputTaggingAndFiltering && !this._includeWorkflowOutputsInResponse) | ||
| { | ||
| yield return CreateObservabilityUpdate(evt); | ||
| yield return CreateObservabilityUpdate(evt, agentResponse.ExecutorId); | ||
| break; | ||
| } | ||
|
|
||
|
|
@@ -610,13 +619,13 @@ AgentResponseUpdate CreateObservabilityUpdate(WorkflowEvent evt) | |
| } | ||
|
|
||
| emittedMessage = true; | ||
| yield return this.CreateUpdate(this.LastResponseId, evt, message); | ||
| yield return this.CreateUpdate(this.LastResponseId, evt, message, agentResponse.ExecutorId); | ||
| } | ||
| if (!emittedMessage && suppressedStreamedMessage) | ||
| { | ||
| // Preserve the completion event for observability after its correlated | ||
| // streamed content has already been forwarded. | ||
| yield return CreateObservabilityUpdate(evt); | ||
| yield return CreateObservabilityUpdate(evt, agentResponse.ExecutorId); | ||
| } | ||
| break; | ||
|
|
||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.