Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

docs(memory): add architecture documentation for memory feature

Steven Enamakelaad330a8dee8
diff --git a/gitbooks/developing/architecture/memory.md b/gitbooks/developing/architecture/memory.md
new file mode 100644
index 0000000000..ddb055dd92
--- /dev/null
+++ b/gitbooks/developing/architecture/memory.md
@@ -0,0 +1,50 @@
+---
+description: >-
+ The Memory v2 host layer in crates/openhuman-core/src/memory/ and the
+ TinyMemory crates it sits on.
+icon: diagram-project
+---
+
+# Memory (`crates/openhuman-core/src/memory/`)
+
+Memory v2 is three operations (Recall, Fetch, Store) over a pluggable engine, plus an engine-neutral `context.md`. The contract lives in TinyMemory (`vendor/tinymemory/docs/specs/memory-v2.md`); the OpenHuman side is `docs/specs/memory-v2.md`. The user-facing feature is described in [Memory](../../features/memory.md).
+
+## TinyMemory crates (`vendor/tinymemory/crates/`)
+
+| Crate | Owns |
+| --- | --- |
+| `tinymemory-api` | `MemoryEngine`, request/response types, `MemoryMeta`, `MetaFilter`, `EngineDescriptor`, `Error`. No I/O. |
+| `tinymemory-cortex` | The CortexDB engine, registered as `cortexdb` (direct `/v1/*`) and `tinyhumans` (behind the backend `/memory/*`, host bearer). |
+| `tinymemory-documents` | Format sniffing and conversion to markdown. |
+| `tinymemory-sources` | Readers for folder, file, link, github, rss and composio payloads, with the SSRF guard. |
+| `tinymemory-safety` | Secret and PII scrubbing before every store. |
+| `tinymemory-context` | `ContextCompiler` for `context.md`. |
+| `tinymemory-import` | Reads a legacy v1 workspace and yields items. |
+| `tinymemory-conformance` | Behaviour suite every engine passes, plus a reference engine. |
+| `tinymemory` | Facade: engine registry, `MemoryConfig`, `build_engine`. |
+
+## Host modules
+
+| Module | Role |
+| --- | --- |
+| `engine` | Binds `[memory] engine`: `tinyhumans` over the host's backend credential (resolved per request), or `cortexdb` with the key stored as `memory-cortexdb`. Engines are cached per config fingerprint. Off when neither is usable. |
+| `ops` | Select engine, recall, fetch, learn, forget, list. `store_item` scrubs before storing. |
+| `tools` | The single `memory` agent tool (`recall`, `fetch`, `learn`, `forget`); not registered when memory is off. |
+| `conversations` | Per-thread buffering of committed turns; stores a `Conversation` item at `batch_turns` or `idle_secs`. Tool calls keep name and id only. |
+| `sources` | The `[[memory.sources]]` registry, on-demand and scheduled sync. |
+| `context` | Compiles, reads and injects `<workspace>/memory/context.md` (cron job `memory_context_refresh`, default every 360 minutes). |
+| `import` | Consent-gated, resumable import of a v1 store; state in `<workspace>/memory/import_state.json`. |
+| `exit` | Flushes buffered conversation turns on quit within a 2 second budget. |
+| `bus` | Turn-commit and cron subscribers, and the idle flusher. |
+| `schemas` | The `openhuman.memory_*` controllers (engines, recall, fetch, learn, forget, items, conversations, sources, context, import). |
+| `status`, `error`, `types` | Engine status, `MEMORY_OFF` / `UNSUPPORTED` / `INVALID_REQUEST` / `UNAUTHORIZED` / `ENGINE` errors, shared types. |
+
+The session host prepends `context.md`, wrapped in `<memory-context>`, as the first user message of a new session only; resumed sessions keep their frozen transcript.
+
+Chat thread persistence is not memory. The JSONL thread store (formerly `memory::conversations` over `tinymemory-conversations`) is now `tinyagents_session::threads` in `vendor/tinyagents`, wrapped by `crates/openhuman-core/src/threads/store`.
+
+The MCP server exposes `memory.recall`, `memory.fetch`, `memory.list`, `memory.learn` and `memory.forget` (`mcp/server/tools/specs.rs`).
+
+## Tests
+
+`tests/memory_v2_e2e.rs` (JSON-RPC), `app/test/playwright/specs/memory-v2.spec.ts` (UI), and unit tests beside each module (`*_tests.rs`).
diff --git a/gitbooks/features/memory.md b/gitbooks/features/memory.md
new file mode 100644
index 0000000000..3c82e1463e
--- /dev/null
+++ b/gitbooks/features/memory.md
@@ -0,0 +1,78 @@
+---
+description: >-
+ Memory v2: a pluggable engine that stores your documents, conversations and
+ learnings, answers questions with citations, and keeps a brief for new chats.
+icon: brain
+---
+
+# Memory
+
+OpenHuman's memory lets the agent remember you across chats: what you are working on, what you prefer, what is in your documents. Memory is a feature of the app, not a hidden database. You pick who stores it, see what is stored, and delete anything.
+
+Open it from **Connections → Memory**. It has six tabs (chips): **Engine**, **Ask**, **Learnings**, **Conversations**, **Documents** and **Context**. The old `/brain` and `/settings/memory-engine` addresses redirect there.
+
+## Engines
+
+An engine stores your memory and answers questions about it. There are two:
+
+| Engine | What it is | Needs |
+| --- | --- | --- |
+| **TinyHumans** | Hosted CortexDB run by TinyHumans | You are signed in |
+| **CortexDB** | Your own CortexDB | An endpoint and an API key (kept in the OS keychain) |
+
+Pick one on the **Engine** tab. If you are signed out and have no CortexDB key, memory is **off**: the agent has no memory tool, nothing is stored, and the Memory page tells you why.
+
+## What the engine does
+
+- **Recall** answers a question in plain language and cites the stored items it relied on. The engine implements it.
+- **Fetch** is raw search over stored items with metadata filters (folder, repo, thread, source, time window). Both launch engines support hybrid search only.
+- **Store** takes three kinds of items: documents, conversations and learnings.
+
+## What gets stored
+
+### Documents
+
+Add a **source** on the **Documents** tab. A source is one of:
+
+| Kind | Target |
+| --- | --- |
+| `folder` | A folder on your computer |
+| `file` | A single file |
+| `link` | A web page |
+| `github` | A repository (`owner/repo`) |
+| `rss` | A feed URL |
+| `composio` | A connected integration (Composio toolkit) |
+
+Sources sync when you press sync and on a schedule you set per source. An unchanged file that syncs again is not stored twice. Removing a source can also forget the items it produced.
+
+### Conversations
+
+After a few committed turns in a thread, or once a thread has been idle for a while, OpenHuman stores the recent turns as one conversation item. Defaults are every 4 turns or 120 seconds idle; change them on the **Conversations** tab, which also lets you turn it off. Tool calls are stored by name and id only, never their arguments. Anything still buffered is flushed when you quit the app, within a short time limit.
+
+### Learnings
+
+A learning is one durable statement: a preference, fact, procedure or correction. The agent saves them with its `memory` tool (`learn` action), and you can add or delete them on the **Learnings** tab.
+
+Everything is scrubbed for secrets and personal identifiers before it leaves your machine.
+
+## The agent's memory tool
+
+The agent has one tool, `memory`, with four actions: `recall`, `fetch`, `learn` and `forget`. OpenHuman's own [MCP server](../developing/mcp-server.md) exposes the same abilities to other apps as `memory.recall`, `memory.fetch`, `memory.list`, `memory.learn` and `memory.forget`.
+
+## context.md
+
+Every six hours (and on demand from the **Context** tab) OpenHuman asks the engine for a short brief about you: who you are, active work, preferences and standing instructions, recent important events, plus your learnings. It is saved as `<workspace>/memory/context.md`, trimmed to a token budget (default 2000), and placed at the start of **new** chats only. A chat you resume keeps the prompt it started with, so it does not see a newer brief. Interval, budget and an on/off switch are on the **Context** tab.
+
+## Importing your previous memory
+
+If OpenHuman finds memory from the earlier (v1) version, the Memory page offers a one-time import. It uploads that data to the engine you selected, so it only starts after you explicitly consent. It resumes if interrupted.
+
+## Removed in v2
+
+The memory tree, graph view, goals list, people and contacts, learning profile, `MEMORY.md` and `PROFILE.md`, the Obsidian vault, the local TinyCortex engine and the Supermemory, Mem0, Cognee and agentMemory engines are gone, as is engine migration. See the [spec](https://github.com/tinyhumansai/openhuman/blob/main/docs/specs/memory-v2.md).
+
+## See also
+
+- [Memory architecture](../developing/architecture/memory.md)
+- [Pluggable engines](../developing/engines.md)
+- [Privacy and security](privacy-and-security.md)