Skip to content

Commit 784cf57

Browse files
committed
feat: enhanced memory flows for better handle loaded conversation
1 parent 5b71282 commit 784cf57

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

AgentCrew/modules/chat/message/conversation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ def load_conversation(self, conversation_id: str) -> Optional[List[Dict[str, Any
111111
self.message_handler.current_conversation_id
112112
)
113113
self.message_handler.memory_service.loaded_conversation = True
114+
self.message_handler.memory_service.load_conversation_context(
115+
self.message_handler.current_conversation_id
116+
)
114117
last_agent_name = history[-1].get("agent", "")
115118
if last_agent_name and self.message_handler.agent_manager.select_agent(
116119
last_agent_name

AgentCrew/modules/memory/base_service.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ async def need_generate_user_context(self, user_input) -> bool:
4949
def clear_conversation_context(self):
5050
pass
5151

52+
@abstractmethod
53+
def load_conversation_context(self, session_id: str):
54+
pass
55+
5256
@abstractmethod
5357
def generate_user_context(self, user_input: str, agent_name: str = "None") -> str:
5458
"""

AgentCrew/modules/memory/chroma_service.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,21 @@ async def need_generate_user_context(self, user_input: str) -> bool:
378378

379379
def clear_conversation_context(self):
380380
self.current_embedding_context = None
381+
self.current_conversation_context = {}
381382
self.context_embedding = []
382383

384+
def load_conversation_context(self, session_id: str):
385+
collection = self._initialize_collection()
386+
latest_memory = collection.get(
387+
where={
388+
"session_id": session_id,
389+
},
390+
)
391+
if latest_memory["documents"]:
392+
self.current_conversation_context[session_id] = latest_memory["documents"][
393+
-1
394+
]
395+
383396
def generate_user_context(self, user_input: str, agent_name: str = "None") -> str:
384397
"""
385398
Generate context based on user input by retrieving relevant memories.

0 commit comments

Comments
 (0)