Skip to content

.NET: fix: avoid local history when service returns conversation id#6141

Open
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/service-history-provider-conflict
Open

.NET: fix: avoid local history when service returns conversation id#6141
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/service-history-provider-conflict

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Summary

To verify

  • dotnet run --project dotnet/tests/Microsoft.Agents.AI.UnitTests/Microsoft.Agents.AI.UnitTests.csproj --framework net10.0 -- --filter-method "Microsoft.Agents.AI.UnitTests.ChatClientAgent_ChatHistoryManagementTests.RunAsync_DoesNotThrow_WhenNoChatHistoryProviderInOptionsAndConversationIdReturnedAsync"
  • dotnet run --project dotnet/tests/Microsoft.Agents.AI.UnitTests/Microsoft.Agents.AI.UnitTests.csproj --framework net10.0 -- --filter-class "Microsoft.Agents.AI.UnitTests.ChatClientAgent_ChatHistoryManagementTests"
  • dotnet build dotnet/src/Microsoft.Agents.AI/Microsoft.Agents.AI.csproj --no-restore
  • dotnet build dotnet/tests/Microsoft.Agents.AI.UnitTests/Microsoft.Agents.AI.UnitTests.csproj --no-restore
  • git diff --check

Notes: full solution dotnet build dotnet/agent-framework-dotnet.slnx --no-restore still fails locally on unrelated projects that have no restored assets and an existing MCP unit-test reference error.

Copilot AI review requested due to automatic review settings May 28, 2026 10:27
@moonbox3 moonbox3 added the .NET label May 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates ChatClientAgent to propagate the service-returned conversation id into ChatOptions during a run, and strengthens a unit test to ensure local history is not persisted when no provider is configured in options.

Changes:

  • Set ChatOptions.ConversationId from the chat response conversation id in both non-streaming and streaming paths.
  • Add an assertion in unit tests that local in-memory history remains empty when no provider is configured via options.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ChatHistoryManagementTests.cs Extends a test to verify no local history persistence occurs in the “no provider in options” scenario.
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs Introduces SetResponseConversationId and applies it so the response conversation id is reflected in ChatOptions.

Comment on lines +1011 to +1021
private static ChatOptions? SetResponseConversationId(ChatOptions? chatOptions, string? responseConversationId)
{
if (string.IsNullOrWhiteSpace(responseConversationId))
{
return chatOptions;
}

chatOptions ??= new();
chatOptions.ConversationId ??= responseConversationId;
return chatOptions;
}
Comment on lines +412 to +414
var inMemoryProvider = agent.ChatHistoryProvider as InMemoryChatHistoryProvider;
Assert.NotNull(inMemoryProvider);
Assert.Empty(inMemoryProvider.GetMessages(session));
Comment on lines +1011 to +1021
private static ChatOptions? SetResponseConversationId(ChatOptions? chatOptions, string? responseConversationId)
{
if (string.IsNullOrWhiteSpace(responseConversationId))
{
return chatOptions;
}

chatOptions ??= new();
chatOptions.ConversationId ??= responseConversationId;
return chatOptions;
}
@github-actions github-actions Bot changed the title fix: avoid local history when service returns conversation id .NET: fix: avoid local history when service returns conversation id May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: InMemoryChatHistoryProvider used even when service stores history (OpenAI Responses)

3 participants