How langchain-ai/memory-agent works
This is a LangGraph ReAct memory agent: a user sends conversation messages, the graph retrieves user-scoped memories, asks a configured chat model to respond or request memory updates, and stores requested updates before continuing the graph. Memory is scoped by configurable user_id so it can be reused across threads. The graph, context, prompt, state, tool, and model-loader modules are represented; the store and model are runtime-provided dependencies. Relationships are based on the README and sampled source; the memory-review UI link is documented but its implementation is outside this repository.
Main entry points: graph.py Agent graph · tools.py Memory upsert tool · context.py Agent context · utils.py Model loader
Components 11
Conversation orchestration
- Agent graph
src/memory_agent/graph.py - Message state
src/memory_agent/state.py
Memory operations
- Memory upsert tool
src/memory_agent/tools.py - Memory store
Runtime configuration
- Agent context
src/memory_agent/context.py - System prompt
src/memory_agent/prompts.py - Model loader
src/memory_agent/utils.py
Other components
- User
- Chat model
- Studio or API
- Memory explorer
Connections 16
- User → Studio or API: sends messages
README.md - Studio or API → Agent graph: invokes
README.md - Agent graph → Studio or API: returns replies
README.md - Agent graph → Message state: updates messages
src/memory_agent/graph.py - Agent graph → Agent context: reads runtime settings
src/memory_agent/graph.py - Agent context → System prompt: defaults prompt
src/memory_agent/context.py - Agent graph → Memory store: searches memories
src/memory_agent/graph.py - Memory store → Agent graph: returns matches
src/memory_agent/graph.py - Agent graph → Model loader: loads model
src/memory_agent/graph.py - Model loader → Chat model: initializes
src/memory_agent/utils.py - Agent graph → Chat model: invokes with prompt
src/memory_agent/graph.py - Chat model → Agent graph: returns reply or tool calls
src/memory_agent/graph.py - Agent graph → Memory upsert tool: executes tool calls
src/memory_agent/graph.py - Memory upsert tool → Memory store: writes memory
src/memory_agent/tools.py - Agent graph → Agent graph: repeats after storage
src/memory_agent/graph.py - Memory explorer → Memory store: reviews saved memories
README.md