Skip to content

Commit a71f768

Browse files
.NET: [Breaking] Delete display name property (#2758)
* delete the AIAgent.DisplayName property * use agent name as a first value for activity display name * Update dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffAgentExecutor.cs Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 0298e0a commit a71f768

File tree

17 files changed

+32
-48
lines changed

17 files changed

+32
-48
lines changed

dotnet/samples/GettingStarted/AgentProviders/Agent_With_CustomImplementation/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override async Task<AgentRunResponse> RunAsync(IEnumerable<ChatMessage> m
4545
}
4646

4747
// Clone the input messages and turn them into response messages with upper case text.
48-
List<ChatMessage> responseMessages = CloneAndToUpperCase(messages, this.DisplayName).ToList();
48+
List<ChatMessage> responseMessages = CloneAndToUpperCase(messages, this.Name).ToList();
4949

5050
// Notify the thread of the input and output messages.
5151
await typedThread.MessageStore.AddMessagesAsync(messages.Concat(responseMessages), cancellationToken);
@@ -69,7 +69,7 @@ public override async IAsyncEnumerable<AgentRunResponseUpdate> RunStreamingAsync
6969
}
7070

7171
// Clone the input messages and turn them into response messages with upper case text.
72-
List<ChatMessage> responseMessages = CloneAndToUpperCase(messages, this.DisplayName).ToList();
72+
List<ChatMessage> responseMessages = CloneAndToUpperCase(messages, this.Name).ToList();
7373

7474
// Notify the thread of the input and output messages.
7575
await typedThread.MessageStore.AddMessagesAsync(messages.Concat(responseMessages), cancellationToken);
@@ -79,7 +79,7 @@ public override async IAsyncEnumerable<AgentRunResponseUpdate> RunStreamingAsync
7979
yield return new AgentRunResponseUpdate
8080
{
8181
AgentId = this.Id,
82-
AuthorName = this.DisplayName,
82+
AuthorName = message.AuthorName,
8383
Role = ChatRole.Assistant,
8484
Contents = message.Contents,
8585
ResponseId = Guid.NewGuid().ToString("N"),
@@ -88,7 +88,7 @@ public override async IAsyncEnumerable<AgentRunResponseUpdate> RunStreamingAsync
8888
}
8989
}
9090

