Skip to main content

Production-ready persistent memory for AI agents. Works with LangChain, CrewAI, AutoGen, and raw Anthropic/OpenAI SDKs.

Project description

agentmemory ๐Ÿง 

Your AI agent forgets everything. AgentMemory fixes that in 3 lines.

PyPI version Tests Python 3.10+ License: MIT


The Problem

Every time your agent starts a new session, it starts from zero.

# What happens today โ€” every single time
agent = MyAgent()
agent.chat("Hi, I'm Alice and I'm building a fraud detection system")
# โ†’ "Nice to meet you, Alice!"

# Next session...
agent = MyAgent()
agent.chat("What's my name?")
# โ†’ "I don't know your name โ€” could you tell me?"  โŒ

This isn't an AI limitation. It's a missing infrastructure layer.


The Solution

from agentmemory import MemoryStore

memory = MemoryStore(agent_id="my-agent")
memory.remember("User's name is Alice, building a fraud detection system in Python")

context = memory.get_context("What do we know about the user?")
# โ†’ "[Memory Context]\n- User's name is Alice, building a fraud detection system in Python"

That's it. Memory persists to disk. It's there next session, and the one after that.


Install

# Minimal install (SQLite episodic memory only, no external dependencies)
pip install agentmemory

# With semantic search + local embeddings (recommended)
pip install "agentmemory[chromadb,local]"

# Batteries included
pip install "agentmemory[all]"

Quick Start

With Anthropic

from agentmemory import MemoryStore
import anthropic

memory = MemoryStore(agent_id="my-agent")
client = anthropic.Anthropic()

def chat(user_input: str) -> str:
    memory.add_message("user", user_input)

    response = client.messages.create(
        model="claude-opus-4-6",
        max_tokens=1024,
        system=f"You are a helpful assistant.\n\n{memory.get_context(user_input)}",
        messages=memory.get_messages(),
    )
    reply = response.content[0].text
    memory.add_message("assistant", reply)
    return reply

chat("Hi, I'm Alice and I'm building a fraud detection system")
chat("I prefer concise code examples")
# ... restart Python ...
chat("What do you know about me?")
# โ†’ "You're Alice, and you're building a fraud detection system in Python.
#    You prefer concise code examples."  โœ…

With OpenAI

from agentmemory.adapters.openai import MemoryOpenAI

client = MemoryOpenAI(agent_id="my-agent")
client.chat("Hi, I'm Alice")
client.chat("I'm building a fraud detection system")
# Next session...
client.chat("What's my name?")  # โ†’ "Your name is Alice." โœ…

With LangChain

from agentmemory import MemoryStore
from agentmemory.adapters.langchain import MemoryHistory, inject_memory_context
from langchain_anthropic import ChatAnthropic

memory = MemoryStore(agent_id="my-agent")
history = MemoryHistory(memory_store=memory)
llm = ChatAnthropic(model="claude-opus-4-6")

history.add_user_message("Hello, I'm Alice")
messages = inject_memory_context(history.messages, memory, query="Alice")
response = llm.invoke(messages)

With CrewAI

from agentmemory import MemoryStore
from agentmemory.adapters.crewai import CrewMemoryCallback, get_memory_context_for_agent
from crewai import Agent, Task

memory = MemoryStore(agent_id="research-crew")

agent = Agent(
    role="Researcher",
    goal="Research AI topics",
    backstory=get_memory_context_for_agent(memory, "Researcher") + "\nExpert researcher.",
)

task = Task(
    description="Research memory systems for AI agents",
    expected_output="Structured research findings",
    agent=agent,
    callback=CrewMemoryCallback(memory),  # Auto-stores task output
)

How It Works

AgentMemory uses a three-tier architecture that mirrors how human memory works:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Your LLM / Agent                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚  get_context() / add_message()
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   MemoryStore                           โ”‚
โ”‚                                                         โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚   Working   โ”‚  โ”‚   Episodic   โ”‚  โ”‚   Semantic    โ”‚  โ”‚
โ”‚  โ”‚   Memory    โ”‚  โ”‚   Memory     โ”‚  โ”‚   Memory      โ”‚  โ”‚
โ”‚  โ”‚             โ”‚  โ”‚              โ”‚  โ”‚               โ”‚  โ”‚
โ”‚  โ”‚ Current     โ”‚  โ”‚ Recent       โ”‚  โ”‚ Long-term     โ”‚  โ”‚
โ”‚  โ”‚ session     โ”‚  โ”‚ history      โ”‚  โ”‚ knowledge     โ”‚  โ”‚
โ”‚  โ”‚ (in-RAM)    โ”‚  โ”‚ (SQLite)     โ”‚  โ”‚ (ChromaDB)    โ”‚  โ”‚
โ”‚  โ”‚             โ”‚  โ”‚              โ”‚  โ”‚               โ”‚  โ”‚
โ”‚  โ”‚ Auto-       โ”‚  โ”‚ Persists     โ”‚  โ”‚ Semantic      โ”‚  โ”‚
โ”‚  โ”‚ compresses  โ”‚  โ”‚ forever      โ”‚  โ”‚ search        โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Working Memory โ€” the current conversation window. Automatically compresses old messages into summaries when it nears the token limit.

