mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.NET Workflows - Support "structured inputs" feature for declarative workflows (#2053)
This commit is contained in:
+3
-1
@@ -15,6 +15,7 @@ internal abstract class AgentProvider(IConfiguration configuration)
|
||||
public const string FunctionTool = "FUNCTIONTOOL";
|
||||
public const string Marketing = "MARKETING";
|
||||
public const string MathChat = "MATHCHAT";
|
||||
public const string InputArguments = "INPUTARGUMENTS";
|
||||
}
|
||||
|
||||
public static class Settings
|
||||
@@ -31,6 +32,7 @@ internal abstract class AgentProvider(IConfiguration configuration)
|
||||
Names.FunctionTool => new FunctionToolAgentProvider(configuration),
|
||||
Names.Marketing => new MarketingAgentProvider(configuration),
|
||||
Names.MathChat => new MathChatAgentProvider(configuration),
|
||||
Names.InputArguments => new PoemAgentProvider(configuration),
|
||||
_ => new TestAgentProvider(configuration),
|
||||
};
|
||||
|
||||
@@ -40,7 +42,7 @@ internal abstract class AgentProvider(IConfiguration configuration)
|
||||
|
||||
await foreach (AgentVersion agent in this.CreateAgentsAsync(foundryEndpoint))
|
||||
{
|
||||
Console.WriteLine($"Created agent: {agent.Name}:{agent.Version})");
|
||||
Console.WriteLine($"Created agent: {agent.Name}:{agent.Version}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Azure.AI.Agents;
|
||||
using Azure.Identity;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Shared.Foundry;
|
||||
|
||||
namespace Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests.Agents;
|
||||
|
||||
internal sealed class PoemAgentProvider(IConfiguration configuration) : AgentProvider(configuration)
|
||||
{
|
||||
protected override async IAsyncEnumerable<AgentVersion> CreateAgentsAsync(Uri foundryEndpoint)
|
||||
{
|
||||
AgentClient agentClient = new(foundryEndpoint, new AzureCliCredential());
|
||||
|
||||
yield return
|
||||
await agentClient.CreateAgentAsync(
|
||||
agentName: "PoemAgent",
|
||||
agentDefinition: this.DefinePoemAgent(),
|
||||
agentDescription: "Authors original poems");
|
||||
}
|
||||
|
||||
private PromptAgentDefinition DefinePoemAgent() =>
|
||||
new(this.GetSetting(Settings.FoundryModelMini))
|
||||
{
|
||||
Instructions =
|
||||
"""
|
||||
Write a one verse poem on the requested topic in the style of: {{style}}.
|
||||
""",
|
||||
StructuredInputs =
|
||||
{
|
||||
["style"] =
|
||||
new StructuredInputDefinition
|
||||
{
|
||||
IsRequired = false,
|
||||
DefaultValue = BinaryData.FromString(@"""haiku"""),
|
||||
Description = "The style of poem to write",
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
+4
-3
@@ -17,11 +17,12 @@ public sealed class DeclarativeWorkflowTest(ITestOutputHelper output) : Workflow
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("CheckSystem.yaml", "CheckSystem.json")]
|
||||
[InlineData("SendActivity.yaml", "SendActivity.json")]
|
||||
[InlineData("InvokeAgent.yaml", "InvokeAgent.json")]
|
||||
[InlineData("InvokeAgent.yaml", "InvokeAgent.json", true)]
|
||||
[InlineData("ConversationMessages.yaml", "ConversationMessages.json")]
|
||||
[InlineData("ConversationMessages.yaml", "ConversationMessages.json", true)]
|
||||
[InlineData("InputArguments.yaml", "InputArguments.json")]
|
||||
[InlineData("InvokeAgent.yaml", "InvokeAgent.json")]
|
||||
[InlineData("InvokeAgent.yaml", "InvokeAgent.json", true)]
|
||||
[InlineData("SendActivity.yaml", "SendActivity.json")]
|
||||
public Task ValidateCaseAsync(string workflowFileName, string testcaseFileName, bool externalConveration = false) =>
|
||||
this.RunWorkflowAsync(GetWorkflowPath(workflowFileName, isSample: false), testcaseFileName, externalConveration);
|
||||
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"description": "Authors a poem in the style specified by the input argument.",
|
||||
"setup": {
|
||||
"input": {
|
||||
"type": "String",
|
||||
"value": "Why is the sky blue?"
|
||||
}
|
||||
},
|
||||
"validation": {
|
||||
"conversation_count": 1,
|
||||
"min_action_count": 1,
|
||||
"min_response_count": 1,
|
||||
"min_message_count": 3,
|
||||
"actions": {
|
||||
"start": [
|
||||
"invoke_poem"
|
||||
],
|
||||
"final": [
|
||||
"invoke_poem"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
"min_response_count": 2,
|
||||
"max_response_count": 8,
|
||||
"min_message_count": 4,
|
||||
"max_message_count": 17,
|
||||
"max_message_count": -1,
|
||||
"actions": {
|
||||
"start": [
|
||||
],
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
kind: Workflow
|
||||
trigger:
|
||||
|
||||
kind: OnConversationStart
|
||||
id: workflow_test
|
||||
actions:
|
||||
|
||||
- kind: InvokeAzureAgent
|
||||
id: invoke_poem
|
||||
conversationId: =System.ConversationId
|
||||
agent:
|
||||
name: PoemAgent
|
||||
input:
|
||||
arguments:
|
||||
style: "ee cummings"
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Agents.AI.Workflows.Declarative.PowerFx;
|
||||
using Microsoft.Agents.AI.Workflows.Declarative.PowerFx.Functions;
|
||||
using Microsoft.Extensions.AI;
|
||||
using Microsoft.PowerFx.Types;
|
||||
|
||||
namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.PowerFx.Functions;
|
||||
|
||||
public sealed class AgentMessageTests
|
||||
{
|
||||
[Fact]
|
||||
public void Construct_Function()
|
||||
{
|
||||
AgentMessage function = new();
|
||||
Assert.NotNull(function);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Execute_ReturnsBlank_ForEmptyInput()
|
||||
{
|
||||
// Arrange
|
||||
StringValue sourceValue = FormulaValue.New(string.Empty);
|
||||
|
||||
// Act
|
||||
FormulaValue result = AgentMessage.Execute(sourceValue);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<BlankValue>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Execute_ReturnsExpectedRecord_ForNonEmptyInput()
|
||||
{
|
||||
const string Text = "Hello";
|
||||
FormulaValue sourceValue = FormulaValue.New(Text);
|
||||
StringValue stringValue = Assert.IsType<StringValue>(sourceValue);
|
||||
|
||||
FormulaValue result = AgentMessage.Execute(stringValue);
|
||||
|
||||
RecordValue recordResult = Assert.IsType<RecordValue>(result, exactMatch: false);
|
||||
|
||||
// Discriminator
|
||||
FormulaValue discriminator = recordResult.GetField(TypeSchema.Discriminator);
|
||||
StringValue discriminatorValue = Assert.IsType<StringValue>(discriminator);
|
||||
Assert.Equal(nameof(ChatMessage), discriminatorValue.Value);
|
||||
|
||||
// Role
|
||||
FormulaValue role = recordResult.GetField(TypeSchema.Message.Fields.Role);
|
||||
StringValue roleValue = Assert.IsType<StringValue>(role);
|
||||
Assert.Equal(ChatRole.Assistant.Value, roleValue.Value);
|
||||
|
||||
// Content table
|
||||
FormulaValue content = recordResult.GetField(TypeSchema.Message.Fields.Content);
|
||||
TableValue table = Assert.IsType<TableValue>(content, exactMatch: false);
|
||||
|
||||
List<RecordValue> rows = table.Rows.Select(value => value.Value).ToList();
|
||||
Assert.Single(rows);
|
||||
|
||||
StringValue contentType = Assert.IsType<StringValue>(rows[0].GetField(TypeSchema.Message.Fields.ContentType));
|
||||
Assert.Equal(TypeSchema.Message.ContentTypes.Text, contentType.Value);
|
||||
|
||||
StringValue contentValue = Assert.IsType<StringValue>(rows[0].GetField(TypeSchema.Message.Fields.ContentValue));
|
||||
Assert.Equal(Text, contentValue.Value);
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System;
|
||||
using Microsoft.Agents.AI.Workflows.Declarative.Extensions;
|
||||
using Microsoft.Agents.AI.Workflows.Declarative.PowerFx.Functions;
|
||||
using Microsoft.Extensions.AI;
|
||||
using Microsoft.PowerFx.Types;
|
||||
|
||||
namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.PowerFx.Functions;
|
||||
|
||||
public sealed class MessageTextTests
|
||||
{
|
||||
[Fact]
|
||||
public void Construct_Function()
|
||||
{
|
||||
MessageText.StringInput function1 = new();
|
||||
Assert.NotNull(function1);
|
||||
|
||||
MessageText.RecordInput function2 = new();
|
||||
Assert.NotNull(function2);
|
||||
|
||||
MessageText.TableInput function3 = new();
|
||||
Assert.NotNull(function3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Execute_ReturnsEmpty_ForEmptyInput()
|
||||
{
|
||||
// Arrange
|
||||
StringValue sourceValue = FormulaValue.New(string.Empty);
|
||||
|
||||
// Act
|
||||
FormulaValue result = MessageText.StringInput.Execute(sourceValue);
|
||||
|
||||
// Assert
|
||||
StringValue stringResult = Assert.IsType<StringValue>(result);
|
||||
Assert.Empty(stringResult.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Execute_ReturnsText_ForStringInput()
|
||||
{
|
||||
// Arrange
|
||||
StringValue sourceValue = FormulaValue.New("wowsie");
|
||||
|
||||
// Act
|
||||
FormulaValue result = MessageText.StringInput.Execute(sourceValue);
|
||||
|
||||
// Assert
|
||||
StringValue stringResult = Assert.IsType<StringValue>(result);
|
||||
Assert.Equal(sourceValue.Value, stringResult.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Execute_ReturnsText_ForMessageInput()
|
||||
{
|
||||
// Arrange
|
||||
RecordValue sourceValue = new ChatMessage(ChatRole.User, "test message").ToRecord();
|
||||
|
||||
// Act
|
||||
FormulaValue result = MessageText.RecordInput.Execute(sourceValue);
|
||||
|
||||
// Assert
|
||||
StringValue stringResult = Assert.IsType<StringValue>(result);
|
||||
Assert.Equal("test message", stringResult.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Execute_ReturnsEmpty_ForUnknownInput()
|
||||
{
|
||||
// Arrange
|
||||
RecordValue sourceValue = FormulaValue.NewRecordFromFields(new NamedValue("Anything", FormulaValue.New(333)));
|
||||
|
||||
// Act
|
||||
FormulaValue result = MessageText.RecordInput.Execute(sourceValue);
|
||||
|
||||
// Assert
|
||||
StringValue stringResult = Assert.IsType<StringValue>(result);
|
||||
Assert.Empty(stringResult.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Execute_ReturnsText_ForMessagesInput()
|
||||
{
|
||||
// Arrange
|
||||
TableValue sourceValue = new ChatMessage[]
|
||||
{
|
||||
new(ChatRole.User, "test message 1"),
|
||||
new(ChatRole.User, "test message 2"),
|
||||
}.ToTable();
|
||||
|
||||
// Act
|
||||
FormulaValue result = MessageText.TableInput.Execute(sourceValue);
|
||||
|
||||
// Assert
|
||||
StringValue stringResult = Assert.IsType<StringValue>(result);
|
||||
Assert.Equal("test message 1\ntest message 2", stringResult.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Execute_ReturnsEmpty_ForEmptyList()
|
||||
{
|
||||
// Arrange
|
||||
TableValue sourceValue = Array.Empty<ChatMessage>().ToTable();
|
||||
|
||||
// Act
|
||||
FormulaValue result = MessageText.TableInput.Execute(sourceValue);
|
||||
|
||||
// Assert
|
||||
StringValue stringResult = Assert.IsType<StringValue>(result);
|
||||
Assert.Empty(stringResult.Value);
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -22,11 +22,10 @@ public class UserMessageTests
|
||||
public void Execute_ReturnsBlank_ForEmptyInput()
|
||||
{
|
||||
// Arrange
|
||||
FormulaValue sourceValue = FormulaValue.New(string.Empty);
|
||||
StringValue stringValue = Assert.IsType<StringValue>(sourceValue);
|
||||
StringValue sourceValue = FormulaValue.New(string.Empty);
|
||||
|
||||
// Act
|
||||
FormulaValue result = UserMessage.Execute(stringValue);
|
||||
FormulaValue result = UserMessage.Execute(sourceValue);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<BlankValue>(result);
|
||||
|
||||
Reference in New Issue
Block a user