91-
private static IEnumerable<ChatMessage> CloneAndToUpperCase(IEnumerable<ChatMessage> messages, string agentName) => messages.Select(x =>
91+
private static IEnumerable<ChatMessage> CloneAndToUpperCase(IEnumerable<ChatMessage> messages, string? agentName) => messages.Select(x =>
9292
{
9393
// Clone the message and update its author to be the agent.
9494
var messageClone = x.Clone();

dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ internal sealed class A2AAgent : AIAgent
3030
private readonly string? _id;
3131
private readonly string? _name;
3232
private readonly string? _description;
33-
private readonly string? _displayName;
3433
private readonly ILogger _logger;
3534

3635
/// <summary>
@@ -40,17 +39,15 @@ internal sealed class A2AAgent : AIAgent
4039
/// <param name="id">The unique identifier for the agent.</param>
4140
/// <param name="name">The the name of the agent.</param>
4241
/// <param name="description">The description of the agent.</param>
43-
/// <param name="displayName">The display name of the agent.</param>
4442
/// <param name="loggerFactory">Optional logger factory to use for logging.</param>
45-
public A2AAgent(A2AClient a2aClient, string? id = null, string? name = null, string? description = null, string? displayName = null, ILoggerFactory? loggerFactory = null)
43+
public A2AAgent(A2AClient a2aClient, string? id = null, string? name = null, string? description = null, ILoggerFactory? loggerFactory = null)
4644
{
4745
_ = Throw.IfNull(a2aClient);
4846

4947
this._a2aClient = a2aClient;
5048
this._id = id;
5149
this._name = name;
5250
this._description = description;
53-
this._displayName = displayName;
5451
this._logger = (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger<A2AAgent>();
5552
}
5653

@@ -203,9 +200,6 @@ public override async IAsyncEnumerable<AgentRunResponseUpdate> RunStreamingAsync
203200
/// <inheritdoc/>
204201
public override string? Name => this._name ?? base.Name;
205202

206-
/// <inheritdoc/>
207-
public override string DisplayName => this._displayName ?? base.DisplayName;
208-
209203
/// <inheritdoc/>
210204
public override string? Description => this._description ?? base.Description;
211205

dotnet/src/Microsoft.Agents.AI.A2A/Extensions/A2AClientExtensions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ public static class A2AClientExtensions
3333
/// <param name="id">The unique identifier for the agent.</param>
3434
/// <param name="name">The the name of the agent.</param>
3535
/// <param name="description">The description of the agent.</param>
36-
/// <param name="displayName">The display name of the agent.</param>
3736
/// <param name="loggerFactory">Optional logger factory for enabling logging within the agent.</param>
3837
/// <returns>An <see cref="AIAgent"/> instance backed by the A2A agent.</returns>
39-
public static AIAgent GetAIAgent(this A2AClient client, string? id = null, string? name = null, string? description = null, string? displayName = null, ILoggerFactory? loggerFactory = null) =>
40-
new A2AAgent(client, id, name, description, displayName, loggerFactory);
38+
public static AIAgent GetAIAgent(this A2AClient client, string? id = null, string? name = null, string? description = null, ILoggerFactory? loggerFactory = null) =>
39+
new A2AAgent(client, id, name, description, loggerFactory);
4140
}

dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,6 @@ public abstract class AIAgent
6060
/// </remarks>
6161
public virtual string? Name { get; }
6262

63-
/// <summary>
64-
/// Gets a display-friendly name for the agent.
65-
/// </summary>
66-
/// <value>
67-
/// The agent's <see cref="Name"/> if available, otherwise the <see cref="Id"/>.
68-
/// </value>
69-
/// <remarks>
70-
/// This property provides a guaranteed non-null string suitable for display in user interfaces,
71-
/// logs, or other contexts where a readable identifier is needed.
72-
/// </remarks>
73-
public virtual string DisplayName => this.Name ?? this.Id;
74-
7563
/// <summary>
7664
/// Gets a description of the agent's purpose, capabilities, or behavior.
7765
/// </summary>

dotnet/src/Microsoft.Agents.AI.DevUI/EntitiesApiExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private static EntityInfo CreateAgentEntityInfo(AIAgent agent)
231231
return new EntityInfo(
232232
Id: entityId,
233233
Type: "agent",
234-
Name: agent.DisplayName,
234+
Name: agent.Name ?? agent.Id,
235235
Description: agent.Description,
236236
Framework: "agent_framework",
237237
Tools: tools,

dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.ChatCompletions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static IEndpointConventionBuilder MapOpenAIChatCompletions(
6161

6262
path ??= $"/{agent.Name}/v1/chat/completions";
6363
var group = endpoints.MapGroup(path);
64-
var endpointAgentName = agent.DisplayName;
64+
var endpointAgentName = agent.Name ?? agent.Id;
6565

6666
group.MapPost("/", async ([FromBody] CreateChatCompletion request, CancellationToken cancellationToken)
6767
=> await AIAgentChatCompletionsProcessor.CreateChatCompletionAsync(agent, request, cancellationToken).ConfigureAwait(false))

dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Responses.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static IEndpointConventionBuilder MapOpenAIResponses(
7676
var handlers = new ResponsesHttpHandler(responsesService);
7777

7878
var group = endpoints.MapGroup(responsesPath);
79-
var endpointAgentName = agent.DisplayName;
79+
var endpointAgentName = agent.Name ?? agent.Id;
8080

8181
// Create response endpoint
8282
group.MapPost("/", handlers.CreateResponseAsync)

dotnet/src/Microsoft.Agents.AI.Workflows/HandoffsWorkflowBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ public HandoffsWorkflowBuilder WithHandoff(AIAgent from, AIAgent to, string? han
125125
{
126126
Throw.ArgumentException(
127127
nameof(to),
128-
$"The provided target agent '{to.DisplayName}' has no description, name, or instructions, and no handoff description has been provided. " +
128+
$"The provided target agent '{to.Name ?? to.Id}' has no description, name, or instructions, and no handoff description has been provided. " +
129129
"At least one of these is required to register a handoff so that the appropriate target agent can be chosen.");
130130
}
131131
}
132132

133133
if (!handoffs.Add(new(to, handoffReason)))
134134
{
135-
Throw.InvalidOperationException($"A handoff from agent '{from.DisplayName}' to agent '{to.DisplayName}' has already been registered.");
135+
Throw.InvalidOperationException($"A handoff from agent '{from.Name ?? from.Id}' to agent '{to.Name ?? to.Id}' has already been registered.");
136136
}
137137

138138
return this;

dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AgentRunStreamingExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal sealed class AgentRunStreamingExecutor(AIAgent agent, bool includeInput
2020

2121
protected override async ValueTask TakeTurnAsync(List<ChatMessage> messages, IWorkflowContext context, bool? emitEvents, CancellationToken cancellationToken = default)
2222
{
23-
List<ChatMessage>? roleChanged = messages.ChangeAssistantToUserForOtherParticipants(agent.DisplayName);
23+
List<ChatMessage>? roleChanged = messages.ChangeAssistantToUserForOtherParticipants(agent.Name ?? agent.Id);
2424

2525
List<AgentRunResponseUpdate> updates = [];
2626
await foreach (var update in agent.RunStreamingAsync(messages, cancellationToken: cancellationToken).ConfigureAwait(false))

dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/HandoffAgentExecutor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected override RouteBuilder ConfigureRoutes(RouteBuilder routeBuilder) =>
6767
List<AgentRunResponseUpdate> updates = [];
6868
List<ChatMessage> allMessages = handoffState.Messages;
6969

70-
List<ChatMessage>? roleChanges = allMessages.ChangeAssistantToUserForOtherParticipants(this._agent.DisplayName);
70+
List<ChatMessage>? roleChanges = allMessages.ChangeAssistantToUserForOtherParticipants(this._agent.Name ?? this._agent.Id);
7171

7272
await foreach (var update in this._agent.RunStreamingAsync(allMessages,
7373
options: this._agentOptions,
@@ -85,7 +85,7 @@ await AddUpdateAsync(
8585
new AgentRunResponseUpdate
8686
{
8787
AgentId = this._agent.Id,
88-
AuthorName = this._agent.DisplayName,
88+
AuthorName = this._agent.Name ?? this._agent.Id,
8989
Contents = [new FunctionResultContent(fcc.CallId, "Transferred.")],
9090
CreatedAt = DateTimeOffset.UtcNow,
9191
MessageId = Guid.NewGuid().ToString("N"),

0 commit comments

Comments
 (0)