Add Long-Term Memory to CrewAI Crews

CrewAI makes it easy to orchestrate multiple AI agents into a crew. But when the crew finishes a run, everything it learned is gone. This guide shows how to give your CrewAI agents persistent, shared memory using REM Labs -- so a research crew can build on last week's findings without starting from scratch.

Why Crews Need Persistent Memory

A typical CrewAI setup has a researcher agent, an analyst agent, and a writer agent. They collaborate on a task, pass findings between each other, and produce output. But the next time you run the crew, the researcher has no idea what it found yesterday. Every run starts from zero.

With a persistent memory backend, each agent can store its findings. The next run starts by recalling what was already discovered, skipping redundant work and building on prior context. More importantly, agents within the crew can share a memory namespace, so the analyst can recall what the researcher stored without explicit message passing.

Step 1: Install

pip install remlabs-memory crewai

Step 2: Configure Crew Memory

from remlabs.integrations.crewai import RemLabsCrewMemory # Each crew shares a namespace memory = RemLabsCrewMemory( api_key="sk-slop-...", crew_namespace="research-crew" )

The RemLabsCrewMemory class gives every agent in the crew access to the same persistent memory store. The crew_namespace isolates this crew's memories from other projects. Agents within the crew can read and write to the shared namespace, and memories persist across runs.

Step 3: Build a Research Crew That Remembers

from crewai import Agent, Task, Crew from remlabs import RemMemory mem = RemMemory(api_key="sk-slop-...") researcher = Agent( role="Senior Researcher", goal="Find and store key findings about the topic", backstory="You are a thorough researcher. Before starting, " "check memory for previous findings on the topic." ) analyst = Agent( role="Data Analyst", goal="Analyze findings and identify patterns", backstory="You have access to shared crew memory. " "Check what the researcher has already found." ) # Task 1: Research with memory recall research_task = Task( description="""Research the current state of AI memory systems. First, recall previous findings: {previous_findings} Then build on them with new research.""", agent=researcher ) # Task 2: Analyze with access to stored research analysis_task = Task( description="Analyze all research findings and produce a summary.", agent=analyst ) crew = Crew( agents=[researcher, analyst], tasks=[research_task, analysis_task] ) # Before running, recall previous work previous = mem.search( "AI memory systems research", namespace="research-crew", limit=10 ) context = "\n".join([r["value"] for r in previous]) if previous else "No previous findings." result = crew.kickoff(inputs={"previous_findings": context}) # After the run, store the new findings mem.set( f"research_{int(__import__('time').time())}", result.raw, namespace="research-crew", tags=["research", "ai-memory"] )

On the first run, previous_findings is empty. On subsequent runs, the crew picks up exactly where it left off. The researcher sees its own prior findings. The analyst can query the shared namespace for everything the crew has ever stored.

How Memory Search Works

When an agent searches crew memory, REM runs four retrieval paths in parallel:

Results are fused and reranked by a neural reranker. This is the same pipeline that scores 90% on LongMemEval -- applied to your crew's memories.

Namespace Patterns

You can structure namespaces however makes sense for your application:

Full reference: See the CrewAI integration docs for all configuration options, including per-agent namespaces and tag-based filtering.

Give your crew a memory

Free tier. No credit card. pip install and go.

Get started free →