Episodic Memory โ€” recent interactions stored in SQLite. No setup required. Evicts least-important entries when full.

Semantic Memory โ€” long-term facts stored as vector embeddings (ChromaDB). Retrieved by meaning, not keyword.


Features

  • Framework-agnostic โ€” works with LangChain, CrewAI, AutoGen, or any raw SDK
  • Local-first โ€” runs entirely on your machine, no cloud required
  • Auto-compression โ€” context window never overflows; old messages are summarized automatically
  • Semantic deduplication โ€” stops storing near-identical facts that pollute retrieval
  • Importance scoring โ€” critical memories survive longer; low-priority ones get evicted first
  • Pluggable backends โ€” ChromaDB (local) or Qdrant (production scale) for semantic memory
  • Zero-config defaults โ€” just MemoryStore(agent_id="x") and you're running

API Reference

MemoryStore

MemoryStore(
    agent_id: str,                        # Unique ID โ€” memories are namespaced by this
    persist_dir: str = "~/.agentmemory", # Where to store memories
    max_working_tokens: int = 4096,      # Token budget before compression triggers
    semantic_backend: str = "chromadb",  # "chromadb" | "qdrant"
    embedding_provider: str = "sentence-transformers",  # "sentence-transformers" | "openai"
    llm_provider: str = "anthropic",     # LLM for compression: "anthropic" | "openai"
    enable_dedup: bool = True,           # Deduplicate before storing
    auto_compress: bool = True,          # Auto-compress when window fills
)
Method Description
memory.remember(content, importance=5) Store a fact in episodic + semantic memory
memory.recall(query, n=5) Retrieve top-n relevant memories by meaning
memory.get_context(query, max_tokens=500) Get formatted context string for system prompt
memory.add_message(role, content) Track a conversation turn in working memory
memory.get_messages() Get current working memory as [{role, content}]
memory.compress() Manually trigger compression of working memory
memory.stats() Get memory usage stats across all tiers
memory.clear(tiers=None) Clear specific or all memory tiers

Comparison

MemGPT LangChain Memory AgentMemory
Framework MemGPT only LangChain only Any framework
Composable library No Partial Yes
Local-first Partial No Yes
Auto-compression Yes No Yes
Semantic search Yes Partial Yes
Deduplication No No Yes
PyPI installable No Yes Yes
Zero config No Partial Yes

Roadmap

  • AutoGen adapter
  • Qdrant production backend examples
  • Memory export/import (JSON)
  • Memory visualization CLI (agentmemory inspect)
  • Async support (AsyncMemoryStore)
  • MCP server integration

Contributing

Contributions are welcome. See CONTRIBUTING.md.

git clone https://github.com/pinakimishra95/agent-memory
cd agent-memory
pip install -e ".[dev]"
pytest tests/

License

MIT. See LICENSE.


Star this repo if you're tired of your agents forgetting everything. ๐ŸŒŸ

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentcortex-0.1.0.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentcortex-0.1.0-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file agentcortex-0.1.0.tar.gz.

File metadata

  • Download URL: agentcortex-0.1.0.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.9

File hashes

Hashes for agentcortex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dda6cdca78a7ec481ecd564d4201689d9354334f944a7153136b38b3ca7291f4
MD5 96786939a30428e92debe91e1c079fd0
BLAKE2b-256 8621f49265bfc14836e9ed58ecc68421d228590a870119da1bb6178e4b5e682e

See more details on using hashes here.

File details

Details for the file agentcortex-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agentcortex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d80748d5844dc256fe71a4804898caf2a32fa0a92b078b2e43eef48c33de2dc4
MD5 1a94874eb063158475ef5a83923e484d
BLAKE2b-256 e27c05235002954da3ee9c0cd078e4440fbcd5d4b29092b5409afd3422328605

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page