mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Rename Agent to AIAgent and instroduce DisplayName (#201)
This commit is contained in:
@@ -13,7 +13,7 @@ namespace AgentConformance.IntegrationTests;
|
||||
/// </summary>
|
||||
public interface IAgentFixture : IAsyncLifetime
|
||||
{
|
||||
Agent Agent { get; }
|
||||
AIAgent Agent { get; }
|
||||
|
||||
Task<List<ChatMessage>> GetChatHistoryAsync(AgentThread thread);
|
||||
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ public class AzureAIAgentsPersistentFixture : IChatClientAgentFixture
|
||||
|
||||
public IChatClient ChatClient => this._agent.ChatClient;
|
||||
|
||||
public Agent Agent => this._agent;
|
||||
public AIAgent Agent => this._agent;
|
||||
|
||||
public async Task<List<ChatMessage>> GetChatHistoryAsync(AgentThread thread)
|
||||
{
|
||||
|
||||
@@ -19,10 +19,10 @@ namespace CopilotStudio.IntegrationTests;
|
||||
public class CopilotStudioFixture : IAgentFixture
|
||||
{
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
|
||||
private Agent _agent;
|
||||
private AIAgent _agent;
|
||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
|
||||
|
||||
public Agent Agent => this._agent;
|
||||
public AIAgent Agent => this._agent;
|
||||
|
||||
public Task<List<ChatMessage>> GetChatHistoryAsync(AgentThread thread)
|
||||
{
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ public class ConcurrentOrchestrationTests
|
||||
Assert.Contains("abc", response);
|
||||
}
|
||||
|
||||
private static async Task<string[]> ExecuteOrchestrationAsync(params Agent[] mockAgents)
|
||||
private static async Task<string[]> ExecuteOrchestrationAsync(params AIAgent[] mockAgents)
|
||||
{
|
||||
// Act
|
||||
ConcurrentOrchestration orchestration = new(mockAgents);
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class GroupChatOrchestrationTests
|
||||
Assert.Equal("lmn", response);
|
||||
}
|
||||
|
||||
private static async Task<string> ExecuteOrchestrationAsync(params Agent[] mockAgents)
|
||||
private static async Task<string> ExecuteOrchestrationAsync(params AIAgent[] mockAgents)
|
||||
{
|
||||
// Act
|
||||
GroupChatOrchestration orchestration = new(new RoundRobinGroupChatManager() { MaximumInvocationCount = mockAgents.Length }, mockAgents);
|
||||
|
||||
@@ -42,7 +42,7 @@ public sealed class HandoffOrchestrationTests : IDisposable
|
||||
public async Task HandoffOrchestrationWithSingleAgentAsync()
|
||||
{
|
||||
// Arrange
|
||||
Agent mockAgent1 =
|
||||
AIAgent mockAgent1 =
|
||||
this.CreateMockAgent(
|
||||
"Agent1",
|
||||
"Test Agent",
|
||||
@@ -59,17 +59,17 @@ public sealed class HandoffOrchestrationTests : IDisposable
|
||||
public async Task HandoffOrchestrationWithMultipleAgentsAsync()
|
||||
{
|
||||
// Arrange
|
||||
Agent mockAgent1 =
|
||||
AIAgent mockAgent1 =
|
||||
this.CreateMockAgent(
|
||||
"Agent1",
|
||||
"Test Agent",
|
||||
Responses.Handoff("Agent2"));
|
||||
Agent mockAgent2 =
|
||||
AIAgent mockAgent2 =
|
||||
this.CreateMockAgent(
|
||||
"Agent2",
|
||||
"Test Agent",
|
||||
Responses.Result("Final response"));
|
||||
Agent mockAgent3 =
|
||||
AIAgent mockAgent3 =
|
||||
this.CreateMockAgent(
|
||||
"Agent3",
|
||||
"Test Agent",
|
||||
|
||||
@@ -34,9 +34,9 @@ public class HandoffsTests
|
||||
// Arrange
|
||||
OrchestrationHandoffs handoffs = new("source");
|
||||
|
||||
Agent sourceAgent = CreateAgent("source", "Source Agent");
|
||||
Agent targetAgent1 = CreateAgent("target1", "Target Agent 1");
|
||||
Agent targetAgent2 = CreateAgent("target2", "Target Agent 2");
|
||||
AIAgent sourceAgent = CreateAgent("source", "Source Agent");
|
||||
AIAgent targetAgent1 = CreateAgent("target1", "Target Agent 1");
|
||||
AIAgent targetAgent2 = CreateAgent("target2", "Target Agent 2");
|
||||
|
||||
// Act
|
||||
handoffs.Add(sourceAgent, targetAgent1, targetAgent2);
|
||||
@@ -58,8 +58,8 @@ public class HandoffsTests
|
||||
// Arrange
|
||||
OrchestrationHandoffs handoffs = new("source");
|
||||
|
||||
Agent sourceAgent = CreateAgent("source", "Source Agent");
|
||||
Agent targetAgent = CreateAgent("target", "Target Agent");
|
||||
AIAgent sourceAgent = CreateAgent("source", "Source Agent");
|
||||
AIAgent targetAgent = CreateAgent("target", "Target Agent");
|
||||
string customDescription = "Custom handoff description";
|
||||
|
||||
// Act
|
||||
@@ -79,7 +79,7 @@ public class HandoffsTests
|
||||
// Arrange
|
||||
OrchestrationHandoffs handoffs = new("source");
|
||||
|
||||
Agent sourceAgent = CreateAgent("source", "Source Agent");
|
||||
AIAgent sourceAgent = CreateAgent("source", "Source Agent");
|
||||
string targetName = "targetName";
|
||||
string description = "Target description";
|
||||
|
||||
@@ -121,12 +121,12 @@ public class HandoffsTests
|
||||
// Arrange
|
||||
OrchestrationHandoffs handoffs = new("source1");
|
||||
|
||||
Agent source1 = CreateAgent("source1", "Source Agent 1");
|
||||
Agent source2 = CreateAgent("source2", "Source Agent 2");
|
||||
AIAgent source1 = CreateAgent("source1", "Source Agent 1");
|
||||
AIAgent source2 = CreateAgent("source2", "Source Agent 2");
|
||||
|
||||
Agent target1 = CreateAgent("target1", "Target Agent 1");
|
||||
Agent target2 = CreateAgent("target2", "Target Agent 2");
|
||||
Agent target3 = CreateAgent("target3", "Target Agent 3");
|
||||
AIAgent target1 = CreateAgent("target1", "Target Agent 1");
|
||||
AIAgent target2 = CreateAgent("target2", "Target Agent 2");
|
||||
AIAgent target3 = CreateAgent("target3", "Target Agent 3");
|
||||
|
||||
// Act
|
||||
handoffs.Add(source1, target1, target2);
|
||||
@@ -155,9 +155,9 @@ public class HandoffsTests
|
||||
public void StaticAddCreatesNewOrchestrationHandoffs()
|
||||
{
|
||||
// Arrange
|
||||
Agent source = CreateAgent("source", "Source Agent");
|
||||
Agent target1 = CreateAgent("target1", "Target Agent 1");
|
||||
Agent target2 = CreateAgent("target2", "Target Agent 2");
|
||||
AIAgent source = CreateAgent("source", "Source Agent");
|
||||
AIAgent target1 = CreateAgent("target1", "Target Agent 1");
|
||||
AIAgent target2 = CreateAgent("target2", "Target Agent 2");
|
||||
|
||||
// Act
|
||||
OrchestrationHandoffs handoffs =
|
||||
@@ -183,8 +183,8 @@ public class HandoffsTests
|
||||
// Arrange
|
||||
OrchestrationHandoffs handoffs = new("source-id");
|
||||
|
||||
Agent sourceAgent = CreateAgent(id: "source-id", name: null);
|
||||
Agent targetAgent = CreateAgent(id: "target-id", name: null, description: "Target Description");
|
||||
AIAgent sourceAgent = CreateAgent(id: "source-id", name: null);
|
||||
AIAgent targetAgent = CreateAgent(id: "target-id", name: null, description: "Target Description");
|
||||
|
||||
// Act
|
||||
handoffs.Add(sourceAgent, targetAgent);
|
||||
@@ -205,8 +205,8 @@ public class HandoffsTests
|
||||
// Arrange
|
||||
OrchestrationHandoffs handoffs = new("source");
|
||||
|
||||
Agent sourceAgent = CreateAgent("source", "Source Agent");
|
||||
Agent targetAgent1 = CreateAgent("target1", name: "target 1");
|
||||
AIAgent sourceAgent = CreateAgent("source", "Source Agent");
|
||||
AIAgent targetAgent1 = CreateAgent("target1", name: "target 1");
|
||||
|
||||
// Act
|
||||
handoffs.Add(sourceAgent, targetAgent1);
|
||||
@@ -227,8 +227,8 @@ public class HandoffsTests
|
||||
// Arrange
|
||||
OrchestrationHandoffs handoffs = new("source");
|
||||
|
||||
Agent sourceAgent = CreateAgent("source", "Source Agent");
|
||||
Agent targetAgent1 = CreateAgent("target1");
|
||||
AIAgent sourceAgent = CreateAgent("source", "Source Agent");
|
||||
AIAgent targetAgent1 = CreateAgent("target1");
|
||||
|
||||
// Act
|
||||
InvalidOperationException ex = Assert.Throws<InvalidOperationException>(() => handoffs.Add(sourceAgent, targetAgent1));
|
||||
|
||||
@@ -11,9 +11,9 @@ using Moq;
|
||||
namespace Microsoft.Agents.Orchestration.UnitTest;
|
||||
|
||||
/// <summary>
|
||||
/// Mock definition of <see cref="Agent"/>.
|
||||
/// Mock definition of <see cref="AIAgent"/>.
|
||||
/// </summary>
|
||||
internal sealed class MockAgent(int index) : Agent
|
||||
internal sealed class MockAgent(int index) : AIAgent
|
||||
{
|
||||
public static MockAgent CreateWithResponse(int index, string response)
|
||||
{
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class SequentialOrchestrationTests
|
||||
Assert.Equal("lmn", response);
|
||||
}
|
||||
|
||||
private static async Task<string> ExecuteOrchestrationAsync(params Agent[] mockAgents)
|
||||
private static async Task<string> ExecuteOrchestrationAsync(params AIAgent[] mockAgents)
|
||||
{
|
||||
// Act
|
||||
SequentialOrchestration orchestration = new(mockAgents);
|
||||
|
||||
@@ -11,11 +11,11 @@ using Moq.Protected;
|
||||
namespace Microsoft.Extensions.AI.Agents.Abstractions.UnitTests;
|
||||
|
||||
/// <summary>
|
||||
/// Unit tests for the <see cref="Agent"/> class.
|
||||
/// Unit tests for the <see cref="AIAgent"/> class.
|
||||
/// </summary>
|
||||
public class AgentTests
|
||||
{
|
||||
private readonly Mock<Agent> _agentMock;
|
||||
private readonly Mock<AIAgent> _agentMock;
|
||||
private readonly Mock<AgentThread> _agentThreadMock;
|
||||
private readonly AgentRunResponse _invokeResponse = new();
|
||||
private readonly List<AgentRunResponseUpdate> _invokeStreamingResponses = [];
|
||||
@@ -30,7 +30,7 @@ public class AgentTests
|
||||
this._invokeResponse = new AgentRunResponse(new ChatMessage(ChatRole.Assistant, "Hi"));
|
||||
this._invokeStreamingResponses.Add(new AgentRunResponseUpdate(ChatRole.Assistant, "Hi"));
|
||||
|
||||
this._agentMock = new Mock<Agent>() { CallBase = true };
|
||||
this._agentMock = new Mock<AIAgent>() { CallBase = true };
|
||||
this._agentMock
|
||||
.Setup(x => x.RunAsync(
|
||||
It.IsAny<IReadOnlyCollection<ChatMessage>>(),
|
||||
@@ -258,9 +258,9 @@ public class AgentTests
|
||||
public abstract class TestAgentThread : AgentThread;
|
||||
|
||||
/// <summary>
|
||||
/// Mock class to test the <see cref="Agent.ValidateOrCreateThreadType{TThreadType}"/> method.
|
||||
/// Mock class to test the <see cref="AIAgent.ValidateOrCreateThreadType{TThreadType}"/> method.
|
||||
/// </summary>
|
||||
private sealed class MockAgent : Agent
|
||||
private sealed class MockAgent : AIAgent
|
||||
{
|
||||
public new TThreadType ValidateOrCreateThreadType<TThreadType>(
|
||||
AgentThread? thread,
|
||||
|
||||
@@ -402,7 +402,7 @@ public class OpenTelemetryAgentTests
|
||||
public void WithOpenTelemetry_ExtensionMethod_CreatesOpenTelemetryAgent()
|
||||
{
|
||||
// Arrange
|
||||
var mockAgent = new Mock<Agent>();
|
||||
var mockAgent = new Mock<AIAgent>();
|
||||
mockAgent.Setup(a => a.Id).Returns("test-id");
|
||||
mockAgent.Setup(a => a.Name).Returns("TestAgent");
|
||||
|
||||
@@ -434,9 +434,9 @@ public class OpenTelemetryAgentTests
|
||||
mockAgent.Verify(a => a.RunAsync(messages, null, null, It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
|
||||
private static Mock<Agent> CreateMockAgent(bool throwError)
|
||||
private static Mock<AIAgent> CreateMockAgent(bool throwError)
|
||||
{
|
||||
var mockAgent = new Mock<Agent>();
|
||||
var mockAgent = new Mock<AIAgent>();
|
||||
mockAgent.Setup(a => a.Id).Returns("test-agent-id");
|
||||
mockAgent.Setup(a => a.Name).Returns("TestAgent");
|
||||
mockAgent.Setup(a => a.Description).Returns("Test Description");
|
||||
@@ -465,9 +465,9 @@ public class OpenTelemetryAgentTests
|
||||
return mockAgent;
|
||||
}
|
||||
|
||||
private static Mock<Agent> CreateMockStreamingAgent(bool throwError)
|
||||
private static Mock<AIAgent> CreateMockStreamingAgent(bool throwError)
|
||||
{
|
||||
var mockAgent = new Mock<Agent>();
|
||||
var mockAgent = new Mock<AIAgent>();
|
||||
mockAgent.Setup(a => a.Id).Returns("test-agent-id");
|
||||
mockAgent.Setup(a => a.Name).Returns("TestAgent");
|
||||
mockAgent.Setup(a => a.Description).Returns("Test Description");
|
||||
@@ -531,7 +531,7 @@ public class OpenTelemetryAgentTests
|
||||
public void Constructor_WithParameters_SetsProperties()
|
||||
{
|
||||
// Arrange
|
||||
var mockAgent = new Mock<Agent>();
|
||||
var mockAgent = new Mock<AIAgent>();
|
||||
mockAgent.Setup(a => a.Id).Returns("test-id");
|
||||
mockAgent.Setup(a => a.Name).Returns("TestAgent");
|
||||
mockAgent.Setup(a => a.Description).Returns("Test Description");
|
||||
@@ -553,7 +553,7 @@ public class OpenTelemetryAgentTests
|
||||
{
|
||||
// Arrange
|
||||
var mockThread = new Mock<AgentThread>().Object;
|
||||
var mockAgent = new Mock<Agent>();
|
||||
var mockAgent = new Mock<AIAgent>();
|
||||
mockAgent.Setup(a => a.GetNewThread()).Returns(mockThread);
|
||||
|
||||
using var telemetryAgent = new OpenTelemetryAgent(mockAgent.Object);
|
||||
@@ -570,7 +570,7 @@ public class OpenTelemetryAgentTests
|
||||
public void Dispose_DisposesResources()
|
||||
{
|
||||
// Arrange
|
||||
var mockAgent = new Mock<Agent>();
|
||||
var mockAgent = new Mock<AIAgent>();
|
||||
var telemetryAgent = new OpenTelemetryAgent(mockAgent.Object);
|
||||
|
||||
// Act & Assert - Should not throw
|
||||
@@ -589,7 +589,7 @@ public class OpenTelemetryAgentTests
|
||||
.AddInMemoryExporter(activities)
|
||||
.Build();
|
||||
|
||||
var mockAgent = new Mock<Agent>();
|
||||
var mockAgent = new Mock<AIAgent>();
|
||||
mockAgent.Setup(a => a.Id).Returns("test-agent-id");
|
||||
mockAgent.Setup(a => a.Name).Returns("TestAgent");
|
||||
|
||||
@@ -631,7 +631,7 @@ public class OpenTelemetryAgentTests
|
||||
.AddInMemoryExporter(activities)
|
||||
.Build();
|
||||
|
||||
var mockAgent = new Mock<Agent>();
|
||||
var mockAgent = new Mock<AIAgent>();
|
||||
mockAgent.Setup(a => a.Id).Returns("test-agent-id");
|
||||
mockAgent.Setup(a => a.Name).Returns((string?)null); // Null name
|
||||
|
||||
@@ -665,7 +665,7 @@ public class OpenTelemetryAgentTests
|
||||
.AddInMemoryExporter(activities)
|
||||
.Build();
|
||||
|
||||
var mockAgent = new Mock<Agent>();
|
||||
var mockAgent = new Mock<AIAgent>();
|
||||
mockAgent.Setup(a => a.Id).Returns("test-agent-id");
|
||||
mockAgent.Setup(a => a.Name).Returns("TestAgent");
|
||||
|
||||
@@ -899,7 +899,7 @@ public class OpenTelemetryAgentTests
|
||||
.AddInMemoryExporter(exportedMetrics)
|
||||
.Build();
|
||||
|
||||
var mockAgent = new Mock<Agent>();
|
||||
var mockAgent = new Mock<AIAgent>();
|
||||
mockAgent.Setup(a => a.Id).Returns("test-agent-id");
|
||||
mockAgent.Setup(a => a.Name).Returns("TestAgent");
|
||||
|
||||
@@ -981,7 +981,7 @@ public class OpenTelemetryAgentTests
|
||||
.AddInMemoryExporter(exportedMetrics)
|
||||
.Build();
|
||||
|
||||
var mockAgent = new Mock<Agent>();
|
||||
var mockAgent = new Mock<AIAgent>();
|
||||
mockAgent.Setup(a => a.Id).Returns("test-agent-id");
|
||||
mockAgent.Setup(a => a.Name).Returns("TestAgent");
|
||||
|
||||
@@ -1028,7 +1028,7 @@ public class OpenTelemetryAgentTests
|
||||
.AddInMemoryExporter(activities)
|
||||
.Build();
|
||||
|
||||
var mockAgent = new Mock<Agent>();
|
||||
var mockAgent = new Mock<AIAgent>();
|
||||
mockAgent.Setup(a => a.Id).Returns("test-agent-id");
|
||||
mockAgent.Setup(a => a.Name).Returns("TestAgent");
|
||||
mockAgent.Setup(a => a.Description).Returns((string?)null); // Null description
|
||||
|
||||
@@ -22,7 +22,7 @@ public class OpenAIAssistantFixture : IChatClientAgentFixture
|
||||
private ChatClientAgent _agent;
|
||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
|
||||
|
||||
public Agent Agent => this._agent;
|
||||
public AIAgent Agent => this._agent;
|
||||
|
||||
public IChatClient ChatClient => this._agent.ChatClient;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class OpenAIChatCompletionFixture : IChatClientAgentFixture
|
||||
}
|
||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
|
||||
|
||||
public Agent Agent => this._agent;
|
||||
public AIAgent Agent => this._agent;
|
||||
|
||||
public IChatClient ChatClient => this._agent.ChatClient;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public class OpenAIResponseFixture(bool store) : IChatClientAgentFixture
|
||||
private ChatClientAgent _agent;
|
||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
|
||||
|
||||
public Agent Agent => this._agent;
|
||||
public AIAgent Agent => this._agent;
|
||||
|
||||
public IChatClient ChatClient => this._agent.ChatClient;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user