long-term-vector-memory
Skill0 starsChanged 6 months agoMITView on GitHub
Adds long-term user-specific memory to agents using the @remember decorator with InMemoryUserMemoryStore. Use when an agent needs to remember facts about individual users across sessions, extracting preferences/facts from conversations and injecting them into future system prompts, or building personalized assistants.
In this repository65 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/building-agents/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llms-full.txtllms.txt
- llms.txtllms.txt
- adding-guardrailsSkill
- agent-health-timeoutSkill
- agent-permission-scopingSkill
- agent-session-isolationSkill
- agent-step-loggingSkill
- agent-supervisor-routerSkill
- agent-telemetrySkill
- async-agent-backgroundSkill
- building-agentsSkill
- building-teamsSkill
- building-toolsSkill
- calendar-scheduling-toolSkill
- callback-tracing-handlerSkill
- chain-of-thought-promptingSkill
- chat-model-configurationSkill
- code-execution-sandboxSkill
- common-agent-patternsSkill
- context-window-managementSkill
- conversation-memorySkill
- conversation-state-dbSkill
- database-query-toolSkill
- document-loadersSkill
- document-rerankingSkill
- email-notification-toolSkill
- embedding-model-ingestionSkill
- fallback-model-chainSkill
- few-shot-injectionSkill
- filesystem-toolSkill
- human-in-the-loopSkill
- hybrid-searchSkill
- inspecting-streamsSkill
- integrating-with-laurenSkill
- json-schema-enforcementSkill
- llm-provider-connectionSkill
- llm-rate-limitingSkill
- managing-memorySkill
- migrating-to-lauren-aiSkill
- multi-agent-delegationSkill
- multi-tool-orchestrationSkill
- multi-turn-tool-stateSkill
- output-guardrailsSkill
- plan-and-execute-agentSkill
- prompt-injection-defenseSkill
- prompt-versioningSkill
- rag-pipelineSkill
- react-agent-loopSkill
- response-validation-retrySkill
- rest-api-toolSkill
- securing-agentsSkill
- semantic-cacheSkill
- streaming-response-handlerSkill
- structured-output-parsingSkill
- sub-agent-spawningSkill
- system-prompt-templatingSkill
- testing-agentsSkill
- The first 60 shown.
The file
Files
Use
codemap find "SymbolName"to locate any symbol before reading — it gives exact file + line range and is faster than grep across the whole repo.
Long-Term Memory with Vector Store Persistence
Overview
Long-term user memory operates at a level above conversation history. Instead
of replaying raw messages, the @remember decorator:
- Injects (
inject=True) — retrieves the top-K relevant facts for the current query and prepends them to the system prompt before each LLM call. - Extracts (
extract=True) — after each turn the LLM extracts new facts from the exchange and persists them to the store.
System prompt
┌─────────────────────────────────────────────────────┐
│ ## What I remember about you: │
│ - User prefers dark mode (confidence: high) │
│ - User works on Python projects (confidence: medium)│
└─────────────────────────────────────────────────────┘Quick start
from lauren_ai import agent, remember
from lauren_ai._memory._in_memory_user import InMemoryUserMemoryStore
_memory_store = InMemoryUserMemoryStore()
@agent(model="claude-opus-4-6", system="You are a personalized assistant.")
@remember(store=_memory_store, extract=True, inject=True, top_k=5)
class PersonalizedAgent: ...Decorator order (mandatory)
@agent(model="claude-opus-4-6") # outermost — applied last
@remember(store=_memory, ...) # between @agent and @use_tools
@use_tools(my_tool) # innermost — applied first
class MyAgent: ...Python applies decorators bottom-up. @remember must sit directly below
@agent so the runner can find its metadata.
@remember parameters
| Parameter | Default | Description |
store | required | UserMemoryStore or DI token string |
extract | True | Extract new facts after each turn |
inject | True | Prepend facts to system prompt |
top_k | 5 | Maximum facts to inject per call |
extraction_model | None | Override model for fact extraction |
Accessing per-user memory
Pass user_id on each runner.run() call so the memory store can segment
facts by user:
resp = await runner.run(PersonalizedAgent(), "I prefer Python", user_id="user-42")Without user_id, facts are stored under a global key (suitable for single-user
applications).
InMemoryUserMemoryStore
The built-in in-memory store is suitable for development and testing. In
production, replace it with a database-backed implementation that satisfies
the UserMemoryStore protocol:
class UserMemoryStore(Protocol):
async def add(self, user_id: str, fact: MemoryFact) -> None: ...
async def search(self, user_id: str, query: str, *, top_k: int = 5) -> list[MemoryFact]: ...
async def delete(self, user_id: str, fact_id: str) -> None: ...
async def clear(self, user_id: str) -> None: ...Testing
Because extraction depends on the LLM parsing the conversation, unit tests
should verify that @remember attaches the correct metadata and that the
agent can run end-to-end with MockTransport:
from lauren_ai._memory import REMEMBER_META
meta = getattr(PersonalizedAgent, REMEMBER_META)
assert meta.inject is True
assert meta.extract is True
assert meta.top_k == 5For a full end-to-end test, queue two completions: one for the main answer and
one for the extraction sub-call (if extract=True).
Reference
lauren_ai._memory:REMEMBER_META,RememberMeta,rememberlauren_ai._memory._in_memory_user:InMemoryUserMemoryStorelauren_ai._memory._user:MemoryFact,UserMemoryStore- Skills:
managing-memory,conversation-memory,rag-pipeline
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

