{"slug": "building-a-slack-bot-that-actually-remembers-slacktag-oss", "title": "Building a Slack Bot That Actually Remembers: slacktag-oss", "summary": "A developer built slacktag-oss, an open-source Slack bot with persistent semantic memory powered by any LLM and Mem0's managed memory layer, eliminating the need for a vector database. The bot uses Mem0's cloud service for stateful memory, allowing stateless bot processes that can be restarted without losing context. The project aims to replicate the conversational continuity of commercial tools like Claude Tag while remaining provider-agnostic.", "body_md": "*How I built an open-source Slack assistant with persistent semantic memory, powered by any LLM and Mem0's managed memory layer — no vector database required.*\n\nMost AI Slack bots have the memory of a goldfish. Every conversation starts from scratch. You ask it about your sprint goals, it gives a great answer, then three days later you ask a follow-up and it has no idea what you're talking about. You end up re-explaining context constantly.\n\nThe commercial solution to this is Claude Tag — a Slack integration that maintains genuine conversational continuity. But it's tied to one provider and not open-source.\n\n`slacktag-oss`\n\nis our attempt to replicate that experience: a Slack bot with real, semantic, persistent memory that works with any LLM — including ones running entirely on your laptop.\n\nA Python Slack bot with:\n\n`!clear`\n\nand `!memory`\n\ncommandsBefore diving into code, here's the full request lifecycle:\n\n```\n┌─────────────────────────────────────────────────────────────┐\n│                         Slack                               │\n│  @mention in channel  ──┐                                   │\n│  DM to bot            ──┼──► Slack Events API               │\n│  Thread reply         ──┘         │                         │\n└───────────────────────────────────│─────────────────────────┘\n                                    │ (Socket Mode / HTTP)\n                                    ▼\n┌─────────────────────────────────────────────────────────────┐\n│                      slack-bolt (Python)                     │\n│   bot.py  ──►  router.py  ──►  handler.py                  │\n│                                    │                        │\n│                    ┌───────────────┤                        │\n│                    │               │                        │\n│                    ▼               ▼                        │\n│              Mem0 Client      LangChain                     │\n│              (managed)        ChatOpenAI                    │\n└────────────────────────────────────────────────────────────-┘\n                    │\n                    ▼\n        ┌───────────────────────┐\n        │   Mem0 Managed Cloud  │\n        │  Vector Embeddings    │\n        │  Entity Extraction    │\n        │  Deduplication        │\n        └───────────────────────┘\n```\n\nThe key design decision: **Mem0 is the only stateful dependency**. There's no database to manage, no Redis, no Qdrant. The bot process itself is stateless — you can restart it freely without losing any memory.\n\n```\nslacktag-oss/\n├── main.py\n├── config/settings.py       ← Pydantic settings from .env\n├── core/\n│   ├── bot.py               ← Slack Bolt app + event registration\n│   ├── handler.py           ← All orchestration logic lives here\n│   └── router.py            ← Dispatches channel mentions vs DMs\n├── memory/\n│   ├── base.py              ← Abstract interface\n│   ├── channel_memory.py    ← Channel + thread scoped memory\n│   ├── dm_memory.py         ← Per-user private memory\n│   └── mem0_store.py        ← Mem0 client factory\n├── llm/client.py            ← ChatOpenAI factory\n└── tools/registry.py        ← Tool plugin stub (v2)\n```\n\nThe typical approach to bot memory is a rolling window: keep the last N messages in the prompt. This breaks down fast — context gets stale, important things fall out of the window, and token costs grow linearly.\n\nMem0 takes a different approach. When you store a conversation, it:\n\nWhen you later ask a question, you get back the most *relevant* past memories — not just the most recent ones. A user's preference mentioned three weeks ago will surface when relevant, even if hundreds of messages happened in between.\n\nBecause we're using Mem0's managed cloud, the entire backend is three lines:\n\n``` python\n# memory/mem0_store.py\nfrom mem0 import MemoryClient\nfrom config.settings import settings\n\ndef get_mem0_client() -> MemoryClient:\n    return MemoryClient(api_key=settings.MEM0_API_KEY)\n```\n\nNo vector database config. No embedding model to choose. No collection names to manage.\n\nThe key insight for a Slack bot is that different conversations need different memory boundaries:\n\n``` python\n# channel_memory.py\ndef scope_id(self, channel_id: str, thread_ts: str = None) -> str:\n    if thread_ts:\n        return f\"thread:{channel_id}:{thread_ts}\"   # isolated thread\n    return f\"channel:{channel_id}\"                   # shared channel\n\n# dm_memory.py\ndef scope_id(self, user_id: str) -> str:\n    return f\"dm:{user_id}\"                           # private per user\n```\n\nMem0 uses this string as a `user_id`\n\n— anything stored under `channel:C12345`\n\nis shared by everyone in that channel. Anything under `dm:U67890`\n\nis private. Thread memory is completely isolated so a debugging session in a thread doesn't pollute the main channel's memory.\n\nBoth `ChannelMemory`\n\nand `DMMemory`\n\nimplement the same four-method interface:\n\n``` python\n# memory/base.py\nclass BaseMemory(ABC):\n    @abstractmethod\n    def add(self, messages: list[dict], scope_id: str) -> None: ...\n\n    @abstractmethod\n    def search(self, query: str, scope_id: str) -> list[dict]: ...\n\n    @abstractmethod\n    def get_all(self, scope_id: str) -> list[dict]: ...\n\n    @abstractmethod\n    def clear(self, scope_id: str) -> None: ...\n```\n\nThis makes it easy to swap backends later — implement `BaseMemory`\n\n, update the factory, done.\n\n``` python\n# llm/client.py\nfrom langchain_openai import ChatOpenAI\nfrom config.settings import settings\n\ndef get_llm() -> ChatOpenAI:\n    return ChatOpenAI(\n        base_url=settings.LLM_BASE_URL,\n        api_key=settings.LLM_API_KEY,\n        model=settings.LLM_MODEL,\n        temperature=0.7,\n        streaming=True,\n    )\n```\n\n`base_url`\n\nis the only thing that changes between providers. Ollama, LM Studio, OpenAI, Groq, Together AI — all work without touching any other code.\n\n`handler.py`\n\nis the heart of the bot. For every request, it:\n\n``` python\n# core/handler.py (simplified)\ndef handle_channel_mention(channel_id, user_id, text, thread_ts=None):\n    scope = channel_memory.scope_id(channel_id, thread_ts)\n\n    # Built-in commands short-circuit before hitting the LLM\n    if text.strip() == \"!clear\":\n        channel_memory.clear(scope)\n        return \"Memory cleared.\"\n    if text.strip() == \"!memory\":\n        return format_memories(channel_memory.get_all(scope))\n\n    # Dual retrieval: semantic + recency\n    relevant = channel_memory.search(text, scope)\n    history  = channel_memory.get_all(scope)\n\n    messages = build_messages(system_prompt, relevant, history, text)\n    response = llm.invoke(messages)\n    reply    = response.content\n\n    # Store the exchange — Mem0 extracts entities + deduplicates\n    channel_memory.add(\n        [{\"role\": \"user\", \"content\": text},\n         {\"role\": \"assistant\", \"content\": reply}],\n        scope,\n    )\n    return reply\n```\n\nThe message list passed to the LLM is assembled in a specific order:\n\n``` python\ndef build_messages(system_prompt, relevant_memories, recent_history, user_input):\n    messages = [SystemMessage(content=system_prompt)]\n\n    # Inject relevant memories as a second system message\n    if relevant_memories:\n        memory_context = \"\\n\".join(\n            m[\"memory\"] for m in relevant_memories if \"memory\" in m\n        )\n        messages.append(SystemMessage(\n            content=f\"Relevant context from earlier:\\n{memory_context}\"\n        ))\n\n    # Append recent history\n    for entry in recent_history[-MAX_HISTORY_MESSAGES:]:\n        if entry.get(\"role\") == \"user\":\n            messages.append(HumanMessage(content=entry[\"content\"]))\n        elif entry.get(\"role\") == \"assistant\":\n            messages.append(AIMessage(content=entry[\"content\"]))\n\n    # Current user message always last\n    messages.append(HumanMessage(content=user_input))\n    return messages\n```\n\nThe two-system-message pattern keeps the bot's persona and instructions separate from the injected memory context — cleaner for the model to reason about.\n\n`slack-bolt`\n\nmakes event handling clean:\n\n```\n# core/bot.py\napp = App(token=settings.SLACK_BOT_TOKEN, signing_secret=settings.SLACK_SIGNING_SECRET)\n\n@app.event(\"app_mention\")\ndef on_mention(event, say):\n    route_mention(event, say)   # channel / thread flow\n\n@app.event(\"message\")\ndef on_message(event, say):\n    if event.get(\"channel_type\") == \"im\" and not event.get(\"bot_id\"):\n        route_dm(event, say)    # DM flow, ignore bot's own messages\n```\n\n`router.py`\n\nextracts the relevant fields and calls the appropriate handler:\n\n``` python\n# core/router.py\ndef route_mention(event, say):\n    channel_id = event.get(\"channel\")\n    thread_ts  = event.get(\"thread_ts\")\n    text       = event.get(\"text\", \"\")\n\n    reply = handle_channel_mention(channel_id, event[\"user\"], text, thread_ts)\n    say(text=reply, thread_ts=thread_ts or event[\"ts\"])\n```\n\nReplies always go back to the same thread — if the mention was in a thread, the bot stays in that thread.\n\nAll config lives in one place with validation:\n\n```\n# config/settings.py\nclass Settings(BaseSettings):\n    SLACK_BOT_TOKEN: str\n    SLACK_APP_TOKEN: str\n    SLACK_SIGNING_SECRET: str\n    LLM_BASE_URL: str = \"http://localhost:11434/v1\"\n    LLM_API_KEY: str = \"ollama\"\n    LLM_MODEL: str = \"llama3.2\"\n    MEM0_API_KEY: str\n    BOT_NAME: str = \"Claude\"\n    MAX_HISTORY_MESSAGES: int = 20\n    SYSTEM_PROMPT: str = \"\"\n\n    class Config:\n        env_file = \".env\"\n```\n\nMissing required fields (the Slack tokens, the Mem0 key) raise a `ValidationError`\n\nat startup — fail fast before any event processing begins.\n\n```\n# Get dependencies\npip install -r requirements.txt\n\n# Start the bot (Socket Mode — no public URL needed)\npython main.py\n```\n\nThat's it. No Docker, no Qdrant, no ngrok. Invite the bot to a channel, `@mention`\n\nit, and it starts building memory from the first message.\n\nHere's a realistic example. Day 1:\n\nUser:@slacktag Our API rate limit is 100 req/min per tenant. Keep that in mind for capacity planning.\n\nBot:Got it. I'll factor that in for any capacity discussions.\n\nDay 3 (hundreds of messages later in the channel):\n\nUser:@slacktag We're about to onboard 5 new enterprise tenants. Any concerns?\n\nBot:A few things to consider: with your current API rate limit of 100 req/min per tenant, 5 new enterprise tenants could significantly increase peak load. You may want to review your rate limiting strategy before onboarding...\n\nMem0 surfaced the rate limit fact from Day 1 because it was semantically relevant to the capacity question — even though it was nowhere in the recent message window.\n\nFor production, swap `SocketModeHandler`\n\nfor a standard HTTP adapter:\n\n``` python\n# Using Flask\nfrom slack_bolt.adapter.flask import SlackRequestHandler\nfrom flask import Flask, request\n\nflask_app = Flask(__name__)\nhandler = SlackRequestHandler(app)\n\n@flask_app.route(\"/slack/events\", methods=[\"POST\"])\ndef events():\n    return handler.handle(request)\n```\n\nPoint your Slack app's Request URL to `https://your-domain/slack/events`\n\n, deploy anywhere (Fly.io, Railway, Cloud Run — all work), and you're done. No state in the server — Mem0 holds everything.\n\nA few extensions that would make this significantly more powerful:\n\n**Pluggable tools** — `tools/registry.py`\n\nis stubbed out for LangChain tool integration. Adding web search (Tavily, Brave Search) or a code execution sandbox would turn this into a capable agent.\n\n**Mem0 graph memory** — Mem0 supports a graph mode that tracks relationships between entities across conversations. You could map out who's on which team, what projects are in flight, and surface that context automatically.\n\n**Per-channel LLM config** — let admins set a different model per channel (e.g., a powerful model for #architecture, a fast cheap model for #random).\n\n**Reaction triggers** — react with 🧠 to explicitly add a message to memory; react with 🗑️ to remove a fact. Much more controllable than pure auto-extraction.\n\n** !summarize** — call\n\n`mem0.get_all()`\n\nand ask the LLM to produce a readable summary of everything it knows about this channel.The codebase is intentionally small. `handler.py`\n\nis ~100 lines. Every module does one thing. If you want to contribute:\n\n```\ngit clone https://github.com/harishkotra/slacktag-oss\ncd slacktag-oss\npython -m venv .venv && source .venv/bin/activate\npip install -r requirements.txt\ncp .env.example .env\n```\n\nPick any feature from the table in the README, implement it, and open a PR. The architecture is designed to stay simple — add without entangling.", "url": "https://wpnews.pro/news/building-a-slack-bot-that-actually-remembers-slacktag-oss", "canonical_source": "https://dev.to/harishkotra/building-a-slack-bot-that-actually-remembers-slacktag-oss-250f", "published_at": "2026-06-26 18:21:41+00:00", "updated_at": "2026-06-26 19:04:29.554336+00:00", "lang": "en", "topics": ["large-language-models", "developer-tools", "ai-agents", "natural-language-processing"], "entities": ["Mem0", "Slack", "LangChain", "ChatOpenAI", "Claude Tag", "Python", "Mem0 MemoryClient"], "alternates": {"html": "https://wpnews.pro/news/building-a-slack-bot-that-actually-remembers-slacktag-oss", "markdown": "https://wpnews.pro/news/building-a-slack-bot-that-actually-remembers-slacktag-oss.md", "text": "https://wpnews.pro/news/building-a-slack-bot-that-actually-remembers-slacktag-oss.txt", "jsonld": "https://wpnews.pro/news/building-a-slack-bot-that-actually-remembers-slacktag-oss.jsonld"}}