# deductive-ai/memgpt architecture

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

- Interactive diagram: https://gitdiagram.com/deductive-ai/memgpt
- Repository: https://github.com/deductive-ai/memgpt

## Overview

MemGPT is a perpetual-chat agent that manages short-term conversation context and longer-lived memory. Its principal workflow is: a user starts or resumes an agent in the CLI, the agent processes turns and model function calls, and persistence and archival storage support continued conversations and retrieval. The README also documents data loading, persona/human configuration, local LLMs, and AutoGen integration. Relationships below use README statements or the SOURCE INDEX reference lists; unsampled implementation details are not inferred.

Main entry points: [`memgpt/main.py`](https://github.com/deductive-ai/memgpt/blob/main/memgpt/main.py) (CLI application), [`memgpt/agent.py`](https://github.com/deductive-ai/memgpt/blob/main/memgpt/agent.py) (Agent loop), [`memgpt/connectors/storage.py`](https://github.com/deductive-ai/memgpt/blob/main/memgpt/connectors/storage.py) (Storage selection), [`memgpt/cli/cli.py`](https://github.com/deductive-ai/memgpt/blob/main/memgpt/cli/cli.py) (CLI commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["CLI and setup"]
  node_cli["CLI commands<br/>[cli.py]"]
  node_configuration["Configuration<br/>[cli_config.py]"]
  node_application["CLI application<br/>[main.py]"]
  node_loader["Data loading<br/>[cli_load.py]"]
end

subgraph group_agent["Agent runtime"]
  node_agent["Agent loop<br/>[agent.py]"]
  node_prompts["Presets and prompts<br/>[presets.py]"]
  node_functions["Agent functions<br/>[gpt_functions.py]"]
  node_persona["Persona definitions<br/>[personas.py]"]
  node_human["Human definitions<br/>[humans.py]"]
end

subgraph group_memory["Memory and persistence"]
  node_memory["Memory tiers<br/>[memory.py]"]
  node_persistence["State persistence"]
  node_storage["Storage selection<br/>[storage.py]"]
  node_localstore[("Local archival store<br/>[local.py]")]
  node_postgres[("Postgres archival store<br/>[db.py]")]
  node_embeddings["Embedding models<br/>[embeddings.py]"]
end

subgraph group_models["Model integrations"]
  node_modelapi["Chat completion<br/>[openai_tools.py]"]
  node_localproxy["Local model proxy"]
end

subgraph group_extensions["Integrations"]
  node_autogen["AutoGen adapter<br/>[interface.py]"]
end

node_user(("User"))
node_modelservice{{"LLM service"}}
node_externaldata["Directory or database dump"]

node_user -->|"starts chat"| node_cli
node_cli -->|"dispatches commands"| node_application
node_application -->|"runs agent"| node_agent
node_cli -->|"configures"| node_configuration
node_application -->|"selects preset"| node_prompts
node_prompts -->|"uses prompts"| node_functions
node_application -->|"loads persona"| node_persona
node_application -->|"loads human"| node_human
node_agent -->|"requests completion"| node_modelapi
node_modelapi -->|"routes local requests"| node_localproxy
node_modelapi -->|"calls model"| node_modelservice
node_agent -->|"updates memory"| node_memory
node_agent -->|"uses state manager"| node_persistence
node_memory -->|"uses archival storage"| node_storage
node_storage -->|"selects backend"| node_localstore
node_storage -->|"selects backend"| node_postgres
node_memory -->|"computes embeddings"| node_embeddings
node_user -->|"loads source"| node_loader
node_externaldata -->|"provides data"| node_loader
node_loader -->|"stores passages"| node_storage
node_user -.->|"uses AutoGen"| node_autogen
node_autogen -->|"adapts agent"| node_agent

click node_cli "https://github.com/deductive-ai/memgpt/blob/main/memgpt/cli/cli.py"
click node_configuration "https://github.com/deductive-ai/memgpt/blob/main/memgpt/cli/cli_config.py"
click node_application "https://github.com/deductive-ai/memgpt/blob/main/memgpt/main.py"
click node_loader "https://github.com/deductive-ai/memgpt/blob/main/memgpt/cli/cli_load.py"
click node_agent "https://github.com/deductive-ai/memgpt/blob/main/memgpt/agent.py"
click node_prompts "https://github.com/deductive-ai/memgpt/blob/main/memgpt/presets.py"
click node_functions "https://github.com/deductive-ai/memgpt/blob/main/memgpt/prompts/gpt_functions.py"
click node_persona "https://github.com/deductive-ai/memgpt/blob/main/memgpt/personas/personas.py"
click node_human "https://github.com/deductive-ai/memgpt/blob/main/memgpt/humans/humans.py"
click node_memory "https://github.com/deductive-ai/memgpt/blob/main/memgpt/memory.py"
click node_persistence "https://github.com/deductive-ai/memgpt/blob/main/memgpt/persistence_manager.py"
click node_storage "https://github.com/deductive-ai/memgpt/blob/main/memgpt/connectors/storage.py"
click node_localstore "https://github.com/deductive-ai/memgpt/blob/main/memgpt/connectors/local.py"
click node_postgres "https://github.com/deductive-ai/memgpt/blob/main/memgpt/connectors/db.py"
click node_embeddings "https://github.com/deductive-ai/memgpt/blob/main/memgpt/embeddings.py"
click node_modelapi "https://github.com/deductive-ai/memgpt/blob/main/memgpt/openai_tools.py"
click node_localproxy "https://github.com/deductive-ai/memgpt/blob/main/memgpt/local_llm/chat_completion_proxy.py"
click node_autogen "https://github.com/deductive-ai/memgpt/blob/main/memgpt/autogen/interface.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_cli,node_configuration,node_application,node_loader,node_user toneBlue
class node_agent,node_prompts,node_functions,node_persona,node_human,node_externaldata toneAmber
class node_memory,node_persistence,node_storage,node_localstore,node_postgres,node_embeddings toneMint
class node_modelapi,node_localproxy toneRose
class node_autogen,node_modelservice toneIndigo
```

## Components

### CLI and setup

- [CLI commands](https://github.com/deductive-ai/memgpt/blob/main/memgpt/cli/cli.py): `memgpt/cli/cli.py`
- [Configuration](https://github.com/deductive-ai/memgpt/blob/main/memgpt/cli/cli_config.py): `memgpt/cli/cli_config.py`
- [CLI application](https://github.com/deductive-ai/memgpt/blob/main/memgpt/main.py): `memgpt/main.py`
- [Data loading](https://github.com/deductive-ai/memgpt/blob/main/memgpt/cli/cli_load.py): `memgpt/cli/cli_load.py`

### Agent runtime

- [Agent loop](https://github.com/deductive-ai/memgpt/blob/main/memgpt/agent.py): `memgpt/agent.py`
- [Presets and prompts](https://github.com/deductive-ai/memgpt/blob/main/memgpt/presets.py): `memgpt/presets.py`
- [Agent functions](https://github.com/deductive-ai/memgpt/blob/main/memgpt/prompts/gpt_functions.py): `memgpt/prompts/gpt_functions.py`
- [Persona definitions](https://github.com/deductive-ai/memgpt/blob/main/memgpt/personas/personas.py): `memgpt/personas/personas.py`
- [Human definitions](https://github.com/deductive-ai/memgpt/blob/main/memgpt/humans/humans.py): `memgpt/humans/humans.py`

### Memory and persistence

- [Memory tiers](https://github.com/deductive-ai/memgpt/blob/main/memgpt/memory.py): `memgpt/memory.py`
- [State persistence](https://github.com/deductive-ai/memgpt/blob/main/memgpt/persistence_manager.py): `memgpt/persistence_manager.py`
- [Storage selection](https://github.com/deductive-ai/memgpt/blob/main/memgpt/connectors/storage.py): `memgpt/connectors/storage.py`
- [Local archival store](https://github.com/deductive-ai/memgpt/blob/main/memgpt/connectors/local.py): `memgpt/connectors/local.py`
- [Postgres archival store](https://github.com/deductive-ai/memgpt/blob/main/memgpt/connectors/db.py): `memgpt/connectors/db.py`
- [Embedding models](https://github.com/deductive-ai/memgpt/blob/main/memgpt/embeddings.py): `memgpt/embeddings.py`

### Model integrations

- [Chat completion](https://github.com/deductive-ai/memgpt/blob/main/memgpt/openai_tools.py): `memgpt/openai_tools.py`
- [Local model proxy](https://github.com/deductive-ai/memgpt/blob/main/memgpt/local_llm/chat_completion_proxy.py): `memgpt/local_llm/chat_completion_proxy.py`

### Integrations

- [AutoGen adapter](https://github.com/deductive-ai/memgpt/blob/main/memgpt/autogen/interface.py): `memgpt/autogen/interface.py`

### Other components

- **User**
- **LLM service**
- **Directory or database dump**

## Connections

- User → CLI commands: starts chat (evidence: `README.md`)
- CLI commands → CLI application: dispatches commands (evidence: `memgpt/cli/cli.py`)
- CLI application → Agent loop: runs agent (evidence: `memgpt/main.py`)
- CLI commands → Configuration: configures (evidence: `memgpt/cli/cli.py`)
- CLI application → Presets and prompts: selects preset (evidence: `memgpt/main.py`)
- Presets and prompts → Agent functions: uses prompts (evidence: `memgpt/presets.py`)
- CLI application → Persona definitions: loads persona (evidence: `memgpt/main.py`)
- CLI application → Human definitions: loads human (evidence: `memgpt/main.py`)
- Agent loop → Chat completion: requests completion (evidence: `memgpt/agent.py`)
- Chat completion → Local model proxy: routes local requests (evidence: `memgpt/openai_tools.py`)
- Chat completion → LLM service: calls model (evidence: `README.md`)
- Agent loop → Memory tiers: updates memory (evidence: `memgpt/agent.py`)
- Agent loop → State persistence: uses state manager (evidence: `memgpt/agent.py`)
- Memory tiers → Storage selection: uses archival storage (evidence: `memgpt/memory.py`)
- Storage selection → Local archival store: selects backend (evidence: `memgpt/connectors/storage.py`)
- Storage selection → Postgres archival store: selects backend (evidence: `memgpt/connectors/storage.py`)
- Memory tiers → Embedding models: computes embeddings (evidence: `memgpt/memory.py`)
- User → Data loading: loads source (evidence: `README.md`)
- Directory or database dump → Data loading: provides data (evidence: `README.md`)
- Data loading → Storage selection: stores passages (evidence: `memgpt/cli/cli_load.py`)
- User → AutoGen adapter: uses AutoGen (evidence: `README.md`)
- AutoGen adapter → Agent loop: adapts agent (evidence: `memgpt/autogen/memgpt_agent.py`)
