Skip to content

A plugin is a program that serves one store as a Stash source. You write it in any language, and keep it in your own repository. Stash starts it, and sends it requests over the plugin protocol. The configuration reference tells how a user adds a plugin to a mount.

The Python SDK speaks this protocol for you. Read on to write a plugin in another language.

  • Stash runs the program stash-source-<plugin> from its PATH, or the command of the source.
  • Each message is one JSON-RPC 2.0 object on one line, in UTF-8. Stash writes requests to the program’s stdin, and reads responses from its stdout.
  • The program writes nothing else to stdout. A line that is not a response is skipped. Write logs to stderr: Stash writes each line to its daemon log.
  • Stash can send a request before the plugin answers the last one. Each response has the id of its request, so a plugin can answer in any order.
  • Stash times each request from when it sends it. A plugin that answers one request at a time must answer each one quickly, or the requests that wait behind it time out.
  • The plugin keeps nothing that Stash needs. Stash can stop it, and start it again, at any time. It starts a new one after the plugin exits, and after a request gets no answer in 30 seconds.
  • A new process must declare the same capabilities as the first one. If it does not, Stash refuses it until the mount starts again.
  • An answer can have at most 16 MiB.

The examples below wrap for readability. Send each object on one line.

The first request to each new process.

Request:

{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocol_version": 1,
"settings": {"user_id": "example-user"}
}
}

Response:

{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocol_version": 1,
"capabilities": ["list", "get", "search", "ingest"],
"description": "Memories for the example user in mem0."
}
}
FieldRequiredDescription
params.protocol_versionyes1. Another version fails the start.
params.settingsyesThe source’s settings table. It is an empty object when the source has none.
result.protocol_versionyes1. Another version fails the start.
result.capabilitiesyesThe methods that the plugin serves: list, get, search, ingest, and plan.
result.descriptionnoText for the source’s _sources/NAME.md page.

Refuse settings that you cannot use with a validation error. Then the source fails to start, and its _sources/NAME.md page gives the reason, with your message, in at most 200 characters. The current daily daemon log has the whole reason.

list, get, and search give records. Stash makes one file of each record, at <dir>/<name>. You choose the folder, the name, and the text.

{"id": "mem-42", "body": "The user is allergic to peanuts.\n",
"dir": "health", "name": "peanut-allergy.md",
"created_at": "2026-10-14T09:00:00Z", "updated_at": "2026-10-15T08:00:00Z"}
FieldRequiredDescription
idyesThe same for the same record in each call. get receives it.
bodyyesThe text of the file.
dirnoThe folder below the source, such as team/runbooks. With none, the source’s own folder. See Paths.
namenoThe whole file name, such as peanut-allergy.md or menu.csv. With none, the file is <date>__<words of the body>.md. See Paths.
previewnoThe line that a search shows for the record. With none, the body.
created_atnoRFC 3339 time. With no name, its date starts the file name.
updated_atnoRFC 3339 time.

A file whose name ends in .md is the body, then a YAML block with stash-fetched-at, the time that Stash fetched the record. Any other file is the body alone, so a JSON or CSV file stays valid.

A folder path is empty for the source root, or is a relative path of /-separated segments. Each segment is 1–255 UTF-8 bytes, is not . or .., and has no NUL character. A file name is one segment.

For a record’s dir and name, Stash also refuses a segment that starts with . or has a control character. Stash composes these values to Unicode NFC. A record that breaks a path rule makes its answer malformed.

Treat id as opaque data. Do not copy an external ID into name. For example, INC/4412 contains /. Use a separate safe name, or leave name out so Stash makes one from created_at and body.

When two records have one name, also with other case, the second one gets __ and 16 hex characters of the sha256 of its id before its extension.

A list or a search can name a folder, in scope, and conditions on the records of your store, in filters. Stash leaves out each one that the request does not have.

{
"scope": {"subtree": "health"},
"filters": [
{
"key": "createdAt",
"op": "gte",
"value": {"datetime": "2026-10-14T00:00:00Z"}
}
]
}
FieldDescription
scope{"exact": "health"}: the records whose dir is that folder. {"subtree": "health"}: that folder and each folder below it. "all" or left out: all records.
filters[].keyA key of the records in your store, such as createdAt.
filters[].opgt, gte, lt, lte, or eq.
filters[].value{"datetime": "<RFC 3339>"}, {"number": 3}, or {"text": "ops"}.

Each record that you give must match all of them. If you cannot apply one, answer with an unsupported error. Never ignore it, or the agent gets records from outside its folder.

One page of the records.

Request:

{
"jsonrpc": "2.0",
"id": 2,
"method": "list",
"params": {"cursor": null, "limit": 100}
}

Response:

