Dear CrewAI Community,
I am facing an issue with the way agents query external (mem0) memory, which renders the memory search ineffective.
Background:
I am trying out using mem0 as a common external memory for 2 crews. Very quickly, this is how it has been implemented in both
@CrewBase
class DocumentRetrievalCrew:
"""Document Retrieval Crew"""
agents_config = "config/document_retrieval_crew/agents.yaml"
tasks_config = "config/document_retrieval_crew/tasks.yaml"
def __init__(self, model: str, domain: str):
self.model_name = model
self.llm = LLM(model=self.model_name)
self.external_memory = ExternalMemory(
embedder_config={
"provider": "mem0",
"config": {"user_id": domain}
}
)
.
.
.
@crew
def crew(self) -> Crew:
"""Creates the Crew"""
return Crew(
agents=self.agents,
tasks=self.tasks,
process=Process.sequential,
external_memory=self.external_memory,
verbose=True,
)
The domain
is used to partition memories by setting their user_id as the domain name
Issue
I have noticed that while memories are added just fine, my crews always face issues querying the memories during a crew run. Looking at my mem0
dashboard, it seems like the agents are putting the entire task prompt wholesale into the query:
From mem0 dashboard:
Query:
"""
The domain is: <domain> Search the knowledge sources using the tools provided for
the most relevant information to the query: <query>
Only search the knowledge sources if the query is related to their descriptions.
"""
Since the entire task prompt contains a lot of extra, unnecessary information, the semantic search does not find memories relevant to this prompt, even though such memories do exist. As such, the memory searches always come out with 0 results:
Image from mem0 dashboard
I can’t even fix this in the agent prompt by instructing it to use focused queries during memory search, since memory searching in crewai doesn’t work like a tool. It seems like using the task prompt wholesale as a query for the memory search is built-in crewai behaviour.
Has anyone else faced this issue?
Possible solution:
The only possible solution I can think of is creating a custom Storage
object to wrap the mem0 memory, and pass this object as the external_memory
for my crew. This Storage object would then have to have a parser function which takes the Agent’s query and filters out irrelevant content before querying the mem0 vector database. However, this doesn’t seem like the most optimal solution.
Any help would be greatly appreciated!