fixbug: recovered role can't observe new message

This commit is contained in:
莘权 马 2024-08-21 13:26:50 +08:00
parent ab846f65e4
commit 8a9cd6a2e7
3 changed files with 14 additions and 3 deletions

View file

@ -81,7 +81,7 @@ class Memory(BaseModel):
return self.storage[-k:]
def find_news(self, observed: list[Message], k=0) -> list[Message]:
"""find news (previously unseen messages) from the the most recent k memories, from all memories when k=0"""
"""find news (previously unseen messages) from the most recent k memories, from all memories when k=0"""
already_observed = self.get(k)
news: list[Message] = []
for i in observed:

View file

@ -422,8 +422,8 @@ class Role(SerializationMixin, ContextMixin, BaseModel):
"""Prepare new messages for processing from the message buffer and other sources."""
# Read unprocessed messages from the msg buffer.
news = []
if self.recovered:
news = [self.latest_observed_msg] if self.latest_observed_msg else []
if self.recovered and self.latest_observed_msg:
news = self.rc.memory.find_news(observed=[self.latest_observed_msg], k=10)
if not news:
news = self.rc.msg_buffer.pop_all()
# Store the read messages in your own memory to prevent duplicate processing.