Skip to content

Get started

Get started with Agent Memory

SurrealDB Agent Memory turns messages and documents into facts that you can query. It keeps each fact with its source, when it was stated, and the facts it replaced, and it answers questions in plain language with a citation for each answer. An agent can use it as a memory that lasts between conversations, and an application can use it as a knowledge base over its own documents.

It runs on SurrealDB Cloud, so there is no server to set up. You can call it from an SDK, over REST, or from any coding assistant that speaks MCP.

If a coding agent is writing your integration, paste this prompt into it. The agent installs the SurrealDB Agent Skills, connects the Agent Memory MCP server to your context, and reads the agent guide before it writes any code:

Set me up for SurrealDB Agent Memory. Fetch https://surrealdb.com/docs/agent-memory/agents/instructions.md and follow it.

The MCP server works with Cursor, VS Code, Windsurf, Zed and OpenCode, and Claude and Codex have a SurrealDB plugin. The agent guide is the single page that an agent needs to use Agent Memory correctly.

Choose the route that matches how you work. Each one ends at the same memory, so you can switch later.

  1. Sign in to SurrealDB Studio, open your organisation, and go to Contexts. A context is one agent memory store.

  2. Create a context, then open its API keys view and create a key. Copy the key, the context ID and the context host.

  3. Paste one of the snippets below, with your own values in place of the placeholders.

npm install @surrealdb/memory
import { AgentMemory } from "@surrealdb/memory";

const memory = new AgentMemory({
  endpoint: "https://<your-context-host>",
  context: "<your-context-id>",
  apiKey: "<your-api-key>",
});

await memory.remember("Alice was promoted to CTO.");
const hits = await memory.recall("What is Alice's role?");
  • Scopes. A scope is a path such as org/acme/user/alice that decides who can read a fact. Writes take scopes, reads take lens, and each path is registered first. Contexts and scope explains how.

  • Chat. POST /chat answers a message from what the memory holds, with citations. See the REST API.

  • Documents. Uploading documents adds manuals, policies and other files to the same memory.

Note

Agent Memory runs on SurrealDB Cloud. Single-tenant deployments are available on the Enterprise plan, and self-hosted deployments in your own cloud account or data centre are in development as part of the same plan. To discuss either, contact sales. Agent Memory Enterprise lists what the plan includes.

An agent with Agent Memory can know a customer across months of conversations, keep each user's notes private from the others, answer questions about a pile of documents with a citation for every claim, and say what was true at a date in the past as well as what is true now. A team of agents can share one memory, with each agent reading only the scopes its key allows.

These guides build the most common cases from start to finish:

Each demo is a finished piece: a body of text ingested into a context, and an interactive page drawn from what the memory holds. Every demo page embeds the result and then explains how it was built, so you can repeat the steps with your own data. The Showcase lists all eight.

A pixel-art street in the Calgary game, with numbered houses and residents standing on the grass.

Calgary 1912-1913 explorer

Walk the city of Calgary built from two volumes of Henderson's Calgary Directory, where every answer a resident gives comes from a scope you can inspect.

Scopes
Two editions
Record view
Characters from the Robin Hood graph drawn as glowing circles on a dark ground, sized by how much the memory knows about each.

Robin Hood character graph

Howard Pyle's The Merry Adventures of Robin Hood ingested one chapter at a time, and drawn as the cast known at each point in the book.

observedAt
asOf
Supersession
Relations
A timeline of edits to the Vulcan article above bars showing when each claim was on the page, with removed claims in grey and uncited periods hatched in gold.

Vulcan, Alberta: an article's history

24 years of edits to one Wikipedia article in Agent Memory, and agents answering questions about what the article used to say. A small model with Agent Memory scores at least as well as a large one reading the history, for less than half the cost.

observedAt
Model comparison
Edit history
A map of the western Mediterranean with red dots for the events of the Second Punic War across Spain, Italy and North Africa, beside a list of the events.

Rome, 753 BC to AD 1453

Every year from the founding of Rome to the fall of Constantinople on a map, with rulers and control of places read back as value histories, and an export that turns any period into a prompt for an LLM.

Triples
observedAt
Value histories
same_as
Two posts from the Y2K thread, each followed by an Agent Memory bar. The bar under TheyKnow's post is open, showing his view of Y2K as serious and how it changed since his last post.

Night Owls: twenty years of forum memory

Seven agents on a simulated bulletin board react to five real events from 1999 to 2019. Each post shows what Agent Memory held on its author at that moment, and private notes from 1999 still come back in 2019.

Multi-agent
Private scopes
asOf
Twenty years
A Teams huddle drawn as a comic strip. Tomás tells Priya the pipeline bids came in under the estimate, and below his message a note from his assistant says the bid figures are confidential to supply chain until award.

Sundance Lake Loop: who can read what on a pipeline project

A fictional pipeline project in six chapters. Each employee's assistant reads Agent Memory through its own scoped key, remembers its owner's conversations, and leaves a note when its owner says something the listener should not hear.

Scoped keys
Conversation memory
asOf
Audit

These are the ideas the rest of the documentation builds on. Each one has a page of its own. If context windows, compaction and embeddings are new to you, How an AI model remembers and the two pages after it explain them first.

IdeaIn shortRead more
Contexts and scopesA context is one memory store. Inside it, scopes are paths such as org/acme/user/alice. A write goes to scopes, and a read or an API key is limited to the scopes it names.Contexts and scope
WritingA message or a document is sent to the context. A language model extracts the entities, attributes and relations in it, and each one is compared with what the memory already holds before it is stored.How it works in five minutes
Change over timeA new value replaces an old one without deleting it, so the memory can answer for any point in time as well as for now.Supersession, decay, and forget
SourcesEvery fact keeps its source: the message or document it came from, and when. Answers cite these sources.Provenance and traceability
ReadingA question goes to the fastest method that can answer it first: in chat, an earlier answer whose facts are still current, then a direct lookup in the graph, a combined vector, keyword and graph search, and last a rewritten query.Coherence, retrieval, and cost tiers
StorageAll of this is stored in a SurrealDB database as records, graph edges, vectors and documents, written in transactions.Unified substrate and authority

For the design behind these ideas, start with Principles and goals and the glossary.

Agent Memory connects to the tools an agent is usually built with:

  • Learn - the mental model, then ingest, retrieval, reasoning, operations and tuning, the Showcase and cookbooks, and the architecture underneath.

  • Integrate - SDKs, the MCP server, framework and AI SDK integrations, and migration guides.

  • Operate - contexts on SurrealDB Cloud, single-tenant Enterprise deployments, and their configuration.

  • Reference - REST, MCP tools, CLI, SDKs, configuration and errors.

The name Spectron

SurrealDB Agent Memory was developed under the project name Spectron, and the rename is arriving in stages. Already renamed: the client SDKs (@surrealdb/memory, surrealdb-memory, and so on), the framework integrations, the CLI, which is now surreal memory, the Agent Memory component of the surreal command-line tool, and the MCP server, which registers as agent-memory.

Still carrying the old name: the SPECTRON_* environment variables, and the X-Spectron-* request headers. Those are configuration and wire contract rather than things the product is called, so they are unchanged for now.

Was this page helpful?

Last updated