LLM-readable documentation index
Function Types

Write Memory Functions

Save an Extract output as a Structured Memory entry

Hand off to an LLM

Add Write Memory to save an Extract output as an entry in Structured Memory. For example, save each processed invoice in its supplier's bucket so a later call can use it as context. Each successful save emits a write_memory event.

Configuration fields

Required fields

FieldTypeDescription
functionNamestringUnique identifier for the function (per environment)
typestringMust be "write_memory"
writeMemoryConfigobjectThe kind and kind version the function saves entries under

Set these fields in writeMemoryConfig.

FieldTypeDescription
kindNamestringName of the kind.
kindVersionNumintegerNumber of the kind version, 1 or greater.

Optional fields

FieldTypeDefaultDescription
displayNamestring-Human-readable display name
tagsstring[]-Tags for organization

Create the function with POST /v3/functions.

{
  "functionName": "invoice-memory-write",
  "type": "write_memory",
  "writeMemoryConfig": { "kindName": "invoice", "kindVersionNum": 1 }
}

On update, omit writeMemoryConfig to keep the current kind version.

Choose a kind version that stores JSON only. A version that requires a file returns 400 with MEMORY_KIND_REQUIRES_FILE. An unknown kind or version returns 400 with MEMORY_KIND_NOT_FOUND or MEMORY_KIND_VERSION_NOT_FOUND.

Use the same schema for Extract and the kind version. Write Memory removes the top-level _metadata field and validates the remaining output against the kind version before saving it as the entry's attributes.

Connect Extract to Write Memory

Connect Write Memory directly after Extract. This workflow starts at Extract and saves its result.

{
  "name": "supplier-invoices",
  "mainNodeName": "extract",
  "nodes": [
    { "name": "extract", "function": { "name": "invoice-extract" } },
    { "name": "write", "function": { "name": "invoice-memory-write" } }
  ],
  "edges": [{ "sourceNodeName": "extract", "destinationNodeName": "write" }]
}
  • A Write Memory node follows an Extract node.
  • Only a Send node can follow a Write Memory node.
  • No Write Memory node can follow a Split node.

Call input

Set memory.write to one Memory URI with the bucket and entry key.

{
  "memory": {
    "write": "bem://memory/buckets/supplier-1042/entries/INV-2041"
  }
}

The function sets the kind. If several Write Memory nodes run, each uses the same bucket and key with its configured kind.

Create the bucket before making the call. Use an unused key for that kind in the bucket. To replace an entry, delete it before calling again with the same key.

The write_memory event

A successful save emits a write_memory event. entry is the entry as it was saved, and producingCallID is the call that saved it.

{
  "eventID": "evt_3Mw7X9PAp6lflibSgPOKNfXaeQY",
  "eventType": "write_memory",
  "functionName": "invoice-memory-write",
  "callID": "wc_3Mw7Wss4M3p3Jiro2tpmdJyn6dr",
  "entry": {
    "id": "ment_3Mw7X8EzIrLiKFmYeb1aTczcTd3",
    "key": "INV-2041",
    "bucketKey": "supplier-1042",
    "kindName": "invoice",
    "kindVersionNum": 1,
    "attributes": {
      "currency": "EUR",
      "invoiceDate": "2026-11-20",
      "totalAmount": 1250,
      "supplierName": "Example Packaging Ltd.",
      "invoiceNumber": "INV-2041"
    },
    "producingCallID": "wc_3Mw7Wss4M3p3Jiro2tpmdJyn6dr"
  }
}

Look for the event where the workflow delivers it. The example omits unrelated fields.

  • When the Write Memory node is the last node on its path, the event is a call output in outputs[].
  • When a Send node follows Write Memory, find the event in the call trace and in the data passed to Send.
  • A write_memory subscription on the Write Memory function receives the event in both cases.

To receive saved entries at a webhook URL, create a subscription on the function.

curl -X POST https://api.bem.ai/v3/subscriptions \
  -H "Content-Type: application/json" \
  -H "x-api-key: $BEM_API_KEY" \
  -d '{
    "name": "invoice-entries",
    "type": "write_memory",
    "functionName": "invoice-memory-write",
    "webhookURL": "https://your-app.example.com/webhooks/bem"
  }'

Errors

A Write that fails saves nothing, and the call ends with an error event. Retrying the Write function call doesn't run the Extract again.

kindMeaning
memory_attributes_invalidThe Extract output doesn't match the kind version's schema.
memory_identity_occupiedA live entry of the kind already has the write destination's key in the bucket.
memory_bucket_not_foundThe write destination's bucket doesn't exist when the Write runs, such as after it was deleted.
memory_write_destination_invalidThe call has no valid memory.write destination.
memory_write_not_savedbem couldn't save the entry.

A second save to the same bucket, kind, and key returns this message.

memory write failed: bucket "supplier-1042" already holds an entry of kind "invoice" with key "INV-2041"

A call whose memory input doesn't fit the workflow returns 400 and runs no function. The error codes are on the Structured Memory page.

On this page