.NET: Honor terminal workflow outputs in Workflow.AsAIAgent responses#6212
Open
ssccinng wants to merge 2 commits into
Open
.NET: Honor terminal workflow outputs in Workflow.AsAIAgent responses#6212ssccinng wants to merge 2 commits into
ssccinng wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adjusts workflow-as-agent behavior so the final AgentResponse prefers designated workflow outputs (rather than intermediate agent responses), and improves message metadata propagation.
Changes:
- Forward
AuthorNamefromChatMessageintoAgentResponseUpdate. - Update workflow output forwarding logic to include terminal outputs even when intermediate outputs are excluded.
- Change
WorkflowHostAgentresponse construction to prefer terminal workflow output updates; add a unit test for the expected behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs | Adds a regression test and a helper executor to validate that workflow-as-agent returns the designated output. |
| dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowSession.cs | Extends update creation to include AuthorName and refines which workflow outputs are forwarded into response updates. |
| dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowHostAgent.cs | Changes how final AgentResponse is computed, preferring terminal workflow outputs when present. |
Comment on lines
568
to
578
| bool includeTerminalOutput = this.IsTerminalOutput(output.ExecutorId); | ||
| if (!this._includeWorkflowOutputsInResponse | ||
| && !includeTerminalOutput) | ||
| { | ||
| goto default; | ||
| } | ||
|
|
||
| foreach (ChatMessage message in updateMessages) | ||
| foreach (ChatMessage message in this._includeWorkflowOutputsInResponse ? updateMessages ?? [] : []) | ||
| { | ||
| yield return this.CreateUpdate(this.LastResponseId, evt, message); | ||
| } |
Comment on lines
+119
to
+129
| WorkflowSession workflowSession = await this.UpdateSessionAsync(messages, session, cancellationToken).ConfigureAwait(false); | ||
| MessageMerger merger = new(); | ||
| List<AgentResponseUpdate> updates = []; | ||
|
|
||
| await foreach (AgentResponseUpdate update in workflowSession.InvokeStageAsync(cancellationToken) | ||
| .ConfigureAwait(false) | ||
| .WithCancellation(cancellationToken)) | ||
| { | ||
| merger.AddUpdate(update); | ||
| updates.Add(update); | ||
| } | ||
|
|
||
| AgentResponse response = merger.ComputeMerged(workflowSession.LastResponseId!, this.Id, this.Name); | ||
| AgentResponse response = this.CreateResponse(workflowSession.LastResponseId!, updates); |
Comment on lines
+179
to
+190
| private bool IsTerminalWorkflowOutputUpdate(AgentResponseUpdate update) | ||
| { | ||
| if (update.RawRepresentation is not WorkflowOutputEvent output | ||
| || output is AgentResponseUpdateEvent | ||
| || output is AgentResponseEvent) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return this._workflow.OutputExecutors.TryGetValue(output.ExecutorId, out HashSet<OutputTag>? tags) | ||
| && !tags.Contains(OutputTag.Intermediate); | ||
| } |
Comment on lines
+562
to
+566
| if (updateMessages == null | ||
| && updateContents == null) | ||
| { | ||
| goto default; | ||
| } |
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.
Fixes #6211.
Summary
Validation
ext dotnet test --project .\tests\Microsoft.Agents.AI.Workflows.UnitTests\Microsoft.Agents.AI.Workflows.UnitTests.csproj -v minimalResult: 1269 passed across
et472 and
et10.0.