Skip to content

Commit 0aba02c

Browse files
authored
[BREAKING] Remove unused AgentThreadMetadata (microsoft#3067)
* Remove unused AgentThreadMetadata * Update DurableTask Changelog
1 parent 3ef67ef commit 0aba02c

7 files changed

Lines changed: 10 additions & 48 deletions

File tree

dotnet/samples/AzureFunctions/08_ReliableStreaming/FunctionTriggers.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,15 @@ public async Task<IActionResult> CreateAsync(
9696

9797
// Create a new agent thread
9898
AgentThread thread = agentProxy.GetNewThread();
99-
AgentThreadMetadata metadata = thread.GetService<AgentThreadMetadata>()
100-
?? throw new InvalidOperationException("Failed to get AgentThreadMetadata from new thread.");
99+
string agentSessionId = thread.GetService<AgentSessionId>().ToString();
101100

102-
this._logger.LogInformation("Creating new agent session: {ConversationId}", metadata.ConversationId);
101+
this._logger.LogInformation("Creating new agent session: {AgentSessionId}", agentSessionId);
103102

104103
// Run the agent in the background (fire-and-forget)
105104
DurableAgentRunOptions options = new() { IsFireAndForget = true };
106105
await agentProxy.RunAsync(prompt, thread, options, cancellationToken);
107106

108-
this._logger.LogInformation("Agent run started for session: {ConversationId}", metadata.ConversationId);
107+
this._logger.LogInformation("Agent run started for session: {AgentSessionId}", agentSessionId);
109108

110109
// Check Accept header to determine response format
111110
// text/plain = raw text output (ideal for terminals)
@@ -114,7 +113,7 @@ public async Task<IActionResult> CreateAsync(
114113
bool useSseFormat = acceptHeader?.Contains("text/plain", StringComparison.OrdinalIgnoreCase) != true;
115114

116115
return await this.StreamToClientAsync(
117-
conversationId: metadata.ConversationId!, cursor: null, useSseFormat, request.HttpContext, cancellationToken);
116+
conversationId: agentSessionId, cursor: null, useSseFormat, request.HttpContext, cancellationToken);
118117
}
119118

120119
/// <summary>

dotnet/samples/AzureFunctions/08_ReliableStreaming/RedisStreamResponseHandler.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@ public async ValueTask OnStreamingResponseUpdateAsync(
6565
"DurableAgentContext.Current is not set. This handler must be used within a durable agent context.");
6666
}
6767

68-
// Get conversation ID from the current thread context, which is only available in the context of
68+
// Get session ID from the current thread context, which is only available in the context of
6969
// a durable agent execution.
70-
string conversationId = context.CurrentThread.GetService<AgentThreadMetadata>()?.ConversationId
71-
?? throw new InvalidOperationException("Unable to determine conversation ID from the current thread.");
72-
string streamKey = GetStreamKey(conversationId);
70+
string agentSessionId = context.CurrentThread.GetService<AgentSessionId>().ToString();
71+
string streamKey = GetStreamKey(agentSessionId);
7372

7473
IDatabase db = this._redis.GetDatabase();
7574
int sequenceNumber = 0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public virtual JsonElement Serialize(JsonSerializerOptions? jsonSerializerOption
6868
/// <exception cref="ArgumentNullException"><paramref name="serviceType"/> is <see langword="null"/>.</exception>
6969
/// <remarks>
7070
/// The purpose of this method is to allow for the retrieval of strongly-typed services that might be provided by the <see cref="AgentThread"/>,
71-
/// including itself or any services it might be wrapping. For example, to access the <see cref="AgentThreadMetadata"/> for the instance,
71+
/// including itself or any services it might be wrapping. For example, to access a <see cref="ChatMessageStore"/> if available for the instance,
7272
/// <see cref="GetService"/> may be used to request it.
7373
/// </remarks>
7474
public virtual object? GetService(Type serviceType, object? serviceKey = null)

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

Lines changed: 0 additions & 29 deletions
This file was deleted.

dotnet/src/Microsoft.Agents.AI.DurableTask/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Added TTL configuration for durable agent entities ([#2679](https://github.com/microsoft/agent-framework/pull/2679))
88
- Switch to new "Run" method name ([#2843](https://github.com/microsoft/agent-framework/pull/2843))
9+
- Removed AgentThreadMetadata and used AgentSessionId directly instead ([#3067](https://github.com/microsoft/agent-framework/pull/3067));
910

1011
## v1.0.0-preview.251204.1
1112

dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAgentThread.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ internal static DurableAgentThread Deserialize(JsonElement serializedThread, Jso
5555
/// <inheritdoc/>
5656
public override object? GetService(Type serviceType, object? serviceKey = null)
5757
{
58-
// This is a common convention for MAF agents.
59-
if (serviceType == typeof(AgentThreadMetadata))
60-
{
61-
return new AgentThreadMetadata(conversationId: this.SessionId.ToString());
62-
}
63-
6458
if (serviceType == typeof(AgentSessionId))
6559
{
6660
return this.SessionId;

dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentThread.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@ public override JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptio
171171

172172
/// <inheritdoc/>
173173
public override object? GetService(Type serviceType, object? serviceKey = null) =>
174-
serviceType == typeof(AgentThreadMetadata)
175-
? new AgentThreadMetadata(this.ConversationId)
176-
: base.GetService(serviceType, serviceKey)
174+
base.GetService(serviceType, serviceKey)
177175
?? this.AIContextProvider?.GetService(serviceType, serviceKey)
178176
?? this.MessageStore?.GetService(serviceType, serviceKey);
179177

0 commit comments

Comments
 (0)