Memory System
How agents read and write persistent, per-team memory using the memory tool.
The memories Table
Memory is stored in a simple key-value table scoped to each team:
memories (
id serial PRIMARY KEY,
teamId text NOT NULL REFERENCES teams(id),
key text NOT NULL,
content text NOT NULL,
createdAt timestamp,
updatedAt timestamp
)One row per key per team. Think of it as a persistent scratchpad that agents can read and write across all conversations.
The memory Tool
The memory tool (in lib/ai/tools/shared/memory-tool.ts) exposes four commands:
| Command | Description | Required Fields |
|---|---|---|
view | Read a specific key | key |
create | Create a new memory entry | key, content |
update | Update an existing entry | key, content, mode |
search | Find entries matching a keyword | query |
The mode field on update: "overwrite" (default) replaces the content, "append" adds to it.
The Special core Key
The core memory key is the team's base context — brand voice, business description, writing style, client preferences, recurring topics.
Agents that use prepareCall fetch this key and inject it into their system prompt:
--- TEAM CORE MEMORY ---
We are a B2B SaaS company targeting CTOs. Our tone is direct, technical, and jargon-free.
We post on LinkedIn twice a week. Never use generic AI buzzwords.
------------------------
This context persists across every conversation without the user having to re-explain their brand each time.
To update core memory, the user can ask any agent: "Update our core memory to note that we're launching a new product next month" — the agent calls memory({ command: "update", key: "core", content: "..." }).
Searching Memory
The search command uses a SQL ILIKE query with a LIMIT 3:
SELECT * FROM memories
WHERE teamId = $1 AND content ILIKE '%query%'
LIMIT 3This is plain SQL text search — no vector embeddings, no RAG. It works well for structured memory entries (brand rules, project notes) but will not perform semantic similarity matching. A vector-based upgrade is a known future improvement.