Skip to content
Merged
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 @@ -96,16 +96,15 @@ public async Task<IActionResult> CreateAsync(

// Create a new agent thread
AgentThread thread = agentProxy.GetNewThread();
AgentThreadMetadata metadata = thread.GetService<AgentThreadMetadata>()
?? throw new InvalidOperationException("Failed to get AgentThreadMetadata from new thread.");
string agentSessionId = thread.GetService<AgentSessionId>().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)
Expand All @@ -114,7 +113,7 @@ public async Task<IActionResult> 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);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AgentThreadMetadata>()?.ConversationId
?? throw new InvalidOperationException("Unable to determine conversation ID from the current thread.");
string streamKey = GetStreamKey(conversationId);
string agentSessionId = context.CurrentThread.GetService<AgentSessionId>().ToString();
string streamKey = GetStreamKey(agentSessionId);

IDatabase db = this._redis.GetDatabase();
int sequenceNumber = 0;
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public virtual JsonElement Serialize(JsonSerializerOptions? jsonSerializerOption
/// <exception cref="ArgumentNullException"><paramref name="serviceType"/> is <see langword="null"/>.</exception>
/// <remarks>
/// The purpose of this method is to allow for the retrieval of strongly-typed services that might be provided by the <see cref="AgentThread"/>,
/// including itself or any services it might be wrapping. For example, to access the <see cref="AgentThreadMetadata"/> for the instance,
/// including itself or any services it might be wrapping. For example, to access a <see cref="ChatMessageStore"/> if available for the instance,
/// <see cref="GetService"/> may be used to request it.
/// </remarks>
public virtual object? GetService(Type serviceType, object? serviceKey = null)
Expand Down
29 changes: 0 additions & 29 deletions dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThreadMetadata.cs

This file was deleted.

1 change: 1 addition & 0 deletions dotnet/src/Microsoft.Agents.AI.DurableTask/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ internal static DurableAgentThread Deserialize(JsonElement serializedThread, Jso
/// <inheritdoc/>
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ public override JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptio

/// <inheritdoc/>
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);

Expand Down
Loading