Skip to main content

# Memory Add Messages

The `memory_add_messages` function adds messages to a persistent memory store for a given session.

- Function name: `extensions.com.cloud-apim.llm-extension.memory_add_messages`

## Supported providers​

Provider | Value | Description
--- | --- | ---
Local (in-memory) | `local` | In-memory storage, no persistence across restarts
Elasticsearch | `elasticsearch` | One document per session
OpenSearch | `opensearch` | One document per session
Redis | `redis` | JSON-serialized messages per session
HTTP (Generic) | `http` | Custom REST API backend
PostgreSQL | `postgresql` | One row per session in a PostgreSQL table

Provider-specific connection parameters are configured in the persistent memory entity's `config.connection` object (e.g., `url`, `index`, `uri`, `table`, `prefix`).

## Parameters​

Parameter | Type | Required | Description
--- | --- | --- | ---
`provider` | string | yes | The persistent memory provider id
`payload` | object | yes | The payload object
`payload.session_id` | string | yes | The session identifier
`payload.messages` | array | yes | The messages to add
`payload.messages[].role` | string | yes | The message role (e.g., `user`, `assistant`, `system`)
`payload.messages[].content` | string | yes | The message content

## Output​

Returns `null` on success.

## Example​

    {
      "kind": "call",
      "function": "extensions.com.cloud-apim.llm-extension.memory_add_messages",
      "args": {
        "provider": "memory_xxxxx",
        "payload": {
          "session_id": "session_001",
          "messages": [
            {
              "role": "user",
              "content": "What is the capital of France?"
            },
            {
              "role": "assistant",
              "content": "The capital of France is Paris."
            }
          ]
        }
      },
      "result": "add_result"
    }