Agent Memory is a database whose only job is to remember things for AI agents. You hand it text; it stores the text durably, embeds it, pulls typed facts out of it, links it to what it already knows, and gives the right pieces back when the agent asks a question later.
It is one Linux binary, agent-memory, written in Rust. There is no external
vector store, graph database or queue to run beside it.
Agents built on a chat log plus a vector index tend to fail in the same few ways:
- They forget what changed. A similarity search returns the old fact and the new one side by side, with nothing saying which one holds today.
- They can't follow a chain. "Where did my manager work before?" needs two hops through who-reports-to-whom; a nearest-neighbour lookup gives one.
- They lose writes. A memory layer that buffers in RAM and flushes "soon" drops the last few seconds of an agent's life on a crash.
Agent Memory treats these as storage problems:
- Every write goes to a write-ahead log and is
fsynced before it is acknowledged. - Each memory is turned into entities, statements and relations with provenance and validity times, so newer facts can supersede older ones explicitly.
- A recall uses several retrievers at once (vector, keyword, graph) and can walk relations across hops.
The server needs Linux: its shard runtime is Glommio on io_uring. On macOS or
Windows, run the container image or use the dev container.
The published image ships the embedding model and the GLiNER classifier, so it needs no model download at startup.
docker run -d --name agent-memory \
-p 8080:8080 -p 9091:9091 \
--security-opt seccomp=unconfined --ulimit memlock=-1 \
-e AGENT_MEMORY__LLM__BROKER__URL=http://your-llm-broker:8080 \
-e AGENT_MEMORY__LLM__BROKER__SERVICE_KEY=change-me \
-e AGENT_MEMORY__ADMIN__TOKEN="$(openssl rand -hex 32)" \
-v agent-memory-data:/var/lib/agent-memory/data \
ghcr.io/shubhamk0205/agent-memory:latest
curl -fsS http://127.0.0.1:9091/healthz # process is up
curl -fsS http://127.0.0.1:9091/readyz # 200 once every shard is servingseccomp=unconfined and memlock=-1 are needed for io_uring. Or use the
compose file, which reads its settings from .env:
cp .env.example .env # fill in the three required values
docker compose up -dThe server listens on three ports:
| Port | What | Who should reach it |
|---|---|---|
8080 |
Data plane: the binary wire protocol (CBOR frames) | your agents / SDK |
9091 |
/healthz, /readyz, /metrics |
load balancer, Prometheus |
9092 |
Admin HTTP API (/v1/*: API keys, workers, snapshots, audit) |
operators only; binds to loopback |
Port 8080 speaks a binary protocol, not HTTP. Talk to it through a client such
as agent-memory-sdk, or implement the protocol yourself from
spec/04_wire_protocol/. The conformance corpus in
crates/agent-memory-protocol/tests/conformance/ gives the exact bytes.
DEPLOY.md covers sizing, upgrades, backups and minting the first
API key.
git clone https://github.com/shubhamk0205/agent-memory
cd agent-memory
# on a Linux host (or inside the dev container: `just docker-up && just docker-shell`)
.devcontainer/bootstrap-model.sh # fetches the models the server needs
export AGENT_MEMORY__LLM__BROKER__URL=http://127.0.0.1:8081
export AGENT_MEMORY__LLM__BROKER__SERVICE_KEY=dev
cargo run --release --bin agent-memory -- --config config/dev.tomlagent-memory --help lists the flags: --config <PATH> (default
config/dev.toml), --version and --help.
The server refuses to start if the embedding model isn't on disk. That's deliberate: it never downloads anything at runtime.
You write memories. Everything else is derived from them.
| Record | Holds | Example |
|---|---|---|
| Memory | The raw text, its 384-dim embedding, salience, links to other memories, provenance | "Sam moved the launch to Friday" |
| Entity | A canonical thing with a stable id, aliases and typed attributes | Person "Sam Ortiz", alias Sam |
| Statement | A typed claim about an entity (Fact, Preference or Event), with confidence and valid-from / valid-to times |
Event(sam, moved, "launch to Friday") |
| Relation | A typed edge between two entities, with cardinality and evidence | reports_to(sam, priya) |
Extraction runs in the background after each write, in three tiers: regex
patterns, then a GLiNER classifier, then an LLM with a response cache. A
candidate is kept only if its type is declared in an active schema. Every
shard seeds a built-in system schema under the reserved agent_memory
namespace (Person, Organization, Project, Event, Place, Concept, plus a few
predicates and relation types), so extraction works out of the box. You add
your own types with the schema DSL:
namespace acme
define entity_type Person {
attributes {
email: text optional unique
}
}
define relation_type reports_to {
from: Person
to: Person
cardinality: many-to-one
}
Tenancy. A namespace is a tenant; a space is the isolation unit an API key is bound to (one agent, one user); a session is a soft grouping inside a space. Namespaces and spaces are hard walls. A request never names its own space: the server reads it from the API key presented at handshake.
Durability. Each shard owns an mmap'd vector arena, a write-ahead log with group commit, a redb metadata store, HNSW indexes and two tantivy indexes. A write is acknowledged only after its WAL record is fsynced. The memory is searchable as soon as the acknowledgement returns. Derived work (edges, extraction, HyPE questions, lexical commit) happens later, and each stage reports its own completion.
The full model is specified in spec/02_data_model/.
RECALL takes a cue (text) and returns ranked memories:
- Fan out. The cue goes to three retrievers in parallel:
- semantic: HNSW nearest neighbours over memory embeddings;
- lexical: BM25 over memory and statement text (tantivy), so exact ids
like
ACME-1247still match; - graph: entities named in the cue are resolved, and the typed graph around them is walked.
- Fuse. The ranked lists are merged with reciprocal-rank fusion.
- Ground. For questions that name an entity, statements and relations reached from that entity are scored by hop distance. A one-hop fact ("where does Sam work") beats an equally strong fact several hops away.
- Rerank (optional). A cross-encoder can re-order the top results. It is
off by default. With it off, a request that asks for reranking fails with
CapabilityNotEnabled; it does not silently fall back.
Besides RECALL, the protocol has PLAN (a path between two states, with
step, time and branch budgets), REASON (a multi-hop explanation of how two
things connect, with evidence), typed-graph reads and writes (ENTITY_*,
STATEMENT_*, RELATION_*, GRAPH_FETCH), SUBSCRIBE for change events, and
TXN_BEGIN / TXN_COMMIT / TXN_ABORT. See
spec/05_operations/ and
spec/13_retrievers/.
Settings live in a TOML file (config/dev.toml for development,
config/docker.toml in the image). Any field can be overridden from the
environment as AGENT_MEMORY__<SECTION>__<FIELD>, with a double underscore
between levels:
AGENT_MEMORY__SERVER__LISTEN_ADDR=0.0.0.0:8080
AGENT_MEMORY__STORAGE__SHARD_COUNT=4
AGENT_MEMORY__SHARD__ARENA_CAPACITY_BYTES=4GiBThe variables you are most likely to set:
| Variable | Purpose |
|---|---|
AGENT_MEMORY__LLM__BROKER__URL |
Required. Where per-namespace LLM credentials are resolved. Only checked for presence at boot. |
AGENT_MEMORY__LLM__BROKER__SERVICE_KEY |
Required. The server's own identity to the broker. Not a provider key. |
AGENT_MEMORY__ADMIN__TOKEN |
Required for the admin API. Bearer token for /v1/*; the admin listener won't start without it. |
AGENT_MEMORY__LLM__MODEL |
Preferred LLM model id (for example gpt-4o-mini). |
AGENT_MEMORY__LLM__API_KEY |
Deprecated shard-wide key, only used by the entity disambiguator and the consolidation summarizer. Leave empty. |
AGENT_MEMORY__RERANK__ENABLED |
Turn on the cross-encoder reranker. Needs a model on disk. |
AGENT_MEMORY_EMBED_MODEL_DIR |
Directory holding the embedding model (model.safetensors, tokenizer, config). |
AGENT_MEMORY_RERANK_MODEL_DIR |
Directory holding the cross-encoder model. |
AGENT_MEMORY_LOG |
Log filter, in tracing EnvFilter syntax. Overrides [monitoring.logging] level. |
AGENT_MEMORY_VERSION, AGENT_MEMORY_WIRE_PORT, AGENT_MEMORY_HTTP_PORT |
Used only by docker-compose.yml: image tag and host ports. |
The server never stores a provider key. LLM calls are paid for with a grant resolved per namespace from the broker. A namespace without a registered key still accepts writes: the pattern and classifier tiers run, and the LLM tier reports that it was skipped.
Metrics are on :9091/metrics, all prefixed agent_memory_. Alert rules are in
config/monitoring/alerts/agent-memory-rules.yml.
Thirteen crates under crates/, listed bottom-up. A crate depends only on
crates above it in the table.
| Crate | Lines | Role |
|---|---|---|
agent-memory-core |
4.3k | Shared ids, node types, errors |
agent-memory-protocol |
23.5k | Wire format: frames, opcodes, CBOR codec, schema DSL parser |
agent-memory-storage |
13.2k | mmap vector arena and write-ahead log |
agent-memory-meta-tables |
11.3k | redb table definitions and row codecs, plus audit, HyPE and extraction-queue tables |
agent-memory-metadata |
40.2k | Graph operations over those tables: entities, statements, relations, schema store, cascades, recovery |
agent-memory-index |
11.1k | HNSW indexes and tantivy shards |
agent-memory-models |
7.2k | embed (BGE embeddings), rerank (cross-encoder), llm (provider clients and credential broker) |
agent-memory-planner |
20.9k | Query planner and pull-based executor |
agent-memory-ingest |
19.4k | extractors (pattern / classifier / LLM tiers, entity resolution) and plugins (enrichers, connectors) |
agent-memory-ops-core |
17.0k | Write model, retrievers and text indexers, memory artifacts, grounded scoring, metrics, OpError |
agent-memory-ops |
46.7k | Request handlers, write applier, single-writer submit path, dispatch |
agent-memory-workers |
37.5k | Background workers: edges, extraction, decay, consolidation, snapshots, GC |
agent-memory-server |
51.9k | The agent-memory binary (shards, connection layer, admin plane, config) and the http transport module |
agent-memory-metadata and agent-memory-ops re-export the modules that moved
into -meta-tables and -ops-core at their old paths, so
agent_memory_metadata::tables::… and agent_memory_ops::index::… still
resolve. Fuzz targets for the protocol decoders and the schema parser are in
fuzz/ (cargo-fuzz, outside the workspace).
cargo check --workspace --all-targets
cargo clippy --workspace --all-targets
cargo test --workspace # Linux only; io_uring needs memlock + seccomp in containersVersion 0.1.0: the first release under this name. Everything described above is implemented and covered by the test suite. Still expect:
- Linux only. On other hosts the server builds a stub that exits.
- No client in this repo. SDKs are separate (
agent-memory-sdk). - On-disk and wire formats may change before 1.0. There is no migration tool yet.
- Single node. Sharding is per core within one host. There is no replication.
The design specification is in spec/ and the plans are in
ROADMAP.md. To contribute, start with
CONTRIBUTING.md. To report a vulnerability, see
SECURITY.md.