Skip to content
Open
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 @@ -89,7 +89,10 @@ async def _on_new_message(self, new_message: str | ChatMessageContent) -> None:
or "thread_id" not in new_message.metadata
or new_message.metadata["thread_id"] != self._id
):
self._chat_history.add_message(new_message)
if isinstance(self._chat_history, ChatHistoryReducer):
await self._chat_history.add_message_async(new_message)
else:
self._chat_history.add_message(new_message)

async def get_messages(self) -> AsyncIterable[ChatMessageContent]:
"""Retrieve the current chat history.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ def test_initialize_with_reducer_chat_history():
assert isinstance(thread._chat_history, ChatHistoryTruncationReducer)


async def test_thread_with_reducer_auto_reduces_new_messages():
reducer = ChatHistoryTruncationReducer(target_count=1, auto_reduce=True)
thread = ChatHistoryAgentThread(chat_history=reducer, thread_id="reducer_test_thread")

await thread.on_new_message(ChatMessageContent(role=AuthorRole.USER, content="first"))
await thread.on_new_message(ChatMessageContent(role=AuthorRole.ASSISTANT, content="second"))

messages = [message async for message in thread.get_messages()]

assert len(messages) == 1
assert messages[0].content == "second"


async def test_get_response(kernel_with_ai_service: tuple[Kernel, ChatCompletionClientBase]):
kernel, _ = kernel_with_ai_service
agent = ChatCompletionAgent(
Expand Down
Loading