From 511ffa46989399c3211d4564df5be1b2dd69d1d7 Mon Sep 17 00:00:00 2001 From: Hash Brown Date: Wed, 9 Oct 2024 21:10:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20follow-up=20(suggested=20questions)=20do?= =?UTF-8?q?es=20not=20refer=20to=20the=20most=20recen=E2=80=A6=20(#9122)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/core/memory/token_buffer_memory.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/core/memory/token_buffer_memory.py b/api/core/memory/token_buffer_memory.py index 60b36c50f0..72da3b0c6f 100644 --- a/api/core/memory/token_buffer_memory.py +++ b/api/core/memory/token_buffer_memory.py @@ -58,7 +58,11 @@ class TokenBufferMemory: # instead of all messages from the conversation, we only need to extract messages # that belong to the thread of last message thread_messages = extract_thread_messages(messages) - thread_messages.pop(0) + + # for newly created message, its answer is temporarily empty, we don't need to add it to memory + if thread_messages and not thread_messages[-1].answer: + thread_messages.pop() + messages = list(reversed(thread_messages)) message_file_parser = MessageFileParser(tenant_id=app_record.tenant_id, app_id=app_record.id)