From 1b8244d9b666a642de8940ae49b33fb6c4274fab Mon Sep 17 00:00:00 2001 From: westey <164392973+westey-m@users.noreply.github.com> Date: Fri, 2 Jan 2026 17:03:00 +0000 Subject: [PATCH 1/2] Remove unused AgentThreadMetadata --- .../08_ReliableStreaming/FunctionTriggers.cs | 9 +++--- .../RedisStreamResponseHandler.cs | 7 ++--- .../AgentThread.cs | 2 +- .../AgentThreadMetadata.cs | 29 ------------------- .../DurableAgentThread.cs | 6 ---- .../ChatClient/ChatClientAgentThread.cs | 4 +-- 6 files changed, 9 insertions(+), 48 deletions(-) delete mode 100644 dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThreadMetadata.cs diff --git a/dotnet/samples/AzureFunctions/08_ReliableStreaming/FunctionTriggers.cs b/dotnet/samples/AzureFunctions/08_ReliableStreaming/FunctionTriggers.cs index e642b64337..a6d3e9db55 100644 --- a/dotnet/samples/AzureFunctions/08_ReliableStreaming/FunctionTriggers.cs +++ b/dotnet/samples/AzureFunctions/08_ReliableStreaming/FunctionTriggers.cs @@ -96,16 +96,15 @@ public async Task CreateAsync( // Create a new agent thread AgentThread thread = agentProxy.GetNewThread(); - AgentThreadMetadata metadata = thread.GetService() - ?? throw new InvalidOperationException("Failed to get AgentThreadMetadata from new thread."); + string agentSessionId = thread.GetService().ToString(); - this._logger.LogInformation("Creating new agent session: {ConversationId}", metadata.ConversationId); + this._logger.LogInformation("Creating new agent session: {AgentSessionId}", agentSessionId); // Run the agent in the background (fire-and-forget) DurableAgentRunOptions options = new() { IsFireAndForget = true }; await agentProxy.RunAsync(prompt, thread, options, cancellationToken); - this._logger.LogInformation("Agent run started for session: {ConversationId}", metadata.ConversationId); + this._logger.LogInformation("Agent run started for session: {AgentSessionId}", agentSessionId); // Check Accept header to determine response format // text/plain = raw text output (ideal for terminals) @@ -114,7 +113,7 @@ public async Task CreateAsync( bool useSseFormat = acceptHeader?.Contains("text/plain", StringComparison.OrdinalIgnoreCase) != true; return await this.StreamToClientAsync( - conversationId: metadata.ConversationId!, cursor: null, useSseFormat, request.HttpContext, cancellationToken); + conversationId: agentSessionId, cursor: null, useSseFormat, request.HttpContext, cancellationToken); } /// diff --git a/dotnet/samples/AzureFunctions/08_ReliableStreaming/RedisStreamResponseHandler.cs b/dotnet/samples/AzureFunctions/08_ReliableStreaming/RedisStreamResponseHandler.cs index b0a95f49f6..21f944338a 100644 --- a/dotnet/samples/AzureFunctions/08_ReliableStreaming/RedisStreamResponseHandler.cs +++ b/dotnet/samples/AzureFunctions/08_ReliableStreaming/RedisStreamResponseHandler.cs @@ -65,11 +65,10 @@ public async ValueTask OnStreamingResponseUpdateAsync( "DurableAgentContext.Current is not set. This handler must be used within a durable agent context."); } - // Get conversation ID from the current thread context, which is only available in the context of + // Get session ID from the current thread context, which is only available in the context of // a durable agent execution. - string conversationId = context.CurrentThread.GetService()?.ConversationId - ?? throw new InvalidOperationException("Unable to determine conversation ID from the current thread."); - string streamKey = GetStreamKey(conversationId); + string agentSessionId = context.CurrentThread.GetService().ToString(); + string streamKey = GetStreamKey(agentSessionId); IDatabase db = this._redis.GetDatabase(); int sequenceNumber = 0; diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThread.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThread.cs index 4794457f41..0a3301d05f 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThread.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThread.cs @@ -68,7 +68,7 @@ public virtual JsonElement Serialize(JsonSerializerOptions? jsonSerializerOption /// is . /// /// The purpose of this method is to allow for the retrieval of strongly-typed services that might be provided by the , - /// including itself or any services it might be wrapping. For example, to access the for the instance, + /// including itself or any services it might be wrapping. For example, to access a if available for the instance, /// may be used to request it. /// public virtual object? GetService(Type serviceType, object? serviceKey = null) diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThreadMetadata.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThreadMetadata.cs deleted file mode 100644 index 3a2d506745..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThreadMetadata.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System.Diagnostics; - -namespace Microsoft.Agents.AI; - -/// -/// Provides metadata information about an instance. -/// -[DebuggerDisplay("ConversationId = {ConversationId}")] -public class AgentThreadMetadata -{ - /// - /// Initializes a new instance of the class. - /// - /// The unique identifier for the conversation, if available. - public AgentThreadMetadata(string? conversationId) - { - this.ConversationId = conversationId; - } - - /// - /// Gets the unique identifier for the conversation, if available. - /// - /// - /// The meaning of this ID may vary depending on the agent implementation. - /// - public string? ConversationId { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAgentThread.cs b/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAgentThread.cs index 32dea2cb18..98dc8ea4b1 100644 --- a/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAgentThread.cs +++ b/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAgentThread.cs @@ -55,12 +55,6 @@ internal static DurableAgentThread Deserialize(JsonElement serializedThread, Jso /// public override object? GetService(Type serviceType, object? serviceKey = null) { - // This is a common convention for MAF agents. - if (serviceType == typeof(AgentThreadMetadata)) - { - return new AgentThreadMetadata(conversationId: this.SessionId.ToString()); - } - if (serviceType == typeof(AgentSessionId)) { return this.SessionId; diff --git a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentThread.cs b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentThread.cs index 7f0ce9a1ea..91e9502968 100644 --- a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentThread.cs +++ b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentThread.cs @@ -171,9 +171,7 @@ public override JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptio /// public override object? GetService(Type serviceType, object? serviceKey = null) => - serviceType == typeof(AgentThreadMetadata) - ? new AgentThreadMetadata(this.ConversationId) - : base.GetService(serviceType, serviceKey) + base.GetService(serviceType, serviceKey) ?? this.AIContextProvider?.GetService(serviceType, serviceKey) ?? this.MessageStore?.GetService(serviceType, serviceKey); From 4b4715667b2624584b1d575711df6a1e93317a52 Mon Sep 17 00:00:00 2001 From: westey <164392973+westey-m@users.noreply.github.com> Date: Fri, 2 Jan 2026 17:17:36 +0000 Subject: [PATCH 2/2] Update DurableTask Changelog --- dotnet/src/Microsoft.Agents.AI.DurableTask/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/dotnet/src/Microsoft.Agents.AI.DurableTask/CHANGELOG.md b/dotnet/src/Microsoft.Agents.AI.DurableTask/CHANGELOG.md index ccc6aa7181..8f8f64fe5c 100644 --- a/dotnet/src/Microsoft.Agents.AI.DurableTask/CHANGELOG.md +++ b/dotnet/src/Microsoft.Agents.AI.DurableTask/CHANGELOG.md @@ -6,6 +6,7 @@ - Added TTL configuration for durable agent entities ([#2679](https://github.com/microsoft/agent-framework/pull/2679)) - Switch to new "Run" method name ([#2843](https://github.com/microsoft/agent-framework/pull/2843)) +- Removed AgentThreadMetadata and used AgentSessionId directly instead ([#3067](https://github.com/microsoft/agent-framework/pull/3067)); ## v1.0.0-preview.251204.1