Skip to content

Use Marina as an agent memory service

Give any agent a memory it can trust: it stores what it saw, what it concluded and where it stopped, and a later session picks up from there. The service runs on its own, without a world or a model. An agent needs only a URL, a credential and a space ID.

For a runnable end-to-end example, start with Put memory to work.

From the repository root, install dependencies with bun install, then provision an identity:

Terminal window
bun run memory init --db data/memory.db --name research-agent --credentials data/research-agent.json
bun run memory serve --db data/memory.db --embeddings none

The server binds 127.0.0.1:3301. The credential file contains token, principalId, spaceId, credentialId and expiresAt; its permissions are 0600. Keep it out of version control. Provisioning is an operator action, not an unauthenticated network endpoint. Repeating init with the same name issues a new credential for the same service principal and private space; use a new credential filename. Existing credentials remain valid until revoked or expired.

The default needs no model: it gives exact queries, relation traversal and text search. For paraphrase search, backups, remote use and limits, see service options.

This example uses the dependency-free Python client. It captures original evidence, writes a memory linked to that evidence, queries it symbolically, and checkpoints a durable source cursor.

Terminal window
PYTHONPATH=src/sdk python3 - <<'PY'
import json
from marina_memory import MarinaMemory
with open("data/research-agent.json") as f:
identity = json.load(f)
memory = MarinaMemory("http://127.0.0.1:3301", identity["token"], identity["spaceId"])
source = memory.capture({"role": "user", "content": "I avoid all animal products."},
session_id="intro", key="intro-source-v1")
receipt = memory.remember("I avoid all animal products.",
claim={"subject": "person:self", "predicate": "diet",
"object": {"kind": "literal", "value": "vegan"}},
source_ids=[source["id"]], key="intro-diet-v1")
print(memory.query(subject="person:self", predicate="diet")["results"])
memory.save_checkpoint({"goal": "Plan a dinner", "diet_record": receipt["id"]},
source_cursor=source["seq"], key="intro-checkpoint-v1")
print(memory.get(receipt["id"]))
PY

A fresh process can call memory.checkpoint() and continue from the stored cursor using memory.sources(after=cursor). Store raw tool outputs before replacing them with a summary. Checkpoint data is explicit agent state; the service does not infer goals or silently summarize.

The TypeScript client is MarinaMemoryClient:

import { MarinaMemoryClient } from "@marina/agent-sdk/memory";
const client = new MarinaMemoryClient(url, token);
const saved = await client.remember(spaceId, { content: "Office: Berlin", subject: "office" }, "office-1");
const corrected = await client.revise(spaceId, saved.id, 1, { content: "Office: Paris" }, "office-2");
await client.waitForIndex(spaceId, corrected);
const current = await client.get(spaceId, saved.id); // version 2
const historical = await client.get(spaceId, saved.id, 1); // original content and attributes
const evidence = await client.retrieve(spaceId, { task: "office location" });
console.log(evidence.evidence, evidence.diagnostics);

Keep the same idempotency key when retrying an ambiguous write. A different payload with that key returns 409; a competing revision with a stale expected_version also returns 409. Clients expose errors and do not retry writes automatically with fresh keys.

The stdio bridge gives Claude Code, Codex or any MCP client the same memory. It needs only the service URL and a credential:

Terminal window
bun run scripts/memory-mcp.ts --url http://127.0.0.1:3301 --credentials /absolute/path/to/data/coding-agent.json

Client interfaces has the Claude Code and Codex configuration, the TypeScript client, the portable skill and the world commands.

Inside a world, a librarian, reflector or evaluator can investigate a memory question and return a cited proposal. Nothing changes until you adopt it:

memory assist librarian Librarian Find Amber's deployment port and cite the evidence
memory jobs

See memory assistance.

The memory service reference holds the detail:

Topic What it covers
HTTP contract Every /v1/memory path.
Retrieval Search, indexes, budgets and task retrieval.
Corrections and retries Versions, idempotency keys and cancellation.
Backup and storage Backup, restore, quotas and recovery.
Review Competing claims, resolution and reusable results.
Portability Export, import, transfers and federation.
Client interfaces TypeScript, MCP, skills and world commands.
Memory assistance Helpers, delegation and adopting proposals.
Portable extensions Knowledge-graph tools, query expansion, joins and rules.