Rename Agent to AIAgent and instroduce DisplayName (#201)

This commit is contained in:
westey
2025-07-18 16:43:38 +01:00
committed by GitHub
Unverified
parent 6e57489a44
commit fc999e2be8
37 changed files with 106 additions and 98 deletions
@@ -31,7 +31,7 @@ public sealed class ChatClientAgent_With_AzureAIAgentsPersistent(ITestOutputHelp
instructions: JokerInstructions);
// Get a local proxy for the agent to work with.
Agent agent = await persistentAgentsClient.GetRunnableAgentAsync(createPersistentAgentResponse.Value.Id);
AIAgent agent = await persistentAgentsClient.GetRunnableAgentAsync(createPersistentAgentResponse.Value.Id);
// Start a new thread for the agent conversation.
AgentThread thread = agent.GetNewThread();
@@ -33,7 +33,7 @@ public sealed class Step01_ChatClientAgent_Running(ITestOutputHelper output) : A
IChatClient chatClient = base.GetChatClient(provider);
// Define the agent
Agent agent = new ChatClientAgent(chatClient, ParrotInstructions, ParrotName);
AIAgent agent = new ChatClientAgent(chatClient, ParrotInstructions, ParrotName);
// Invoke the agent and output the text result.
Console.WriteLine(await agent.RunAsync("Fortune favors the bold."));
@@ -24,7 +24,7 @@ public abstract class AgentActor : OrchestrationActor
/// <param name="context">The orchestration context.</param>
/// <param name="agent">An <see cref="Agent"/>.</param>
/// <param name="logger">The logger to use for the actor</param>
protected AgentActor(ActorId id, IAgentRuntime runtime, OrchestrationContext context, Agent agent, ILogger? logger = null)
protected AgentActor(ActorId id, IAgentRuntime runtime, OrchestrationContext context, AIAgent agent, ILogger? logger = null)
: base(id, runtime, context, agent.Description, logger)
{
this.Agent = agent;
@@ -34,7 +34,7 @@ public abstract class AgentActor : OrchestrationActor
/// <summary>
/// Gets the associated agent.
/// </summary>
protected Agent Agent { get; }
protected AIAgent Agent { get; }
/// <summary>
/// Gets the current conversation thread used during agent communication.
@@ -32,7 +32,7 @@ public abstract partial class AgentOrchestration<TInput, TOutput>
/// Initializes a new instance of the <see cref="AgentOrchestration{TInput, TOutput}"/> class.
/// </summary>
/// <param name="members">Specifies the member agents or orchestrations participating in this orchestration.</param>
protected AgentOrchestration(params Agent[] members)
protected AgentOrchestration(params AIAgent[] members)
{
_ = Throw.IfNull(members);
@@ -87,7 +87,7 @@ public abstract partial class AgentOrchestration<TInput, TOutput>
/// <summary>
/// Gets the list of member targets involved in the orchestration.
/// </summary>
protected IReadOnlyList<Agent> Members { get; }
protected IReadOnlyList<AIAgent> Members { get; }
/// <summary>
/// Orchestration identifier without generic parameters for use in
@@ -22,10 +22,10 @@ internal sealed class ConcurrentActor : AgentActor
/// <param name="id">The unique identifier of the agent.</param>
/// <param name="runtime">The runtime associated with the agent.</param>
/// <param name="context">The orchestration context.</param>
/// <param name="agent">An <see cref="Agent"/>.</param>
/// <param name="agent">An <see cref="AIAgent"/>.</param>
/// <param name="resultActor">Identifies the actor collecting results.</param>
/// <param name="logger">The logger to use for the actor</param>
public ConcurrentActor(ActorId id, IAgentRuntime runtime, OrchestrationContext context, Agent agent, ActorType resultActor, ILogger<ConcurrentActor>? logger = null)
public ConcurrentActor(ActorId id, IAgentRuntime runtime, OrchestrationContext context, AIAgent agent, ActorType resultActor, ILogger<ConcurrentActor>? logger = null)
: base(id, runtime, context, agent, logger)
{
this._handoffActor = resultActor;
@@ -16,7 +16,7 @@ public sealed class ConcurrentOrchestration : ConcurrentOrchestration<string, st
/// Initializes a new instance of the <see cref="ConcurrentOrchestration"/> class.
/// </summary>
/// <param name="members">The agents to be orchestrated.</param>
public ConcurrentOrchestration(params Agent[] members)
public ConcurrentOrchestration(params AIAgent[] members)
: base(members)
{
this.ResultTransform =
@@ -23,7 +23,7 @@ public class ConcurrentOrchestration<TInput, TOutput>
/// Initializes a new instance of the <see cref="ConcurrentOrchestration{TInput, TOutput}"/> class.
/// </summary>
/// <param name="agents">The agents participating in the orchestration.</param>
public ConcurrentOrchestration(params Agent[] agents)
public ConcurrentOrchestration(params AIAgent[] agents)
: base(agents)
{
}
@@ -52,7 +52,7 @@ public class ConcurrentOrchestration<TInput, TOutput>
// Register member actors - All agents respond to the same message.
int agentCount = 0;
foreach (Agent agent in this.Members)
foreach (AIAgent agent in this.Members)
{
++agentCount;
@@ -23,9 +23,9 @@ internal sealed class GroupChatAgentActor : AgentActor
/// <param name="id">The unique identifier of the agent.</param>
/// <param name="runtime">The runtime associated with the agent.</param>
/// <param name="context">The orchestration context.</param>
/// <param name="agent">An <see cref="Agent"/>.</param>
/// <param name="agent">An <see cref="AIAgent"/>.</param>
/// <param name="logger">The logger to use for the actor</param>
public GroupChatAgentActor(ActorId id, IAgentRuntime runtime, OrchestrationContext context, Agent agent, ILogger<GroupChatAgentActor>? logger = null)
public GroupChatAgentActor(ActorId id, IAgentRuntime runtime, OrchestrationContext context, AIAgent agent, ILogger<GroupChatAgentActor>? logger = null)
: base(id, runtime, context, agent, logger)
{
this._cache = [];
@@ -14,7 +14,7 @@ public sealed class GroupChatOrchestration : GroupChatOrchestration<string, stri
/// </summary>
/// <param name="manager">The manages the flow of the group-chat.</param>
/// <param name="members">The agents to be orchestrated.</param>
public GroupChatOrchestration(GroupChatManager manager, params Agent[] members)
public GroupChatOrchestration(GroupChatManager manager, params AIAgent[] members)
: base(manager, members)
{
}
@@ -26,7 +26,7 @@ public class GroupChatOrchestration<TInput, TOutput> :
/// </summary>
/// <param name="manager">The manages the flow of the group-chat.</param>
/// <param name="agents">The agents participating in the orchestration.</param>
public GroupChatOrchestration(GroupChatManager manager, params Agent[] agents)
public GroupChatOrchestration(GroupChatManager manager, params AIAgent[] agents)
: base(agents)
{
Throw.IfNull(manager, nameof(manager));
@@ -51,7 +51,7 @@ public class GroupChatOrchestration<TInput, TOutput> :
int agentCount = 0;
GroupChatTeam team = [];
foreach (Agent agent in this.Members)
foreach (AIAgent agent in this.Members)
{
++agentCount;
ActorType agentType = await RegisterAgentAsync(agent, agentCount).ConfigureAwait(false);
@@ -79,7 +79,7 @@ public class GroupChatOrchestration<TInput, TOutput> :
return managerType;
ValueTask<ActorType> RegisterAgentAsync(Agent agent, int agentCount) =>
ValueTask<ActorType> RegisterAgentAsync(AIAgent agent, int agentCount) =>
runtime.RegisterOrchestrationAgentAsync(
this.FormatAgentType(context.Topic, $"Agent_{agentCount}"),
(agentId, runtime) =>
@@ -32,7 +32,7 @@ internal sealed partial class HandoffActor : AgentActor
/// <param name="id">The unique identifier of the agent.</param>
/// <param name="runtime">The runtime associated with the agent.</param>
/// <param name="context">The orchestration context.</param>
/// <param name="agent">An <see cref="Agent"/>.</param>>
/// <param name="agent">An <see cref="AIAgent"/>.</param>>
/// <param name="handoffs">The handoffs available to this agent</param>
/// <param name="resultHandoff">The handoff agent for capturing the result.</param>
/// <param name="logger">The logger to use for the actor</param>
@@ -15,7 +15,7 @@ public sealed class HandoffOrchestration : HandoffOrchestration<string, string>
/// </summary>
/// <param name="handoffs">Defines the handoff connections for each agent.</param>
/// <param name="members">The agents to be orchestrated.</param>
public HandoffOrchestration(OrchestrationHandoffs handoffs, params Agent[] members)
public HandoffOrchestration(OrchestrationHandoffs handoffs, params AIAgent[] members)
: base(handoffs, members)
{
}
@@ -24,7 +24,7 @@ public class HandoffOrchestration<TInput, TOutput> : AgentOrchestration<TInput,
/// </summary>
/// <param name="handoffs">Defines the handoff connections for each agent.</param>
/// <param name="agents">Additional agents participating in the orchestration that weren't passed to <paramref name="handoffs"/>.</param>
public HandoffOrchestration(OrchestrationHandoffs handoffs, params Agent[] agents) : base(
public HandoffOrchestration(OrchestrationHandoffs handoffs, params AIAgent[] agents) : base(
agents is { Length: 0 } ? handoffs.Agents.ToArray() :
handoffs.Agents is { Count: 0 } ? agents :
handoffs.Agents.Concat(agents).Distinct().ToArray())
@@ -74,7 +74,7 @@ public class HandoffOrchestration<TInput, TOutput> : AgentOrchestration<TInput,
ActorType agentType = outputType;
for (int index = this.Members.Count - 1; index >= 0; --index)
{
Agent agent = this.Members[index];
AIAgent agent = this.Members[index];
HandoffLookup map = [];
handoffMap[agent.Name ?? agent.Id] = map;
agentType =
@@ -36,7 +36,7 @@ public sealed class OrchestrationHandoffs : Dictionary<string, AgentHandoffs>
/// Initializes a new instance of the <see cref="OrchestrationHandoffs"/> class with no handoff relationships.
/// </summary>
/// <param name="firstAgent">The first agent to be invoked (prior to any handoff).</param>
public OrchestrationHandoffs(Agent firstAgent)
public OrchestrationHandoffs(AIAgent firstAgent)
: this(firstAgent.Name ?? firstAgent.Id)
{
this.Agents.Add(firstAgent);
@@ -63,7 +63,7 @@ public sealed class OrchestrationHandoffs : Dictionary<string, AgentHandoffs>
/// </summary>
/// <param name="source">The source agent.</param>
/// <returns>The updated <see cref="OrchestrationHandoffs"/> instance.</returns>
public static OrchestrationHandoffs StartWith(Agent source) => new(source);
public static OrchestrationHandoffs StartWith(AIAgent source) => new(source);
/// <summary>
/// Adds handoff relationships from a source agent to one or more target agents.
@@ -72,13 +72,13 @@ public sealed class OrchestrationHandoffs : Dictionary<string, AgentHandoffs>
/// <param name="source">The source agent.</param>
/// <param name="targets">The target agents to add as handoff targets for the source agent.</param>
/// <returns>The updated <see cref="OrchestrationHandoffs"/> instance.</returns>
public OrchestrationHandoffs Add(Agent source, params Agent[] targets)
public OrchestrationHandoffs Add(AIAgent source, params AIAgent[] targets)
{
string key = source.Name ?? source.Id;
AgentHandoffs agentHandoffs = this.GetAgentHandoffs(key);
foreach (Agent target in targets)
foreach (AIAgent target in targets)
{
if (string.IsNullOrWhiteSpace(target.Description) && string.IsNullOrWhiteSpace(target.Name))
{
@@ -101,7 +101,7 @@ public sealed class OrchestrationHandoffs : Dictionary<string, AgentHandoffs>
/// <param name="target">The target agent.</param>
/// <param name="description">The handoff description.</param>
/// <returns>The updated <see cref="OrchestrationHandoffs"/> instance.</returns>
public OrchestrationHandoffs Add(Agent source, Agent target, string description)
public OrchestrationHandoffs Add(AIAgent source, AIAgent target, string description)
=> this.Add(source.Name ?? source.Id, target.Name ?? target.Id, description);
/// <summary>
@@ -111,7 +111,7 @@ public sealed class OrchestrationHandoffs : Dictionary<string, AgentHandoffs>
/// <param name="targetName">The target agent's name or ID.</param>
/// <param name="description">The handoff description.</param>
/// <returns>The updated <see cref="OrchestrationHandoffs"/> instance.</returns>
public OrchestrationHandoffs Add(Agent source, string targetName, string description)
public OrchestrationHandoffs Add(AIAgent source, string targetName, string description)
=> this.Add(source.Name ?? source.Id, targetName, description);
/// <summary>
@@ -139,7 +139,7 @@ public sealed class OrchestrationHandoffs : Dictionary<string, AgentHandoffs>
return agentHandoffs;
}
internal HashSet<Agent> Agents { get; } = [];
internal HashSet<AIAgent> Agents { get; } = [];
}
/// <summary>
@@ -23,10 +23,10 @@ internal sealed class SequentialActor : AgentActor
/// <param name="id">The unique identifier of the agent.</param>
/// <param name="runtime">The runtime associated with the agent.</param>
/// <param name="context">The orchestration context.</param>
/// <param name="agent">An <see cref="Agent"/>.</param>
/// <param name="agent">An <see cref="AIAgent"/>.</param>
/// <param name="nextAgent">The identifier of the next agent for which to handoff the result</param>
/// <param name="logger">The logger to use for the actor</param>
public SequentialActor(ActorId id, IAgentRuntime runtime, OrchestrationContext context, Agent agent, ActorType nextAgent, ILogger<SequentialActor>? logger = null)
public SequentialActor(ActorId id, IAgentRuntime runtime, OrchestrationContext context, AIAgent agent, ActorType nextAgent, ILogger<SequentialActor>? logger = null)
: base(id, runtime, context, agent, logger)
{
logger?.LogInformation("ACTOR {ActorId} {NextAgent}", this.Id, nextAgent);
@@ -14,7 +14,7 @@ public sealed class SequentialOrchestration : SequentialOrchestration<string, st
/// Initializes a new instance of the <see cref="SequentialOrchestration"/> class.
/// </summary>
/// <param name="members">The agents to be orchestrated.</param>
public SequentialOrchestration(params Agent[] members)
public SequentialOrchestration(params AIAgent[] members)
: base(members)
{
}
@@ -20,7 +20,7 @@ public class SequentialOrchestration<TInput, TOutput> : AgentOrchestration<TInpu
/// Initializes a new instance of the <see cref="SequentialOrchestration{TInput, TOutput}"/> class.
/// </summary>
/// <param name="agents">The agents participating in the orchestration.</param>
public SequentialOrchestration(params Agent[] agents)
public SequentialOrchestration(params AIAgent[] agents)
: base(agents)
{
}
@@ -44,7 +44,7 @@ public class SequentialOrchestration<TInput, TOutput> : AgentOrchestration<TInpu
ActorType nextAgent = outputType;
for (int index = this.Members.Count - 1; index >= 0; --index)
{
Agent agent = this.Members[index];
AIAgent agent = this.Members[index];
nextAgent = await RegisterAgentAsync(agent, index, nextAgent).ConfigureAwait(false);
logger.LogRegisterActor(this.OrchestrationLabel, nextAgent, "MEMBER", index + 1);
@@ -52,7 +52,7 @@ public class SequentialOrchestration<TInput, TOutput> : AgentOrchestration<TInpu
return nextAgent;
ValueTask<ActorType> RegisterAgentAsync(Agent agent, int index, ActorType nextAgent) =>
ValueTask<ActorType> RegisterAgentAsync(AIAgent agent, int index, ActorType nextAgent) =>
runtime.RegisterOrchestrationAgentAsync(
this.GetAgentType(context.Topic, index),
(agentId, runtime) =>
@@ -12,7 +12,7 @@ namespace Microsoft.Extensions.AI.Agents;
/// Base abstraction for all agents. An agent instance may participate in one or more conversations.
/// A conversation may include one or more agents.
/// </summary>
public abstract class Agent
public abstract class AIAgent
{
/// <summary>
/// Gets the identifier of the agent.
@@ -27,6 +27,14 @@ public abstract class Agent
/// </summary>
public virtual string? Name { get; }
/// <summary>
/// Gets a display name for the agent, which is either the <see cref="Name"/> or <see cref="Id"/> if the name is not set.
/// </summary>
public virtual string DisplayName
{
get => this.Name ?? this.Id;
}
/// <summary>
/// Gets the description of the agent (optional).
/// </summary>
@@ -9,7 +9,7 @@ using System.Text.Json.Serialization;
namespace Microsoft.Extensions.AI.Agents;
/// <summary>
/// Represents a single streaming response chunk from an <see cref="Agent"/>.
/// Represents a single streaming response chunk from an <see cref="AIAgent"/>.
/// </summary>
/// <remarks>
/// <para>
@@ -16,7 +16,7 @@ namespace Microsoft.Extensions.AI.Agents.CopilotStudio;
/// <summary>
/// Represents a Copilot Studio agent in the cloud.
/// </summary>
public class CopilotStudioAgent : Agent
public class CopilotStudioAgent : AIAgent
{
private readonly ILogger _logger;
@@ -3,7 +3,7 @@
namespace Microsoft.Extensions.AI.Agents;
/// <summary>
/// Extension methods for <see cref="Agent"/>.
/// Extension methods for <see cref="AIAgent"/>.
/// </summary>
public static class AgentExtensions
{
@@ -13,7 +13,7 @@ public static class AgentExtensions
/// <param name="agent">The agent to wrap.</param>
/// <param name="sourceName">An optional source name that will be used on the telemetry data.</param>
/// <returns>An <see cref="OpenTelemetryAgent"/> that wraps the original agent with telemetry.</returns>
public static OpenTelemetryAgent WithOpenTelemetry(this Agent agent, string? sourceName = null)
public static OpenTelemetryAgent WithOpenTelemetry(this AIAgent agent, string? sourceName = null)
{
return new OpenTelemetryAgent(agent, sourceName);
}
@@ -15,7 +15,7 @@ namespace Microsoft.Extensions.AI.Agents;
/// <summary>
/// Represents an agent that can be invoked using a chat client.
/// </summary>
public sealed class ChatClientAgent : Agent
public sealed class ChatClientAgent : AIAgent
{
private readonly ChatClientAgentOptions? _agentOptions;
private readonly ILogger _logger;
@@ -18,9 +18,9 @@ namespace Microsoft.Extensions.AI.Agents;
/// This class provides telemetry instrumentation for agent operations including activities, metrics, and logging.
/// The telemetry output follows OpenTelemetry semantic conventions in <see href="https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-agent-spans/"/> and is subject to change as the conventions evolve.
/// </remarks>
public sealed class OpenTelemetryAgent : Agent, IDisposable
public sealed class OpenTelemetryAgent : AIAgent, IDisposable
{
private readonly Agent _innerAgent;
private readonly AIAgent _innerAgent;
private readonly ActivitySource _activitySource;
private readonly Meter _meter;
private readonly Histogram<double> _operationDurationHistogram;
@@ -32,7 +32,7 @@ public sealed class OpenTelemetryAgent : Agent, IDisposable
/// </summary>
/// <param name="innerAgent">The underlying agent to wrap with telemetry.</param>
/// <param name="sourceName">An optional source name that will be used on the telemetry data.</param>
public OpenTelemetryAgent(Agent innerAgent, string? sourceName = null)
public OpenTelemetryAgent(AIAgent innerAgent, string? sourceName = null)
{
this._innerAgent = Throw.IfNull(innerAgent);
@@ -13,7 +13,7 @@ namespace AgentConformance.IntegrationTests;
/// </summary>
public interface IAgentFixture : IAsyncLifetime
{
Agent Agent { get; }
AIAgent Agent { get; }
Task<List<ChatMessage>> GetChatHistoryAsync(AgentThread thread);
@@ -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)
{
@@ -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);
@@ -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)
{
@@ -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;