Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Carry ModelId through the streaming update wrapper
The ChatResponseUpdate the agent's update is wrapped in for telemetry dropped
ModelId, so gen_ai.response.model was missing on streaming runs.
  • Loading branch information
atty57 committed Oct 9, 2026
commit 516aef2441d7861267ab1ea8f4f43f5f51e22715
1 change: 1 addition & 0 deletions dotnet/src/Microsoft.Agents.AI/OpenTelemetryAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ private static ChatResponseUpdate ToChatResponseUpdate(AgentResponseUpdate updat
CreatedAt = update.CreatedAt,
FinishReason = update.FinishReason,
MessageId = update.MessageId,
ModelId = (update.RawRepresentation as ChatResponseUpdate)?.ModelId,
RawRepresentation = update,
ResponseId = update.ResponseId,
Role = update.Role,
Comment thread
SergeyMenshykh marked this conversation as resolved.
Resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,44 @@ public async Task RunStreamingAsync_WrappingChatClientAgent_PreservesAgentContin
}
#pragma warning restore MEAI001

[Fact]
public async Task RunStreamingAsync_ReportsResponseModelFromInnerUpdateAsync()
{
// Arrange
// The telemetry chat client reads the response model off the ChatResponseUpdate the agent's update is
// wrapped in, so ModelId has to be carried over from the inner update's raw representation.
var sourceName = Guid.NewGuid().ToString();
var activities = new ConcurrentActivityList();
using var tracerProvider = OpenTelemetry.Sdk.CreateTracerProviderBuilder()
.AddSource(sourceName)
.AddInMemoryExporter(activities)
.Build();

var innerAgent = new TestAIAgent { RunStreamingAsyncFunc = CallbackAsync };

async static IAsyncEnumerable<AgentResponseUpdate> CallbackAsync(
IEnumerable<ChatMessage> messages, AgentSession? session, AgentRunOptions? options, [EnumeratorCancellation] CancellationToken cancellationToken)
{
await Task.Yield();
yield return new AgentResponseUpdate(ChatRole.Assistant, "ok")
{
RawRepresentation = new ChatResponseUpdate { ModelId = "innermodel" },
};
}

using var agent = new OpenTelemetryAgent(innerAgent, sourceName);

// Act
await foreach (var update in agent.RunStreamingAsync("hi"))
{
await Task.Yield();
}

// Assert
var activity = Assert.Single(activities);
Assert.Equal("innermodel", activity.GetTagItem("gen_ai.response.model"));
}

[Fact]
public async Task AutoWireChatClient_ChatClientAgentRunOptions_NoUserFactory_PreservesChatOptions_Async()
{
Expand Down
Loading