Why agent frameworks need external memory
CrewAI and LangChain are excellent frameworks for building multi-agent systems. But their built-in memory is limited to the current session. When the script ends, everything is forgotten.
Adding Mengram gives your agents persistent semantic, episodic, and procedural memory that survives across sessions and improves over time.
CrewAI integration
CrewAI has native Mengram support via the mengram extra:
pip install 'crewai[mengram]'
Configure in your crew:
from crewai import Crew, Agent, Task
# Set your Mengram API key
import os
os.environ["MENGRAM_API_KEY"] = "mg-your-key"
researcher = Agent(
role="Senior Researcher",
goal="Find relevant information on the topic",
backstory="You are an experienced researcher.",
memory=True # Enables CrewAI's memory system
)
crew = Crew(
agents=[researcher],
tasks=[...],
memory=True,
memory_config={{
"provider": "mengram",
}}
)
result = crew.kickoff()
# Memories persist across crew runs!
LangChain integration
Use Mengram as a memory backend for LangChain agents:
from langchain_openai import ChatOpenAI
from mengram import Mengram
llm = ChatOpenAI(model="gpt-4o")
m = Mengram(api_key="mg-your-key")
def agent_with_memory(user_id: str, query: str):
# Get user context from memory
profile = m.profile(user_id=user_id)
memories = m.search(query, user_id=user_id)
# Build context-aware prompt
context = "\n".join([r.memory for r in memories])
messages = [
{{"role": "system", "content": profile}},
{{"role": "user", "content": f"Relevant memories:\n{{context}}\n\nQuery: {{query}}"}}
]
response = llm.invoke(messages)
# Store the interaction
m.add(f"User: {{query}}\nAgent: {{response.content}}", user_id=user_id)
return response.content
What this enables
- Cross-session learning: Agents remember past research, decisions, and outcomes
- User-specific behavior: Each user gets personalized responses based on their history
- Workflow improvement: Procedural memory captures successful task patterns that evolve from failures
- Team memory: Multiple agents share a common memory space for collaborative knowledge
Multi-agent memory sharing
# CrewAI agents sharing memory via the same user_id
researcher = Agent(role="Researcher", memory=True)
writer = Agent(role="Writer", memory=True)
reviewer = Agent(role="Reviewer", memory=True)
# All agents in the same crew share memory
# The researcher's findings are available to the writer
# The reviewer's feedback improves future workflows
This is the power of three memory types — the researcher stores facts (semantic), the writer references past articles (episodic), and the reviewer's feedback updates the writing process (procedural).
Get started: pip install mengram-ai and grab a free API key. Full quickstart tutorial here.