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
@@ -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);