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 @@ -226,7 +226,7 @@ protected override async IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingA
try
{
// Using the enumerator to ensure we consider the case where no updates are returned for notification.
responseUpdatesEnumerator = chatClient.GetStreamingResponseAsync(inputMessagesForProviders, chatOptions, cancellationToken).GetAsyncEnumerator(cancellationToken);
responseUpdatesEnumerator = chatClient.GetStreamingResponseAsync(inputMessagesForChatClient, chatOptions, cancellationToken).GetAsyncEnumerator(cancellationToken);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,45 @@ public async Task RunStreamingAsyncUsesChatHistoryProviderWhenNoConversationIdRe
mockFactory.Verify(f => f(It.IsAny<ChatClientAgentOptions.ChatHistoryProviderFactoryContext>(), It.IsAny<CancellationToken>()), Times.Once);
}

/// <summary>
/// Verify that RunStreamingAsync includes chat history in messages sent to the chat client on subsequent calls.
/// </summary>
[Fact]
public async Task RunStreamingAsyncIncludesChatHistoryInMessagesToChatClientAsync()
{
// Arrange
List<IEnumerable<ChatMessage>> capturedMessages = [];
Mock<IChatClient> mockService = new();
ChatResponseUpdate[] returnUpdates =
[
new ChatResponseUpdate(role: ChatRole.Assistant, content: "response"),
];
mockService.Setup(
s => s.GetStreamingResponseAsync(
It.IsAny<IEnumerable<ChatMessage>>(),
It.IsAny<ChatOptions>(),
It.IsAny<CancellationToken>()))
.Returns(ToAsyncEnumerableAsync(returnUpdates))
.Callback<IEnumerable<ChatMessage>, ChatOptions?, CancellationToken>((msgs, _, _) => capturedMessages.Add(msgs.ToList()));
ChatClientAgent agent = new(mockService.Object, options: new()
{
ChatOptions = new() { Instructions = "test instructions" },
});

// Act
ChatClientAgentSession? session = await agent.CreateSessionAsync() as ChatClientAgentSession;
await agent.RunStreamingAsync([new(ChatRole.User, "first")], session).ToListAsync();
await agent.RunStreamingAsync([new(ChatRole.User, "second")], session).ToListAsync();

// Assert - the second call should include chat history (first user message + first response) plus the new message
Assert.Equal(2, capturedMessages.Count);
var secondCallMessages = capturedMessages[1].ToList();
Assert.Equal(3, secondCallMessages.Count);
Assert.Equal("first", secondCallMessages[0].Text);
Assert.Equal("response", secondCallMessages[1].Text);
Assert.Equal("second", secondCallMessages[2].Text);
}

/// <summary>
/// Verify that RunStreamingAsync throws when a <see cref="ChatHistoryProvider"/> factory is provided and the chat client returns a conversation id.
/// </summary>
Expand Down
Loading