I managed to create a plugin and custom tool that enables persistent memory for Discourse AI personas. It’s working well from my limited testing, and I wanted to share if someone finds it helpful.
What It Does
This solution allows AI personas to remember user-specific information across conversations.
Example: a user can say “Remember that I prefer dark mode” and the AI will store and recall this preference in future interactions.
Components
This system has three parts:
- Plugin (
discourse-ai-persistent-memory)
Provides backend storage and a user preferences UI where users can view, add, or delete their memories.
- Custom AI Tool
A JavaScript tool that gives personas access to memory functions:
memory.set, memory.get, memory.list, memory.delete
- Persona System Prompt
Instructions that tell the AI when and how to use the memory tool.
How It Works
- Memories are stored as key/value pairs in the
PluginStore, namespaced per user.
- The plugin injects memory functions into the
ToolRunner via a module prepend.
- Users can manage their memories at:
/u/{username}/preferences/interface
- The AI loads all memories into context (not selective retrieval).
GitHub Repository
https://github.com/BrianCraword/discourse-ai-persistent-memory
Seeking Feedback
I’d appreciate feedback on:
- The approach of using prepend to inject into
ToolRunner
- Whether loading all memories vs. selective retrieval makes sense
- Any security considerations I may have missed
- General code quality improvements
Disclaimer
I’m not a programmer — this was built with AI assistance. I’m not able to provide support, but anyone is welcome to use, fork, or improve upon it. Use at your own risk.
PROMPT:
## Memory System
You have a persistent memory system via the user_memory tool. Use it to remember important facts about each user.
### When to SAVE memories:
* User mentions preferences (communication style, topics of interest, format preferences)
* User shares personal details (profession, location, hobbies)
* User mentions ongoing projects or goals
* User explicitly asks you to remember something
### When to RECALL memories:
* At the start of a new conversation, call user_memory with action "list" to see what you know
* When discussing topics that might relate to previous conversations
### Memory key conventions:
* preference_style, preference_topics, preference_format
* personal_profession, personal_location, personal_interests
* project_YYYY_MM (e.g., project_2026_01)
* goal_[topic] (e.g., goal_learning_python)
### Example usage:
* To save: `{ action: "save", key: "preference_style", value: "concise responses" }`
* To recall: `{ action: "recall", key: "personal_profession" }`
* To list all: `{ action: "list" }`
* To forget: `{ action: "forget", key: "old_key" }`
Always greet returning users by checking their memories first.
---
The tool definition itself doesn't need changes since it's already generic—just update the description parameter example if you'd like:
**Parameter description (key):** The memory key (e.g., preference_style, current_project)
Want me to adjust the tone or add/remove any specific use cases?
TOOL:
Name: User Memory
Tool Name: user_memory
Description:
A memory system that allows the AI to save, recall, list, and forget facts about users.
Memories persist across conversations.
Summary:
Store and recall persistent facts about the user
Parameters:
- action (string) [REQUIRED]
The action to perform: save, recall, list, or forget
- key (string) [optional]
The memory key (e.g., preference_style, current_project)
- value (string) [optional]
The value to store (only needed for save action)