# Memory Bank

> The vault's durable, privacy-classified record of what its agents and workflows learned — what it holds, how knowledge gets in (workflows write cubbies, curators propose, people accept), how agents, workflows, apps, and LLM agents read it, and what ROC shows.

Source: https://developers.manykind.ai/vaults/memory-bank/

The **Memory Bank** is the vault's long-term memory: what its agents and
workflows have learned, and how each run builds on the ones before it. It
belongs to the vault, so it belongs to the customer. Agents come and go; the
Memory Bank stays.

## What it holds

A graph of **records** and **relations**.

| Record field | Meaning |
|---|---|
| `id` | Stable id you choose. Writing the same id again updates the record. |
| `type` | What kind of thing it is, e.g. `fact`, `decision`, `principle`, `note`. |
| `title`, `body` | The content. |
| `scope` | Where it lives: the vault scope that governs who may read it. |
| `privacy` | How sensitive it is: `public`, `internal`, `private`, or `restricted`. |

A **relation** is a directed, typed edge from one record (`in`) to another
(`out`). It carries its own `scope` and `privacy`, because a link can be more
sensitive than the records it joins.

Records also move through review states (`proposed`, `accepted`, `rejected`,
`superseded`). Reads return accepted records unless they ask for other states.

### Two axes of access

Every read is gated twice:

- **Scope** decides *where* a reader may look. A reader sees only scopes their
  grants reach. An ungranted scope returns no rows, never an error.
- **Privacy** decides *how sensitive* a fact a reader may see. A vault member
  can hold a privacy ceiling (Public, Internal, Private, or Restricted).

A run reads with the permissions of the person who started it.

## How data gets in

Workflows write cubbies; curators propose; people accept.

