-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Description
When deserializing a session with ChatClientAgent.DeserializeSessionAsync, the framework passes the serialized ChatHistoryProviderState to ChatHistoryProviderFactory. However, the official CosmosDBChatExtensions factory ignores this state and always creates a new CosmosChatHistoryProvider, which generates a new ConversationId. As a result, conversation history is lost on each deserialize.
Expected:
The factory should use context.SerializedState when present and call CosmosChatHistoryProvider.CreateFromSerializedState(...) to preserve the original ConversationId
Actual:
The factory always creates new CosmosChatHistoryProvider(...), losing the previous ConversationId
Suggested Fix:
options.ChatHistoryProviderFactory = (context, ct) =>
{
if (context.SerializedState.ValueKind == JsonValueKind.Object)
{
return new ValueTask<ChatHistoryProvider>(
CosmosChatHistoryProvider.CreateFromSerializedState(
new CosmosClient(accountEndpoint, tokenCredential),
context.SerializedState,
databaseId,
containerId,
context.JsonSerializerOptions));
}
return new ValueTask<ChatHistoryProvider>(
new CosmosChatHistoryProvider(accountEndpoint, tokenCredential, databaseId, containerId));
};
Code Sample
Error Messages / Stack Traces
Package Versions
Microsoft.Agents.AI 1.0.0-preview.251113.1
.NET Version
.NET 10
Additional Context
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status