Skip to content
SocialMate

SocialMate Local API

AI agents with real memory

Get AI Context: one call hands your agent the whole conversation, role-mapped and token-windowed — drop the fragile n8n memory node.

A WhatsApp trigger only hands your workflow the single message that just arrived — "Is it still available?" means nothing without the thread it belongs to. The usual n8n fix is a memory node that you wire up, configure a session key for, and hope holds state between executions. SocialMate already stores the entire conversation, so it hands you a better primitive: Get AI Context — one operation that returns the whole thread, role-mapped and token-budgeted, ready to drop into any LLM node.

The n8n memory node

  • State lives in n8n — lost on restart, fragile across executions
  • You manage session keys per contact by hand
  • Empty on the very first message of a thread
  • Ignores history that happened in the app or on your phone
  • No token budgeting — you truncate it yourself

Message → Get AI Context

  • State lives in SocialMate's synced archive — durable, survives restarts
  • Keyed by chat ID; nothing to manage
  • Full back-history on the very first agent run
  • Sees every message — app, phone, API, all of it
  • Token-windowed and role-mapped out of the box

What it returns

Message → Get AI Context fetches a chat's recent history from the synced database and shapes it for an agent. Pick the format your LLM node wants:

  • transcript — a single role-mapped string you can paste straight into a system prompt: Conversation so far:\n{{ $json.transcript }}.
  • messages — a structured array [{ role, name, content, ts, type }] for chat-model or memory nodes.
  • meta{ totalMessages, returnedMessages, truncated, oldestReturnedTs, newestReturnedTs, tokenEstimate, window } so you know exactly what fit in the window.

Roles are mapped from WhatsApp's point of view: messages from the contact become user, messages from your account become assistant. That's the exact shape an LLM expects — no transformation node in between.

GET /v1/accounts/:id/ai-context Pro
{
  "data": {
    "transcript": "Jordan: Is the 2-bed still available?\nAssistant: Yes! Want a viewing this week?\nJordan: Saturday morning works",
    "messages": [
      { "role": "user",      "name": "Jordan",    "content": "Is the 2-bed still available?", "ts": 1750000000000, "type": "text" },
      { "role": "assistant", "name": "Assistant", "content": "Yes! Want a viewing this week?", "ts": 1750000040000, "type": "text" },
      { "role": "user",      "name": "Jordan",    "content": "Saturday morning works",        "ts": 1750000090000, "type": "text" }
    ],
    "meta": { "totalMessages": 42, "returnedMessages": 18, "truncated": true, "oldestReturnedTs": 1749998000000, "newestReturnedTs": 1750000090000, "tokenEstimate": 3960, "window": { "maxMessages": 50, "maxTokens": 4000 } }
  }
}

Options

OptionDefaultWhat it does
maxMessages50How many recent messages to consider (1–500).
maxTokens4000Approximate token budget (100–32000); the window stops once it's reached so you never blow your model's context.
formatbothtranscript, messages, or both.
orderoldestoldest for chronological, newest to feed an agent newest-first.
includeTimestampsfalsePrefix each transcript line with its ISO timestamp.
beforeTsUnix-ms cutoff — window to messages before this time. Set it to the trigger message's timestamp to exclude the just-arrived line.

The agent workflow

Three nodes turn an incoming WhatsApp message into a context-aware reply:

  1. SocialMate Triggermessage.received.
  2. SocialMate → Message: Get AI Context — Chat ID ={{ $json.data.chatId }}, format: transcript, order: newest, maxTokens: 4000.
  3. Your LLM node (OpenAI, Anthropic, DeepSeek, Ollama, the n8n AI Agent…) with a system message that interpolates {{ $json.transcript }}, then SocialMate → Message: Send Text to reply.

The package ships a working DeepSeek real-estate concierge in its examples/ folder that does exactly this — see Recipes to import it.

Let the agent control WhatsApp — as a tool

Beyond memory, every SocialMate operation is exposed as an n8n AI-Agent tool (usableAsTool), so an AI Agent can send, read, look up contacts, manage groups and queue batches of personalised messages on WhatsApp on its own — deciding which tool to call for each message. Set N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE=true on your instance, add an AI Agent node, and attach SocialMate on its Tool input (the package ships an ai-agent-tool.json example). Full walkthrough on the WhatsApp AI agent tool for n8n page.

Or use MCP — Claude Desktop, Cursor, any client

SocialMate also ships a native Model Context Protocol server (socialmate-mcp): point Claude Desktop, Cursor or any MCP client at it and 44 WhatsApp tools appear natively. MCP also sidesteps a known n8n community-tool quirk (empty tool observations). One thing to know: MCP is request/response with no inbound push, so to auto-react to incoming messages you either poll whatsapp_fetch_new_messages or drive the loop from the SocialMate Trigger below. Full config, the tool catalogue and the inbound patterns are in the MCP server docs (and the WhatsApp MCP server overview).

Bring your own brain. SocialMate provides the memory, not the model. AI generation (replies, summaries, triage) inside SocialMate itself is "coming soon" and isn't shipped — you stay in control of which LLM you use, your prompts, and your costs. Get AI Context is the feed; your n8n LLM node is the brain.

Get AI Context is Pro. It reads the synced message archive, which is the Pro history lever (Free is live-only — it receives messages via the trigger but can't query the back-history). Upgrade once and every agent you build gets perfect recall. Compare plans →

Free forever · no card Download free