Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ protected override async IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingA
Role = update.Role,
ContinuationToken = update.ContinuationToken,
AdditionalProperties = update.AdditionalProperties,
})
{
AgentId = update.AgentId
};
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ protected override async IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingA
AdditionalProperties = update.AdditionalProperties,
AuthorName = update.AuthorName,
ContinuationToken = update.ContinuationToken,
})
{
AgentId = update.AgentId
};
});

// Small delay to simulate streaming
await Task.Delay(50, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ private static AgentResponseUpdate ProcessIncomingServerApprovalRequests(
AdditionalProperties = chatUpdate.AdditionalProperties
})
{
AgentId = update.AgentId,
ContinuationToken = update.ContinuationToken,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ private static AgentResponseUpdate ProcessOutgoingApprovalRequests(
AdditionalProperties = chatUpdate.AdditionalProperties
})
{
AgentId = update.AgentId,
ContinuationToken = update.ContinuationToken
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ protected override async Task<AgentResponse> RunCoreAsync(IEnumerable<ChatMessag

return new AgentResponse
{
AgentId = this.Id,
ResponseId = Guid.NewGuid().ToString("N"),
Messages = responseMessages
};
Expand Down Expand Up @@ -94,7 +93,6 @@ protected override async IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingA
{
yield return new AgentResponseUpdate
{
AgentId = this.Id,
AuthorName = message.AuthorName,
Role = ChatRole.Assistant,
Contents = message.Contents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ await aiProjectClient
{
if (responseUpdate.MessageId != lastMessageId)
{
Console.WriteLine($"\n\n{responseUpdate.AuthorName ?? responseUpdate.AgentId}");
Console.WriteLine($"\n\n{responseUpdate.AuthorName ?? agent.Id}");
}

lastMessageId = responseUpdate.MessageId;
Expand Down
5 changes: 0 additions & 5 deletions dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ protected override async Task<AgentResponse> RunCoreAsync(IEnumerable<ChatMessag

return new AgentResponse
{
AgentId = this.Id,
ResponseId = message.MessageId,
RawRepresentation = message,
Messages = [message.ToChatMessage()],
Expand All @@ -115,7 +114,6 @@ protected override async Task<AgentResponse> RunCoreAsync(IEnumerable<ChatMessag

var response = new AgentResponse
{
AgentId = this.Id,
ResponseId = agentTask.Id,
RawRepresentation = agentTask,
Messages = agentTask.ToChatMessages() ?? [],
Expand Down Expand Up @@ -295,7 +293,6 @@ private AgentResponseUpdate ConvertToAgentResponseUpdate(AgentMessage message)
{
return new AgentResponseUpdate
{
AgentId = this.Id,
ResponseId = message.MessageId,
RawRepresentation = message,
Role = ChatRole.Assistant,
Expand All @@ -309,7 +306,6 @@ private AgentResponseUpdate ConvertToAgentResponseUpdate(AgentTask task)
{
return new AgentResponseUpdate
{
AgentId = this.Id,
ResponseId = task.Id,
RawRepresentation = task,
Role = ChatRole.Assistant,
Expand All @@ -322,7 +318,6 @@ private AgentResponseUpdate ConvertToAgentResponseUpdate(TaskUpdateEvent taskUpd
{
AgentResponseUpdate responseUpdate = new()
{
AgentId = this.Id,
ResponseId = taskUpdateEvent.TaskId,
RawRepresentation = taskUpdateEvent,
Role = ChatRole.Assistant,
Expand Down
13 changes: 0 additions & 13 deletions dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,6 @@ public IList<ChatMessage> Messages
[JsonIgnore]
public IEnumerable<UserInputRequestContent> UserInputRequests => this._messages?.SelectMany(x => x.Contents).OfType<UserInputRequestContent>() ?? [];

/// <summary>
/// Gets or sets the identifier of the agent that generated this response.
/// </summary>
/// <value>
/// A unique string identifier for the agent, or <see langword="null"/> if not specified.
/// </value>
/// <remarks>
/// This identifier helps track which agent generated the response in multi-agent scenarios
/// or for debugging and telemetry purposes.
/// </remarks>
public string? AgentId { get; set; }

/// <summary>
/// Gets or sets the unique identifier for this specific response.
/// </summary>
Expand Down Expand Up @@ -276,7 +264,6 @@ public AgentResponseUpdate[] ToAgentResponseUpdates()
RawRepresentation = message.RawRepresentation,
Role = message.Role,

AgentId = this.AgentId,
ResponseId = this.ResponseId,
MessageId = message.MessageId,
CreatedAt = this.CreatedAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,11 @@ public static AgentResponse ToAgentResponse(
{
_ = Throw.IfNull(updates);

AgentResponseDetails additionalDetails = new();
ChatResponse chatResponse =
AsChatResponseUpdatesWithAdditionalDetails(updates, additionalDetails)
AsChatResponseUpdates(updates)
.ToChatResponse();

return new AgentResponse(chatResponse)
{
AgentId = additionalDetails.AgentId,
};
return new AgentResponse(chatResponse);
}

/// <summary>
Expand Down Expand Up @@ -160,52 +156,31 @@ static async Task<AgentResponse> ToAgentResponseAsync(
IAsyncEnumerable<AgentResponseUpdate> updates,
CancellationToken cancellationToken)
{
AgentResponseDetails additionalDetails = new();
ChatResponse chatResponse = await
AsChatResponseUpdatesWithAdditionalDetailsAsync(updates, additionalDetails, cancellationToken)
AsChatResponseUpdatesAsync(updates, cancellationToken)
.ToChatResponseAsync(cancellationToken)
.ConfigureAwait(false);

return new AgentResponse(chatResponse)
{
AgentId = additionalDetails.AgentId,
};
return new AgentResponse(chatResponse);
}
}

private static IEnumerable<ChatResponseUpdate> AsChatResponseUpdatesWithAdditionalDetails(
IEnumerable<AgentResponseUpdate> updates,
AgentResponseDetails additionalDetails)
private static IEnumerable<ChatResponseUpdate> AsChatResponseUpdates(
IEnumerable<AgentResponseUpdate> updates)
{
foreach (var update in updates)
{
UpdateAdditionalDetails(update, additionalDetails);
yield return update.AsChatResponseUpdate();
}
}

private static async IAsyncEnumerable<ChatResponseUpdate> AsChatResponseUpdatesWithAdditionalDetailsAsync(
private static async IAsyncEnumerable<ChatResponseUpdate> AsChatResponseUpdatesAsync(
IAsyncEnumerable<AgentResponseUpdate> updates,
AgentResponseDetails additionalDetails,
[EnumeratorCancellation] CancellationToken cancellationToken)
{
await foreach (var update in updates.WithCancellation(cancellationToken).ConfigureAwait(false))
{
UpdateAdditionalDetails(update, additionalDetails);
yield return update.AsChatResponseUpdate();
}
}

private static void UpdateAdditionalDetails(AgentResponseUpdate update, AgentResponseDetails details)
{
if (update.AgentId is { Length: > 0 })
{
details.AgentId = update.AgentId;
}
}

private sealed class AgentResponseDetails
{
public string? AgentId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ public IList<AIContent> Contents
/// <summary>Gets or sets additional properties for the update.</summary>
public AdditionalPropertiesDictionary? AdditionalProperties { get; set; }

/// <summary>Gets or sets the ID of the agent that produced the response.</summary>
public string? AgentId { get; set; }

/// <summary>Gets or sets the ID of the response of which this update is a part.</summary>
public string? ResponseId { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ protected override async Task<AgentResponse> RunCoreAsync(
// so that they can tell things like response boundaries.
return new AgentResponse(responseMessagesList)
{
AgentId = this.Id,
ResponseId = responseMessagesList.LastOrDefault()?.MessageId,
};
}
Expand Down Expand Up @@ -127,7 +126,6 @@ protected override async IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingA
// so that they can tell things like response boundaries.
yield return new AgentResponseUpdate(message.Role, message.Contents)
{
AgentId = this.Id,
AdditionalProperties = message.AdditionalProperties,
AuthorName = message.AuthorName,
RawRepresentation = message.RawRepresentation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@ internal sealed class EntityAgentWrapper(
// The ID of the agent is always the entity ID.
protected override string? IdCore => this._entityContext.Id.ToString();

protected override async Task<AgentResponse> RunCoreAsync(
protected override Task<AgentResponse> RunCoreAsync(
IEnumerable<ChatMessage> messages,
AgentSession? session = null,
AgentRunOptions? options = null,
CancellationToken cancellationToken = default)
{
AgentResponse response = await base.RunCoreAsync(
return base.RunCoreAsync(
messages,
session,
this.GetAgentEntityRunOptions(options),
cancellationToken);

response.AgentId = this.Id;
return response;
}

protected override async IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingAsync(
Expand All @@ -49,7 +46,6 @@ protected override async IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingA
this.GetAgentEntityRunOptions(options),
cancellationToken))
{
update.AgentId = this.Id;
yield return update;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ private async ValueTask InvokeAgentAsync(IWorkflowContext context, IEnumerable<C
new(actionableMessages)
{
AdditionalProperties = agentResponse.AdditionalProperties,
AgentId = agentResponse.AgentId,
CreatedAt = agentResponse.CreatedAt,
ResponseId = agentResponse.ResponseId,
Usage = agentResponse.Usage,
Expand Down
12 changes: 1 addition & 11 deletions dotnet/src/Microsoft.Agents.AI.Workflows/MessageMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,10 @@ private int CompareByDateTimeOffset(AgentResponse left, AgentResponse right)
return left.CreatedAt.Value.CompareTo(right.CreatedAt.Value);
}

public AgentResponse ComputeMerged(string primaryResponseId, string? primaryAgentId = null, string? primaryAgentName = null)
public AgentResponse ComputeMerged(string primaryResponseId)
{
List<ChatMessage> messages = [];
Dictionary<string, AgentResponse> responses = [];
HashSet<string> agentIds = [];

foreach (string responseId in this._mergeStates.Keys)
{
Expand All @@ -146,11 +145,6 @@ public AgentResponse ComputeMerged(string primaryResponseId, string? primaryAgen

foreach (AgentResponse response in responses.Values)
{
if (response.AgentId is not null)
{
agentIds.Add(response.AgentId);
}

if (response.CreatedAt.HasValue)
{
createdTimes.Add(response.CreatedAt.Value);
Expand Down Expand Up @@ -179,9 +173,6 @@ public AgentResponse ComputeMerged(string primaryResponseId, string? primaryAgen
return new AgentResponse(messages)
{
ResponseId = primaryResponseId,
AgentId = primaryAgentId
?? primaryAgentName
?? (agentIds.Count == 1 ? agentIds.First() : null),
CreatedAt = DateTimeOffset.UtcNow,
Usage = usage,
AdditionalProperties = additionalProperties
Expand All @@ -204,7 +195,6 @@ static AgentResponse MergeResponses(AgentResponse? current, AgentResponse incomi

return new()
{
AgentId = incoming.AgentId ?? current.AgentId,
AdditionalProperties = MergeProperties(current.AdditionalProperties, incoming.AdditionalProperties),
CreatedAt = incoming.CreatedAt ?? current.CreatedAt,
Messages = current.Messages.Concat(incoming.Messages).ToList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ protected override RouteBuilder ConfigureRoutes(RouteBuilder routeBuilder) =>
await AddUpdateAsync(
new AgentResponseUpdate
{
AgentId = this._agent.Id,
AuthorName = this._agent.Name ?? this._agent.Id,
Contents = [new FunctionResultContent(fcc.CallId, "Transferred.")],
CreatedAt = DateTimeOffset.UtcNow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Task<AgentResponse> RunCoreAsync(
merger.AddUpdate(update);
}

return merger.ComputeMerged(workflowSession.LastResponseId!, this.Id, this.Name);
return merger.ComputeMerged(workflowSession.LastResponseId!);
}

protected override async
Expand Down
7 changes: 1 addition & 6 deletions dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ protected override async IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingA

yield return new(update)
{
AgentId = this.Id,
ContinuationToken = WrapContinuationToken(update.ContinuationToken, GetInputMessages(inputMessages, continuationToken), responseUpdates)
};
}
Expand Down Expand Up @@ -465,11 +464,7 @@ private async Task<TAgentResponse> RunCoreAsync<TAgentResponse, TChatClientRespo
// Notify the AIContextProvider of all new messages.
await NotifyAIContextProviderOfSuccessAsync(safeSession, inputMessages, aiContextProviderMessages, chatResponse.Messages, cancellationToken).ConfigureAwait(false);

var agentResponse = agentResponseFactoryFunc(chatResponse);

agentResponse.AgentId = this.Id;

return agentResponse;
return agentResponseFactoryFunc(chatResponse);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/Shared/Workflows/Execution/WorkflowRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public async Task ExecuteAsync(Func<Workflow> workflowProvider, string input)

if (messageId is not null)
{
string? agentName = streamEvent.Update.AuthorName ?? streamEvent.Update.AgentId ?? nameof(ChatRole.Assistant);
string? agentName = streamEvent.Update.AuthorName ?? streamEvent.ExecutorId ?? nameof(ChatRole.Assistant);
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write($"\n{agentName.ToUpperInvariant()}:");
Console.ForegroundColor = ConsoleColor.DarkGray;
Expand Down
1 change: 0 additions & 1 deletion dotnet/tests/AgentConformance.IntegrationTests/RunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public virtual async Task RunWithStringReturnsExpectedResultAsync()
Assert.NotNull(response);
Assert.Single(response.Messages);
Assert.Contains("Paris", response.Text);
Assert.Equal(agent.Id, response.AgentId);
}

[RetryFact(Constants.RetryCount, Constants.RetryDelay)]
Expand Down
Loading
Loading