Skip to main content
For the full source code and advanced implementation details, see the official CrewAI Integration in our repository.

Overview

Integrating MemMachine with CrewAI empowers your agents with a persistent memory layer. Unlike standard session memory, this integration allows your crews to remember past interactions, learn user preferences, and maintain deep context across multiple tasks and sessions.

Configuration

The integration is primarily managed through environment variables. You can set these in your .env file or export them directly in your shell:
VariableDescriptionDefault
MEMORY_BACKEND_URLThe URL of your MemMachine backend servicehttp://localhost:8080
CREWAI_ORG_IDYour organization identifiercrewai_org
CREWAI_PROJECT_IDYour project identifiercrewai_project
CREWAI_USER_ID(Optional) Scopes memory to a specific userNone
CREWAI_SESSION_ID(Optional) Scopes memory to a specific sessionNone

1

Install Dependencies

Install the core CrewAI framework along with the MemMachine client:
pip install crewai crewai-tools memmachine-client
2

Initialize Memory Tools

The create_memmachine_tools helper simplifies the setup. This will return a list of tools that agents can use to add and search their memory.
from integrations.crewai.tool import create_memmachine_tools

# Initialize tools with your project configuration
memmachine_tools = create_memmachine_tools(
    base_url="http://localhost:8080",
    org_id="my_org",
    project_id="my_project",
    user_id="user123",
)
3

Assign Tools to Agents

Pass the memmachine_tools list to your CrewAI agents. Agents will use these tools automatically when they need to store a new finding or recall a past preference.
from crewai import Agent, Task, Crew

researcher = Agent(
    role="Research Specialist",
    goal="Identify emerging trends and remember key data points",
    backstory="You are an expert researcher. You prioritize long-term memory to avoid repeating work.",
    tools=memmachine_tools,
    verbose=True,
)
4

Execute the Crew

Once the agent is equipped with the memory tools, define your tasks and kickoff the crew.
task = Task(
    description="Research the latest 2026 AI trends and store the top 5 findings in memory.",
    agent=researcher,
)

crew = Crew(agents=[researcher], tasks=[task])
result = crew.kickoff()

Advanced Usage

Shared Team Memory

If you want multiple agents to share the same knowledge pool, initialize the tools with a group_id. This is ideal for collaborative agents where a “Writer” needs to recall information stored by a “Researcher.”
memmachine_tools = create_memmachine_tools(
    org_id="my_org",
    project_id="my_project",
    group_id="research_team", # Agents in this group share memory
)

Manual Memory Management

For more granular control, you can use the MemMachineTools class directly without the CrewAI agent wrapper.
from integrations.crewai.tool import MemMachineTools

tools = MemMachineTools(org_id="my_org", project_id="my_project")

# Manually add a specific fact
tools.add_memory(content="User prefers Python for data science.", role="user")

# Manually query memory
results = tools.search_memory(query="What is the user's preferred language?")
print(results["summary"])
Pro Tip: Use clear user_id or session_id identifiers to prevent “memory bleed” between different users or unrelated tasks.

Requirements

  • MemMachine Server: Must be reachable at the MEMORY_BACKEND_URL.
  • Python: 3.10 or higher.
  • Framework: CrewAI and crewai-tools.