Repository navigation
Description
Summary
Enable agents served via public links to maintain persistent, per-user memory across sessions. When a verified user sends a message, the platform retrieves their memory from the database, injects it into the agent's context at runtime, and after each conversation the system summarizes what was learned and writes it back. One agent, many users — each with their own private memory.
Motivation
Today, public chat sessions replay the last 10 conversation turns as raw context. This breaks for long conversations (context pressure), loses facts from early sessions, and has no memory across separate visits. With per-user memory, a public agent can truly personalize its behavior — remembering a user's name, preferences, goals, and history without any work from the agent author.
Design
Scope
- Memory is scoped to
(agent_name, user_email)— per agent, per user, cross-session - Email verification is required — no memory for anonymous sessions
- Memory is a plain text blob (not vector DB, not structured JSON) — simplest viable start
New Table: public_user_memory
CREATE TABLE IF NOT EXISTS public_user_memory (
id TEXT PRIMARY KEY,
agent_name TEXT NOT NULL,
user_email TEXT NOT NULL,
memory_text TEXT NOT NULL DEFAULT '',
message_count INTEGER DEFAULT 0,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL,
UNIQUE(agent_name, user_email)
);
CREATE INDEX idx_public_user_memory_lookup ON public_user_memory(agent_name, user_email);No changes to existing public_chat_sessions or public_chat_messages tables.
Request Flow (before agent receives message)
In POST /api/public/chat/{token} (src/backend/routers/public.py), after email verification:
- Look up
public_user_memoryfor(agent_name, verified_email) - If found and
memory_textis non-empty, prepend a user context block to the system prompt:
## What you know about this user
{memory_text}
---
- Pass this as
system_promptintotask_execution_service.execute_task()— it gets forwarded via--append-system-prompt, layered on top of the existing platform instructions
The context_prompt (conversation history) continues unchanged as the message parameter.
Memory Update Flow (after agent responds)
After execution completes (both sync and async paths), if identifier_type == "email":
- Increment
message_counton thepublic_user_memoryrow (create it if first message) - Every 5 messages, trigger a background summarization task:
- Fetch the last 20 messages from
public_chat_messagesfor this session - Call a lightweight LLM (e.g.,
claude-haikuor whatever model is configured) with a summarization prompt:You are a memory system. Given this conversation, extract a concise bullet list of facts about the user that would be useful to remember for future conversations. Be specific: name, preferences, goals, context. Max 300 words. Existing memory: {current_memory_text} New conversation: {last_20_messages} Output: updated memory text only. - Write the result back to
public_user_memory.memory_text
- Fetch the last 20 messages from
This is fire-and-forget — the user's current request is never blocked by summarization.
No new endpoints required for v1
Memory is managed entirely by the platform. Admin visibility can be added later.
Files to Change
| File | Change |
|---|---|
src/backend/db/schema.py |
Add public_user_memory table + index |
src/backend/db/public_links.py |
Add get_or_create_user_memory(), update_user_memory(), increment_message_count() |
src/backend/database.py |
Delegation methods for new DB ops |
src/backend/routers/public.py |
Fetch memory + inject into system_prompt; trigger background summarization after response |
src/backend/services/platform_prompt_service.py |
Helper to format user memory block |
Acceptance Criteria
-
public_user_memorytable created via migration inschema.py - First message from a verified user creates a memory row (empty
memory_text) - Subsequent messages include existing
memory_textinsystem_promptvia--append-system-prompt - After every 5th message, background summarization runs and updates
memory_text - Anonymous sessions are unaffected (no memory, no change to existing flow)
- No performance impact on the hot path (summarization is fire-and-forget)
- Summarization failures are logged but do not surface as errors to the user
Out of Scope (follow-up)
- Admin UI to view/edit/delete user memories
- Per-link toggle to enable/disable memory
- Cross-agent memory (memory shared across agents)
- Vector/semantic memory — text blob is sufficient for v1
- User-facing memory transparency (showing users what is remembered)
Related
src/backend/routers/public.py— public chat handlersrc/backend/services/platform_prompt_service.py—--append-system-promptinjectiondocs/memory/feature-flows/public-agent-links.md— feature flow- Requirements 15.1 (Public Agent Links), 15.1c (Session Memory spec)
Activity
vybe commentedon Mar 19, 2026
Implemented MEM-001: Per-user persistent memory for public link agents.
What was built:
public_user_memorytable: plain-text memory blob scoped to(agent_name, user_email)get_or_create_user_memory(),increment_message_count(),update_user_memory()inPublicLinkOperationsformat_user_memory_block()helper inplatform_prompt_service.pysystem_promptfor all email-verified sessions (sync + async paths)_summarize_user_memory()every 5 messages (claude-haiku)tests/test_public_user_memory.pyAll acceptance criteria met. Anonymous sessions unaffected.
feat: Per-user persistent memory for public link agents (MEM-001)
chore(enterprise): bump submodule pointer f5d69be6 → 7f40361 (ent#185) (