{
"jsonrpc": "2.0",
"id": 2,
"result": {
"records": [{"id": "mem-42", "body": "..."}],
"next": "page-2"
}
}
FieldTypeRequiredDescription
params.cursorstring or nullyesThe cursor from the last response. null starts the listing.
params.limitpositive integer or nullyesThe most records in the page. null requests the plugin’s natural page.
params.scopeobject or "all"noThe folder selection from Folders and filters.
params.filtersarraynoThe filters from Folders and filters.
result.recordsarrayyesThe records in this page.
result.nextstring or nullnoThe next cursor. null or an omitted field ends the listing.

One whole record.

Request:

{
"jsonrpc": "2.0",
"id": 3,
"method": "get",
"params": {"id": "mem-42"}
}

Response:

{
"jsonrpc": "2.0",
"id": 3,
"result": {"record": {"id": "mem-42", "body": "..."}}
}
FieldTypeRequiredDescription
params.idstringyesThe record ID that list or search returned.
result.recordobjectyesThe whole record.

Answer a missing record with a not_found error.

The records that match a text, best first.

Request:

{
"jsonrpc": "2.0",
"id": 4,
"method": "search",
"params": {
"query": "allergies",
"limit": 10,
"scope": {"subtree": "health"}
}
}

Response:

{
"jsonrpc": "2.0",
"id": 4,
"result": {
"results": [
{"record": {"id": "mem-42", "body": "..."}, "score": 0.83}
]
}
}
FieldTypeRequiredDescription
params.querystringyesThe search text.
params.limitpositive integeryesThe most records to return.
params.scopeobject or "all"noThe folder selection from Folders and filters.
params.filtersarraynoThe filters from Folders and filters.
result.resultsarrayyesThe matches, best first.
result.results[].recordobjectyesOne matching record.
result.results[].scorenumbernoThe score that stash search shows.

What the mount loads when it starts. Stash asks one time, after initialize, and only a plugin that declares plan. Without plan, the mount loads nothing when it starts, and files come only from search and get.

Request:

{
"jsonrpc": "2.0",
"id": 5,
"method": "plan",
"params": {}
}

Response:

{
"jsonrpc": "2.0",
"id": 5,
"result": {
"directories": ["health", "team"],
"steps": [
{
"list": {
"limit": 25,
"scope": {"exact": "health"},
"filters": [
{
"key": "createdAt",
"op": "gte",
"value": {"datetime": "2026-10-14T00:00:00Z"}
}
]
}
},
{
"search": {
"query": "What does the user prefer?",
"limit": 10
}
}
]
}
}
FieldTypeRequiredDescription
result.directoriesarray of stringsnoFolder paths that follow Paths, to show when no record is in them. The default is [].
result.stepsarraynoAt most 10 list or search steps. The default is [].
result.steps[].listobjectper stepThe list parameters. limit is required and is at most 100.
result.steps[].searchobjectper stepThe search parameters. query and limit are required. query is not empty, and limit is at most 100.

A plan that lists or searches when the plugin does not serve that method fails the start.

The turns of an agent’s session, to write back. Stash sends ingest only when the source sets write.trajectory = {}.

Request:

{
"jsonrpc": "2.0",
"id": 6,
"method": "ingest",
"params": {
"token": "5f1c...",
"session": "session-1",
"turns": [
{
"id": "turn-1",
"role": "user",
"text": "Deploy it.",
"at": "2026-10-14T00:00:00Z"
}
]
}
}

Response:

{
"jsonrpc": "2.0",
"id": 6,
"result": {"id": "agent-sessions/session-1/5f1c.md"}
}
FieldTypeRequiredDescription
params.tokenstringyesThe idempotency token for this batch.
params.sessionstringyesThe agent session ID.
params.turnsarrayyesThe turns in the batch.
params.turns[].idstringyesThe turn ID.
params.turns[].rolestringyesuser, assistant, tool, or other.
params.turns[].textstringyesThe turn text.
params.turns[].atstringyesThe RFC 3339 time of the turn.
result.idstringyesThe ID of what the plugin wrote.

Stash sends a batch again after a failure. The same batch has the same token, so write it one time, for example under a key made from the token.

Answer a failure with a JSON-RPC error. Put its kind in data.kind:

Error response:

{"jsonrpc": "2.0", "id": 7, "error": {"code": -32000,
"message": "mem0 refused the API key", "data": {"kind": "access_denied"}}}
data.kindStash
throttled, unavailable, timeoutsends the request again, after a wait
not_foundshows that the record does not exist
access_denied, validation, malformed, unsupported, rejected, otherdoes not send the request again

To get your secrets again, for example after the store refuses a token, exit. Stash starts a new plugin for the next request, and reads its env again.

An error with no data.kind gets its kind from its JSON-RPC code: -32601 (method not found) is unsupported, -32602 (invalid params) is validation, and each other code is other. Stash shows the message on one line, after the method and the code: get: JSON-RPC error -32000: mem0 refused the API key.