.NET: Remove AgentThread.GetMessagesAsync (#668)

* Remove AgentThread.GetMessagesAsync

* Remove unecessary using
This commit is contained in:
westey
2025-09-09 17:40:07 +01:00
committed by GitHub
Unverified
parent 5c3c2fe634
commit ec5ea3c8a8
7 changed files with 8 additions and 79 deletions
@@ -88,56 +88,6 @@ public class AgentThreadTests
#endregion Constructor and Property Tests
#region GetMessagesAsync Tests
[Fact]
public async Task GetMessagesAsyncReturnsEmptyListWhenNoStoreAsync()
{
// Arrange
var thread = new AgentThread();
// Act
var messages = await ToListAsync(thread.GetMessagesAsync(CancellationToken.None));
// Assert
Assert.Empty(messages);
}
[Fact]
public async Task GetMessagesAsyncReturnsEmptyListWhenAgentServiceIdAsync()
{
// Arrange
var thread = new AgentThread { ConversationId = "thread-123" };
// Act
var messages = await ToListAsync(thread.GetMessagesAsync(CancellationToken.None));
// Assert
Assert.Empty(messages);
}
[Fact]
public async Task GetMessagesAsyncReturnsMessagesFromStoreAsync()
{
// Arrange
var store = new InMemoryChatMessageStore
{
new ChatMessage(ChatRole.User, "Hello"),
new ChatMessage(ChatRole.Assistant, "Hi there!")
};
var thread = new AgentThread { MessageStore = store };
// Act
var messages = await ToListAsync(thread.GetMessagesAsync(CancellationToken.None));
// Assert
Assert.Equal(2, messages.Count);
Assert.Equal("Hello", messages[0].Text);
Assert.Equal("Hi there!", messages[1].Text);
}
#endregion GetMessagesAsync Tests
#region OnNewMessagesAsync Tests
[Fact]
@@ -32,7 +32,7 @@ public class OpenAIChatCompletionFixture : IChatClientAgentFixture
public async Task<List<ChatMessage>> GetChatHistoryAsync(AgentThread thread)
{
return await thread.GetMessagesAsync().ToListAsync();
return thread.MessageStore is null ? [] : (await thread.MessageStore.GetMessagesAsync()).ToList();
}
public Task<ChatClientAgent> CreateChatClientAgentAsync(
@@ -50,7 +50,7 @@ public class OpenAIResponseFixture(bool store) : IChatClientAgentFixture
return [.. previousMessages, responseMessage];
}
return await thread.GetMessagesAsync().ToListAsync();
return thread.MessageStore is null ? [] : (await thread.MessageStore.GetMessagesAsync()).ToList();
}
private static ChatMessage ConvertToChatMessage(ResponseItem item)