diff --git a/mem0/memory/main.py b/mem0/memory/main.py index 99bc0b1e5a..5c6413bf86 100644 --- a/mem0/memory/main.py +++ b/mem0/memory/main.py @@ -270,13 +270,15 @@ def _should_use_agent_memory_extraction(self, messages, metadata): bool: True if should use agent memory extraction, False for user memory extraction """ # Check if agent_id is present in metadata - has_agent_id = metadata.get("agent_id") is not None - + agent_id = metadata.get("agent_id") + if agent_id is None: + return False + # Check if there are assistant role messages - has_assistant_messages = any(msg.get("role") == "assistant" for msg in messages) - - # Use agent memory extraction if agent_id is present and there are assistant messages - return has_agent_id and has_assistant_messages + for msg in messages: + if msg.get("role") == "assistant": + return True + return False def add( self,