1. A **workflow** writes its working rows to its own
   [cubby](https://developers.manykind.ai/agents/building-blocks/cubbies/), never to the Memory Bank.
2. A **curator** is an agent whose connection the vault owner gave the
   **harvester** or **analyzer** role. It reads those rows and files
   **proposed** records: statements for a person to accept (harvester), or
   measured counts (analyzer).
3. A **person** accepts or rejects each proposal in ROC. The record keeps who
   decided and when (`reviewed_by`, `reviewed_at`).
4. Workflows and agents read the **accepted** records back.

| Writer | How |
|---|---|
| A harvester | `ctx.memory.propose(record)`: always `proposed`; reads first, never rewrites a decided record, reads the write back. |
| An analyzer | `ctx.memory.proposeMetric(record)` and `ctx.memory.proposeObservation(record)`. Its `metric:` and `obs:` records stay proposed and read as "measured, not reviewed". |
| A person | ROC **Browse**: accept or reject a proposal. |

A vault that enforces curators refuses a bank write from any other agent with
`403`. `mk build` warns on a workflow's `remember` and `relate` steps for the
same reason.

`privacy` is required on every write and never defaulted. Before filing
anything, answer: *who reads this later, and does each row need its own
visibility?* A record or edge above the writer's own privacy ceiling is refused
with `403 PRIVACY_ABOVE_CEILING`.

```ts

await ctx.memory.propose({
  id: "principle:finance-four-eyes",
  type: "principle",
  title: "Refunds over 500 need a second approver",
  body: "Agreed after the March audit.",
  scope: "finance",
  domain: "finance",
  privacy: "internal",
  props: { source: "cubby:finance/_shared/refunds", source_hash: sourceHash(auditRows) },
});
```

Work in progress belongs in a [cubby](https://developers.manykind.ai/agents/building-blocks/cubbies/). The
full pattern, with ids, cubby design and registering a curator, is in
[Build on the Memory Bank](https://developers.manykind.ai/vaults/build-on-the-memory-bank/).

## How agents and workflows read it

| Reader | How |
|---|---|
| A workflow | `recall` step: search by `match`, or list by `types` / `domains`; accepted records unless `statuses` says otherwise. |
| A code agent | `ctx.memory.search(match, opts)`, `.list(opts)`, `.record(id)`, `.neighbours(id, opts)`, `.metrics(opts)`, `.countByType()`. Rows are typed records with `status`, `domain` and `version`. |
| A widget | A named query with `tool: "search" \| "get" \| "neighbours" \| "countByType"`. See [Widgets](https://developers.manykind.ai/agents/building-blocks/widgets/). |
| Your app | `vault.memory.search`, `.list`, `.get`, `.neighbours`, `.countByType` in the Vault SDK. |
| An LLM agent | The vault's MCP endpoint (below). |

```ts
const hits = await ctx.memory.search("refund approval", { domains: ["finance"], limit: 5 });
const rec = await ctx.memory.record(hits[0].id);   // any status: check rec?.status before acting
```

### From your app

The Vault SDK returns rows exactly as the vault sends them: a `columns` list and
positional `rows`, plus a `cursor` when more rows exist.

```ts
const page = await vault.memory.search("refund approval", { scope: "finance", limit: 20 });
// page.columns: id, type, title, scope, privacy, rank, snippet, domain, status, version
const next = page.cursor
  ? await vault.memory.search("refund approval", { scope: "finance", cursor: page.cursor })
  : undefined;
```

Read `neighbours` rows by position: the far record's `type` and the edge's
`type` share a column name.

### From an LLM agent: MCP

The vault serves its Memory Bank as MCP tools at:

```text
POST /api/v1/vaults/:vaultId/mcp
```

It is a stateless Streamable HTTP server, authenticated like any vault read.
During a run, an LLM agent that receives the run's execution token presents
it, so it searches with the permissions of the person who started the run. See
[Authentication](https://developers.manykind.ai/agents/llm-agents/bring-your-own/#authentication).

| Tool | Arguments | Limits |
|---|---|---|
| `search` | `query`, optional `domains`, `types`, `statuses`, `limit` | `limit` default 10, at most 25 |
| `get` | `ids`, optional `body_chars`, `offset` | 1 to 10 ids; `body_chars` default 4000, at most 8000 |
| `neighbours` | `id`, optional `edge_type`, `direction`, `limit` | `limit` default 10, at most 25 |
| `record_upsert` | `id`, `type`, `title`, `scope`, `privacy`, optional `body`, `status`, `domain`, `props`, `created_at` | Curator connections only; their records land `proposed`. |
| `relation_upsert` | `in`, `out`, `type`, `scope`, `privacy` | Curator connections only. Both records must be visible to the run. |
| `record_metric_upsert` | `id`, `metric_key`, `metric_value` | Analyzer connections only, on a `metric:` record that is still proposed. One value per record and key. |

Writes follow the same rules as an agent's `ctx.memory` writes: only from a
curator connection, and only into scopes the run may write. A write the rules admit answers `{"ok":true}` whether or
not a row changed; read it back with `get` to confirm.

Search matches words of three or more letters by stem, ranks records that match
more and rarer words first, and returns ids, titles, and a snippet; call `get`
for full text. Tool failures come back as MCP tool errors the model can act on;
authentication failures stay HTTP 401 or 403.

## In ROC

The **Memory Bank** page shows the vault behind the selected Agent Service, and
only what your grants reach.

| Tab | Shows |
|---|---|
| **Overview** | Ask a question and get an answer drawn from the records only; knowledge and run counts, knowledge by type, recently changed records. |
| **Journeys** | Runs for one domain and subject, step by step, with key takeaways; compare a run with others. |
| **Browse** | Search and open records; filter to **Needs review** and accept or reject a proposal (the record keeps who decided and when); **Show run entries** to include the runs' own bookkeeping. |
| **Outcomes** | What a workflow wrote and what a person decided afterwards. |

![Memory Bank Overview tab with the Ask box and knowledge counts](https://developers.manykind.ai/shots/memory-bank-overview.png)
<!-- shot: memory-bank-browse | /agent-services/:serviceId/memory?tab=browse | Browse tab with a record open -->

## Related

- [Next: Build on the Memory Bank](https://developers.manykind.ai/vaults/build-on-the-memory-bank/)
- [Vaults](https://developers.manykind.ai/vaults/overview/)
- [Members](https://developers.manykind.ai/vaults/members/)
- [Cubbies](https://developers.manykind.ai/agents/building-blocks/cubbies/)
- [Workflow steps](https://developers.manykind.ai/agents/workflows/steps/)
