Skip to main content

n8n + MEMANTO

n8n Add persistent memory to your n8n workflows using MEMANTO’s REST API. n8n workflows are stateless by default — each execution starts fresh. With MEMANTO, you can store context from one workflow run and recall it in future runs, giving your automations a memory that grows over time.

How It Works

n8n Workflow -> HTTP Request nodes -> MEMANTO Server -> Moorcheh.ai
MEMANTO exposes a simple REST API. In n8n, you call it using the built-in HTTP Request node — no custom code or plugins required.

Prerequisites

  • n8n (self-hosted or cloud)
  • Moorcheh API key
  • MEMANTO server accessible from your n8n instance

Step 1: Start MEMANTO Server

On your server or locally:
pip install memanto
memanto serve
If n8n is running in the cloud or Docker, expose MEMANTO via a public URL or use a tunnel like ngrok.

Step 2: Store Your API Key in n8n

  1. Go to Settings > Credentials > New Credential
  2. Choose Header Auth
  3. Set Name: MEMANTO Auth
  4. Set Header Name: Authorization
  5. Set Header Value: Bearer mk_your_api_key

Core Workflow Patterns

Pattern 1: Activate Session + Remember

Use this at the start of a workflow to open a session and store context. Node 1 — Activate Session (HTTP Request)
FieldValue
MethodPOST
URLhttp://your-memanto-server:8000/api/v2/agents/n8n-agent/activate
AuthenticationHeader Auth → MEMANTO Auth
This returns a session_token. Use an Expression in later nodes to reference it:
{{ $node["Activate Session"].json.session_token }}
Node 2 — Remember (HTTP Request)
FieldValue
MethodPOST
URLhttp://your-memanto-server:8000/api/v2/agents/n8n-agent/remember
AuthenticationHeader Auth → MEMANTO Auth
Additional HeadersX-Session-Token: {{ $node["Activate Session"].json.session_token }}
Query Parametersmemory_type: fact
Query Parameterscontent: {{ $json.message }} (or any field from your trigger)

Pattern 2: Recall Context

Retrieve relevant memories before making an LLM call or sending a response. Node — Recall (HTTP Request)
FieldValue
MethodGET
URLhttp://your-memanto-server:8000/api/v2/agents/n8n-agent/recall
AuthenticationHeader Auth → MEMANTO Auth
Additional HeadersX-Session-Token: {{ $node["Activate Session"].json.session_token }}
Query Parametersquery: {{ $json.userMessage }}
Query Parameterslimit: 5
The response contains a memories array. Access the first result with:
{{ $json.memories[0].content }}
Or join all results into a single string using a Code node:
const memories = $input.first().json.memories || [];
return [{ json: { context: memories.map(m => `- ${m.content}`).join("
") } }];

Pattern 3: AI-Powered Answer from Memory

Let MEMANTO answer a question directly using its built-in RAG: Node — Answer (HTTP Request)
FieldValue
MethodPOST
URLhttp://your-memanto-server:8000/api/v2/agents/n8n-agent/answer
AuthenticationHeader Auth → MEMANTO Auth
Additional HeadersX-Session-Token: {{ $node["Activate Session"].json.session_token }}
Query Parametersquestion: {{ $json.question }}
Returns answer — a grounded response based on stored memories, no external LLM call needed.

Example: Customer Support Workflow

This workflow receives a customer message via webhook, recalls past context, and sends a personalized reply.
[Webhook] → [Activate Session] → [Recall Context] → [Format Prompt] → [OpenAI] → [Remember Exchange] → [Respond]
Webhook Node — receives:
{ "customer_id": "cust_123", "message": "I need help with my order" }
Activate Session — POST to /api/v2/agents/{{ $json.customer_id }}/activate Using the customer ID as the agent ID gives each customer their own isolated memory. Recall Context — GET /api/v2/agents/{{ $json.customer_id }}/recall
  • query: {{ $json.message }}
Code Node — Format Prompt
const memories = $input.first().json.memories || [];
const context = memories.length
  ? memories.map(m => `- ${m.content}`).join("
")
  : "No prior context.";

return [{
  json: {
    prompt: `Customer history:
${context}

Customer: ${$("Webhook").item.json.message}
Agent:`
  }
}];
OpenAI Node — use the formatted prompt to generate a reply. Remember Exchange — POST to /api/v2/agents/.../remember
  • content: the customer’s message and the agent’s reply

Memory Types in n8n

Set the memory_type query parameter in your Remember node to categorize what you store:
TypeWhen to use
factObjective information about the user or entity
preferenceUser likes, dislikes, or settings
decisionChoices made during the workflow
commitmentPromises or follow-up actions
eventThings that happened (order placed, ticket opened)
errorIssues or failures to avoid repeating

Persisting Session Tokens

Sessions expire after 6 hours. For long-running or scheduled workflows, extend the session: Extend Session (HTTP Request)
FieldValue
MethodPOST
URLhttp://your-memanto-server:8000/api/v2/session/extend
Query Parametersextend_hours: 6
HeadersBoth Authorization and X-Session-Token
For workflows that run on a schedule, activate a fresh session at the start of each run rather than persisting the token between executions.

Next Steps