# langchain-ai/memory-agent architecture

> Architecture diagram of the GitHub repository langchain-ai/memory-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/langchain-ai/memory-agent
- Repository: https://github.com/langchain-ai/memory-agent

## Overview

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: [`src/memory_agent/graph.py`](https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/graph.py) (Agent graph), [`src/memory_agent/tools.py`](https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/tools.py) (Memory upsert tool), [`src/memory_agent/context.py`](https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/context.py) (Agent context), [`src/memory_agent/utils.py`](https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/utils.py) (Model loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Conversation orchestration"]
  node_graph["Agent graph<br/>[graph.py]"]
  node_state["Message state<br/>[state.py]"]
end

subgraph group_memory["Memory operations"]
  node_memory_tool["Memory upsert tool<br/>[tools.py]"]
  node_memory_store[("Memory store")]
end

subgraph group_configuration["Runtime configuration"]
  node_context["Agent context<br/>[context.py]"]
  node_prompt["System prompt<br/>[prompts.py]"]
  node_model_loader["Model loader<br/>[utils.py]"]
end

node_user(("User"))
node_chat_model["Chat model"]
node_studio["Studio or API"]
node_memory_explorer["Memory explorer"]

node_user -->|"sends messages"| node_studio
node_studio -->|"invokes"| node_graph
node_graph -->|"returns replies"| node_studio
node_graph -->|"updates messages"| node_state
node_graph -->|"reads runtime settings"| node_context
node_context -->|"defaults prompt"| node_prompt
node_graph -->|"searches memories"| node_memory_store
node_memory_store -->|"returns matches"| node_graph
node_graph -->|"loads model"| node_model_loader
node_model_loader -->|"initializes"| node_chat_model
node_graph -->|"invokes with prompt"| node_chat_model
node_chat_model -->|"returns reply or tool calls"| node_graph
node_graph -->|"executes tool calls"| node_memory_tool
node_memory_tool -->|"writes memory"| node_memory_store
node_graph -->|"repeats after storage"| node_graph
node_memory_explorer -.->|"reviews saved memories"| node_memory_store

click node_graph "https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/graph.py"
click node_state "https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/state.py"
click node_context "https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/context.py"
click node_prompt "https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/prompts.py"
click node_model_loader "https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/utils.py"
click node_memory_tool "https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/tools.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_graph,node_state,node_user toneBlue
class node_memory_tool,node_memory_store toneAmber
class node_context,node_prompt,node_model_loader,node_studio toneMint
class node_chat_model,node_memory_explorer toneIndigo
```

## Components

### Conversation orchestration

- [Agent graph](https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/graph.py): `src/memory_agent/graph.py`
- [Message state](https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/state.py): `src/memory_agent/state.py`

### Memory operations

- [Memory upsert tool](https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/tools.py): `src/memory_agent/tools.py`
- **Memory store**

### Runtime configuration

- [Agent context](https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/context.py): `src/memory_agent/context.py`
- [System prompt](https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/prompts.py): `src/memory_agent/prompts.py`
- [Model loader](https://github.com/langchain-ai/memory-agent/blob/main/src/memory_agent/utils.py): `src/memory_agent/utils.py`

### Other components

- **User**
- **Chat model**
- **Studio or API**
- **Memory explorer**

## Connections

- User → Studio or API: sends messages (evidence: `README.md`)
- Studio or API → Agent graph: invokes (evidence: `README.md`)
- Agent graph → Studio or API: returns replies (evidence: `README.md`)
- Agent graph → Message state: updates messages (evidence: `src/memory_agent/graph.py`)
- Agent graph → Agent context: reads runtime settings (evidence: `src/memory_agent/graph.py`)
- Agent context → System prompt: defaults prompt (evidence: `src/memory_agent/context.py`)
- Agent graph → Memory store: searches memories (evidence: `src/memory_agent/graph.py`)
- Memory store → Agent graph: returns matches (evidence: `src/memory_agent/graph.py`)
- Agent graph → Model loader: loads model (evidence: `src/memory_agent/graph.py`)
- Model loader → Chat model: initializes (evidence: `src/memory_agent/utils.py`)
- Agent graph → Chat model: invokes with prompt (evidence: `src/memory_agent/graph.py`)
- Chat model → Agent graph: returns reply or tool calls (evidence: `src/memory_agent/graph.py`)
- Agent graph → Memory upsert tool: executes tool calls (evidence: `src/memory_agent/graph.py`)
- Memory upsert tool → Memory store: writes memory (evidence: `src/memory_agent/tools.py`)
- Agent graph → Agent graph: repeats after storage (evidence: `src/memory_agent/graph.py`)
- Memory explorer → Memory store: reviews saved memories (evidence: `README.md`)
