Skip to content

Memory store: one service, two modes ​

This is the design for where Cully's data lives and how the pieces find it. The rule is the one k3s follows: one program carries the whole control plane, and a SQLite file stands where a database server would be. Every client (coding agent, browser UI, CLI) talks to one MCP contract and never learns which mode is behind it.

Choosing a mode in setup ​

Self modeHosted mode
Setupcully setup --localcully setup --mcp-url https://your-cully/mcp
What the agent starts or callscully mcp serve over stdioThe hosted MCP over streamable HTTP (OAuth)
RecordsSQLite file ~/.cully/memory.dbPostgreSQL, behind the Cully data API
Text searchSQLite FTS5PostgreSQL full-text
Semantic recallsqlite-vec, over vectors the coding agent suppliesMem0
Who runs itNobody: the agent launches it per sessionAn operator (cully-mcp, cully-data, PostgreSQL, Mem0)
OwnerThe person running the processThe signed-in OAuth subject

Setup registers exactly one cully MCP entry in each agent's own config (a command entry for self mode, a url entry for hosted mode). It never overwrites a different cully entry, and cully uninstall removes only an entry it created.

Components ​

  • cully start (the same command as cully ui) serves the browser UI. With no --mcp-url it also embeds the memory service at /mcp on the same listener, behind the UI's sign-in code sent as a Bearer token, because the local service has no accounts. With --mcp-url (or CULLY_MCP_URL) it embeds nothing and uses the hosted deployment.
  • cully mcp serve is the same service on its own: stdio for an agent, or --addr for streamable HTTP.
  • memory.Service is the one request/validation layer. memory.Repository is the storage seam: the SQLite store (internal/store/sqlite) and the PostgreSQL store (internal/store/postgres, with Mem0) both implement it.
  • memory.db is a different file from cully.db, which holds only the UI's own state (tasks, agents, jobs, live events). They use different SQLite drivers and never open the same file.

One request, either mode ​

What the UI sends to the service ​

In self mode the UI process holds an in-process MCP connection to the embedded service (mcp.LocalCaller). Its saves use the same tools an agent calls, with the same validation and owner scoping, but no network and no model call:

UI eventTool
An approved agent is saved or changedcully_agent_save
A task is accepted or linked to a sessioncully_session
Workflow records and task summaries (only after you consent to sync)cully_log

In hosted mode there is no embedded service; the UI keeps the older path, where one short headless agent call relays the save through the agent's own OAuth sign-in. Because memory.db is one file, anything the UI saves is visible to a coding agent running cully mcp serve, and the reverse (SQLite file locking serialises the two processes).

Status ​

Built: the SQLite store, cully mcp serve, the shared tool list (including cully_tasks), the embedded service in cully start, the UI's in-process saves, and setup registering the stdio entry.

Still local to the UI, in cully.db: its own working state (live task events, queues, evals, jobs, caches). It is not shared memory. Reading other machines' records back (the pull side of sync) still goes through a headless agent call. Hosted-only tools (cully_optimization_*, cully_workspace_*) answer "needs the hosted Cully service" in self mode.

Running it by hand ​

sh
cully mcp serve                       # MCP on stdin/stdout: what a coding agent launches
cully mcp serve --addr 127.0.0.1:8080 # the same tools over streamable HTTP at /mcp
cully mcp serve --db ~/notes.db --owner me

The local service has no sign-in: the process runs as its owner and every record is scoped to --owner (default $USER). Bind HTTP to loopback only. The release binaries stay CGO_ENABLED=0: SQLite and sqlite-vec run as WebAssembly inside the binary.

Data model ​

Every row carries its owner, and every query filters on it.

TableHoldsNotes
entriesWork, issue, learning, decision, task and optimization recordssummary, approach, outcome, issue, learning, next_steps, occurred_at
entries_ftsFTS5 index over the text columnsKept in step by triggers
entry_vecsqlite-vec vec0 table, one vector per entryPartitioned by owner; created when the first embedding arrives, with that vector's size
sessionsAn agent session: native id, branch, assistant, linked task(owner, session_ref) is the key
agentsNamed agents as JSON definitions plus notesNames are unique per owner, ignoring case
metaschema_version, embedding_dims

A task is an entries row of type task; a session links to one. A task spans many sessions.

Tools ​

The same list is served in both modes. Each is owner-scoped.

ToolPurpose
cully_log, cully_get, cully_update, cully_deleteRecords
cully_search, cully_recall, cully_recent, cully_contextFinding prior work
cully_session, cully_session_get, cully_tasksSessions and accepted tasks
cully_agents, cully_agent_save, cully_agent_deleteNamed agents
cully_optimization_*Workflow patterns and plans (hosted service only)
cully_workspace_read, cully_workspace_writeTeam workspace (hosted service only)

The tools marked hosted-only answer a clear "needs the hosted Cully service" error from the local store.

Embeddings ​

Cully never runs an embedding model. The coding agent that calls the tool makes the vector and passes it as embedding (a list of up to 4096 numbers) on cully_log, and on cully_search or cully_recall for the query. Rules:

  • Use one model for the whole database. The first vector fixes the size; a vector of another size is refused with a message naming both sizes.
  • cully_recall with an embedding ranks by meaning (nearest neighbours inside your own records). Without one, or before anything is embedded, it falls back to FTS5 text search, so the same call always works.
  • Deleting a record deletes its vector. The hosted service ignores embedding; Mem0 indexes the text itself.

Built in the open. Apache 2.0 licensed.