-
Notifications
You must be signed in to change notification settings - Fork 2k
.NET: Fix declarative workflow regressions for hosted agents #5905
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fbb4c86
Fix declarative workflow regressions for hosted agents
alliscode 1baf4af
Hosted-agent HITL: persist session across previous_response_id chains…
alliscode ea5153c
Apply PropertyPath workaround to initialization path; share + tidy he…
alliscode c6e8291
Add tests for AgentProviderExtensions.InvokeAgentAsync autoSend behavior
alliscode bb11357
Surface SendActivity output via AgentResponseUpdateEvent
alliscode 28ee58a
Revert previous_response_id session-key fallback
alliscode 4e65b04
Set Foundry ProductContext per-executor instead of via PropertyPath w…
alliscode f545d77
Address review feedback on InvokeFunctionToolExecutor
alliscode c7aa990
Honor AutoSendIsDefaultValue when computing autoSend
alliscode 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
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
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
139 changes: 139 additions & 0 deletions
139
...osoft.Agents.AI.Workflows.Declarative.UnitTests/Extensions/AgentProviderExtensionsTest.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,139 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Agents.AI.Workflows.Declarative.Extensions; | ||
| using Microsoft.Agents.AI.Workflows.Declarative.Kit; | ||
| using Microsoft.Agents.AI.Workflows.Declarative.PowerFx; | ||
| using Microsoft.Agents.AI.Workflows.Declarative.UnitTests.ObjectModel; | ||
| using Microsoft.Agents.ObjectModel; | ||
| using Microsoft.Extensions.AI; | ||
| using Microsoft.PowerFx.Types; | ||
| using Moq; | ||
|
|
||
| namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.Extensions; | ||
|
|
||
| /// <summary> | ||
| /// Tests for <see cref="AgentProviderExtensions.InvokeAgentAsync"/>. | ||
| /// </summary> | ||
| public sealed class AgentProviderExtensionsTest(ITestOutputHelper output) : WorkflowActionExecutorTest(output) | ||
| { | ||
| private const string WorkflowConversationId = "workflow-conv-id"; | ||
| private const string AgentName = "test-agent"; | ||
|
|
||
| [Fact] | ||
| public Task AutoSendFalseOnWorkflowConversationSuppressesResponseEventsAsync() => | ||
| this.RunAsync(autoSend: false, conversationId: WorkflowConversationId, expectResponseEvents: false); | ||
|
alliscode marked this conversation as resolved.
|
||
|
|
||
| [Fact] | ||
| public Task AutoSendTrueOnWorkflowConversationEmitsResponseEventsAsync() => | ||
| this.RunAsync(autoSend: true, conversationId: WorkflowConversationId, expectResponseEvents: true); | ||
|
|
||
| [Fact] | ||
| public Task AutoSendFalseOnExternalConversationSuppressesResponseEventsAsync() => | ||
| this.RunAsync(autoSend: false, conversationId: "other-conv-id", expectResponseEvents: false); | ||
|
|
||
| [Fact] | ||
| public Task AutoSendTrueOnExternalConversationEmitsResponseEventsAndCopiesMessagesAsync() => | ||
| this.RunAsync( | ||
| autoSend: true, | ||
| conversationId: "other-conv-id", | ||
| expectResponseEvents: true, | ||
| expectCrossConversationCopy: true); | ||
|
|
||
| private async Task RunAsync( | ||
| bool autoSend, | ||
| string conversationId, | ||
| bool expectResponseEvents, | ||
| bool expectCrossConversationCopy = false) | ||
| { | ||
| // Arrange: seed the workflow conversation id so IsWorkflowConversation can recognize it. | ||
| this.State.Set( | ||
| SystemScope.Names.ConversationId, | ||
| FormulaValue.New(WorkflowConversationId), | ||
| VariableScopeNames.System); | ||
|
|
||
| MockAgentProvider mockProvider = new(); | ||
| AgentResponseUpdate[] updates = | ||
| [ | ||
| new(ChatRole.Assistant, "hello "), | ||
| new(ChatRole.Assistant, "world"), | ||
| ]; | ||
| mockProvider | ||
| .Setup(p => p.InvokeAgentAsync( | ||
| AgentName, | ||
| It.IsAny<string?>(), | ||
| It.IsAny<string?>(), | ||
| It.IsAny<IEnumerable<ChatMessage>?>(), | ||
| It.IsAny<IDictionary<string, object?>?>(), | ||
| It.IsAny<CancellationToken>())) | ||
| .Returns(ToAsyncEnumerableAsync(updates)); | ||
|
|
||
| List<(string ConversationId, ChatMessage Message)> copiedMessages = []; | ||
| mockProvider | ||
| .Setup(p => p.CreateMessageAsync( | ||
| It.IsAny<string>(), | ||
| It.IsAny<ChatMessage>(), | ||
| It.IsAny<CancellationToken>())) | ||
| .Returns<string, ChatMessage, CancellationToken>( | ||
| (convId, msg, _) => | ||
| { | ||
| copiedMessages.Add((convId, msg)); | ||
| return Task.FromResult(msg); | ||
| }); | ||
|
|
||
| string actionId = this.CreateActionId().Value; | ||
|
|
||
| // Act | ||
| WorkflowEvent[] events = | ||
| await this.ExecuteAsync( | ||
| actionId, | ||
| async (IWorkflowContext context, ActionExecutorResult _, CancellationToken cancellationToken) => | ||
| { | ||
| await mockProvider.Object.InvokeAgentAsync( | ||
| actionId, | ||
| context, | ||
| AgentName, | ||
| conversationId, | ||
| autoSend, | ||
| cancellationToken: cancellationToken).ConfigureAwait(false); | ||
| }); | ||
|
|
||
| // Assert | ||
| int updateEventCount = events.OfType<AgentResponseUpdateEvent>().Count(); | ||
| int responseEventCount = events.OfType<AgentResponseEvent>().Count(); | ||
|
|
||
| if (expectResponseEvents) | ||
| { | ||
| Assert.Equal(updates.Length, updateEventCount); | ||
| Assert.Equal(1, responseEventCount); | ||
| } | ||
| else | ||
| { | ||
| Assert.Equal(0, updateEventCount); | ||
| Assert.Equal(0, responseEventCount); | ||
| } | ||
|
|
||
| if (expectCrossConversationCopy) | ||
| { | ||
| Assert.NotEmpty(copiedMessages); | ||
| Assert.All(copiedMessages, c => Assert.Equal(WorkflowConversationId, c.ConversationId)); | ||
| } | ||
| else | ||
| { | ||
| Assert.Empty(copiedMessages); | ||
| } | ||
| } | ||
|
|
||
| private static async IAsyncEnumerable<AgentResponseUpdate> ToAsyncEnumerableAsync(IEnumerable<AgentResponseUpdate> updates) | ||
| { | ||
| foreach (AgentResponseUpdate update in updates) | ||
| { | ||
| yield return update; | ||
| } | ||
|
|
||
| await Task.CompletedTask; | ||
| } | ||
| } | ||
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.