# subuzis/letta1 architecture

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

- Interactive diagram: https://gitdiagram.com/subuzis/letta1
- Repository: https://github.com/subuzis/letta1

## Overview

Letta is a persistent, model-agnostic runtime for stateful LLM agents. A user or SDK sends requests through the REST API; the server manages agent execution, whose model and tool interactions produce responses while agent state and conversation history persist. The README also documents ADE access, OpenAI-compatible endpoints, and multiple hosted and local model backends. The source index supports several module relationships, but many runtime calls are in unsampled excerpts; those links are omitted or marked unverified rather than asserted.

Main entry points: [`letta/services/agent_manager.py`](https://github.com/subuzis/letta1/blob/main/letta/services/agent_manager.py) (Agent manager), [`letta/server/rest_api/app.py`](https://github.com/subuzis/letta1/blob/main/letta/server/rest_api/app.py) (REST API), [`letta/server/server.py`](https://github.com/subuzis/letta1/blob/main/letta/server/server.py) (Server orchestration), [`letta/agent.py`](https://github.com/subuzis/letta1/blob/main/letta/agent.py) (Agent reasoning)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_sdk["Python client<br/>[client.py]"]
  node_rest["REST API<br/>[app.py]"]
  node_v1["V1 routes<br/>[agents.py]"]
  node_openai["OpenAI routes"]
  node_ws["WebSocket API<br/>[server.py]"]
end

subgraph group_runtime["Agent runtime"]
  node_server["Server orchestration<br/>[server.py]"]
  node_agent["Agent reasoning<br/>[agent.py]"]
  node_chatagent["Chat-only agent<br/>[chat_only_agent.py]"]
  node_stream["Streaming interface"]
end

subgraph group_state["Persistence and memory"]
  node_agentmgr["Agent manager<br/>[agent_manager.py]"]
  node_msgmgr["Message manager<br/>[message_manager.py]"]
  node_passagemgr["Passage manager<br/>[passage_manager.py]"]
  node_source["Source management<br/>[source_manager.py]"]
  node_db[("SQL database<br/>[sqlalchemy_base.py]")]
  node_agentstate["Agent state schemas<br/>[agent.py]"]
  node_memory["Memory schemas<br/>[memory.py]"]
  node_passages["Passage schemas<br/>[passage.py]"]
end

subgraph group_models["Models and tools"]
  node_gateway["LLM dispatch<br/>[llm_api_tools.py]"]
  node_provider["Model providers<br/>[openai.py]"]
  node_local["Local model backends"]
  node_toolmgr["Tool management<br/>[tool_manager.py]"]
  node_tools["Tool functions<br/>[functions.py]"]
  node_embeddings["Embedding service<br/>[embeddings.py]"]
end

node_user(("API user"))
node_ade(("ADE"))

node_user -->|"sends requests"| node_rest
node_user -->|"uses SDK"| node_sdk
node_sdk -->|"calls API"| node_rest
node_ade -->|"uses API"| node_rest
node_rest -->|"mounts routes"| node_v1
node_rest -->|"mounts routes"| node_openai
node_rest -->|"uses server"| node_server
node_ws -->|"uses server"| node_server
node_server -.->|"runs agents"| node_agent
node_server -.->|"manages agents"| node_agentmgr
node_server -.->|"runs chat agents"| node_chatagent
node_agentmgr -->|"initializes manager"| node_msgmgr
node_agentmgr -->|"initializes manager"| node_source
node_agentmgr -->|"initializes manager"| node_toolmgr
node_agentmgr -.->|"persists state"| node_db
node_agentmgr -->|"builds state"| node_agentstate
node_agent -.->|"requests completion"| node_gateway
node_gateway -->|"dispatches model call"| node_provider
node_gateway -->|"dispatches local call"| node_local
node_agent -.->|"executes tools"| node_toolmgr
node_toolmgr -->|"loads functions"| node_tools
node_passagemgr -->|"creates embeddings"| node_embeddings
node_passagemgr -->|"uses passage schema"| node_passages
node_passagemgr -.->|"stores passages"| node_db
node_agent -.->|"streams output"| node_stream

click node_sdk "https://github.com/subuzis/letta1/blob/main/letta/client/client.py"
click node_rest "https://github.com/subuzis/letta1/blob/main/letta/server/rest_api/app.py"
click node_v1 "https://github.com/subuzis/letta1/blob/main/letta/server/rest_api/routers/v1/agents.py"
click node_openai "https://github.com/subuzis/letta1/blob/main/letta/server/rest_api/routers/openai/chat_completions/chat_completions.py"
click node_ws "https://github.com/subuzis/letta1/blob/main/letta/server/ws_api/server.py"
click node_server "https://github.com/subuzis/letta1/blob/main/letta/server/server.py"
click node_agent "https://github.com/subuzis/letta1/blob/main/letta/agent.py"
click node_chatagent "https://github.com/subuzis/letta1/blob/main/letta/chat_only_agent.py"
click node_stream "https://github.com/subuzis/letta1/blob/main/letta/streaming_interface.py"
click node_agentmgr "https://github.com/subuzis/letta1/blob/main/letta/services/agent_manager.py"
click node_msgmgr "https://github.com/subuzis/letta1/blob/main/letta/services/message_manager.py"
click node_passagemgr "https://github.com/subuzis/letta1/blob/main/letta/services/passage_manager.py"
click node_source "https://github.com/subuzis/letta1/blob/main/letta/services/source_manager.py"
click node_db "https://github.com/subuzis/letta1/blob/main/letta/orm/sqlalchemy_base.py"
click node_agentstate "https://github.com/subuzis/letta1/blob/main/letta/schemas/agent.py"
click node_memory "https://github.com/subuzis/letta1/blob/main/letta/schemas/memory.py"
click node_gateway "https://github.com/subuzis/letta1/blob/main/letta/llm_api/llm_api_tools.py"
click node_provider "https://github.com/subuzis/letta1/blob/main/letta/llm_api/openai.py"
click node_local "https://github.com/subuzis/letta1/tree/main/letta/local_llm"
click node_toolmgr "https://github.com/subuzis/letta1/blob/main/letta/services/tool_manager.py"
click node_tools "https://github.com/subuzis/letta1/blob/main/letta/functions/functions.py"
click node_embeddings "https://github.com/subuzis/letta1/blob/main/letta/embeddings.py"
click node_passages "https://github.com/subuzis/letta1/blob/main/letta/schemas/passage.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_sdk,node_rest,node_v1,node_openai,node_ws,node_user toneBlue
class node_server,node_agent,node_chatagent,node_stream toneAmber
class node_agentmgr,node_msgmgr,node_passagemgr,node_source,node_db,node_agentstate,node_memory,node_passages toneMint
class node_gateway,node_provider,node_local,node_toolmgr,node_tools,node_embeddings toneRose
class node_ade toneIndigo
```

## Components

### API and access

- [Python client](https://github.com/subuzis/letta1/blob/main/letta/client/client.py): `letta/client/client.py`
- [REST API](https://github.com/subuzis/letta1/blob/main/letta/server/rest_api/app.py): `letta/server/rest_api/app.py`
- [V1 routes](https://github.com/subuzis/letta1/blob/main/letta/server/rest_api/routers/v1/agents.py): `letta/server/rest_api/routers/v1/agents.py`
- [OpenAI routes](https://github.com/subuzis/letta1/blob/main/letta/server/rest_api/routers/openai/chat_completions/chat_completions.py): `letta/server/rest_api/routers/openai/chat_completions/chat_completions.py`
- [WebSocket API](https://github.com/subuzis/letta1/blob/main/letta/server/ws_api/server.py): `letta/server/ws_api/server.py`

### Agent runtime

- [Server orchestration](https://github.com/subuzis/letta1/blob/main/letta/server/server.py): `letta/server/server.py`
- [Agent reasoning](https://github.com/subuzis/letta1/blob/main/letta/agent.py): `letta/agent.py`
- [Chat-only agent](https://github.com/subuzis/letta1/blob/main/letta/chat_only_agent.py): `letta/chat_only_agent.py`
- [Streaming interface](https://github.com/subuzis/letta1/blob/main/letta/streaming_interface.py): `letta/streaming_interface.py`

### Persistence and memory

- [Agent manager](https://github.com/subuzis/letta1/blob/main/letta/services/agent_manager.py): `letta/services/agent_manager.py`
- [Message manager](https://github.com/subuzis/letta1/blob/main/letta/services/message_manager.py): `letta/services/message_manager.py`
- [Passage manager](https://github.com/subuzis/letta1/blob/main/letta/services/passage_manager.py): `letta/services/passage_manager.py`
- [Source management](https://github.com/subuzis/letta1/blob/main/letta/services/source_manager.py): `letta/services/source_manager.py`
- [SQL database](https://github.com/subuzis/letta1/blob/main/letta/orm/sqlalchemy_base.py): `letta/orm/sqlalchemy_base.py`
- [Agent state schemas](https://github.com/subuzis/letta1/blob/main/letta/schemas/agent.py): `letta/schemas/agent.py`
- [Memory schemas](https://github.com/subuzis/letta1/blob/main/letta/schemas/memory.py): `letta/schemas/memory.py`
- [Passage schemas](https://github.com/subuzis/letta1/blob/main/letta/schemas/passage.py): `letta/schemas/passage.py`

### Models and tools

- [LLM dispatch](https://github.com/subuzis/letta1/blob/main/letta/llm_api/llm_api_tools.py): `letta/llm_api/llm_api_tools.py`
- [Model providers](https://github.com/subuzis/letta1/blob/main/letta/llm_api/openai.py): `letta/llm_api/openai.py`
- [Local model backends](https://github.com/subuzis/letta1/tree/main/letta/local_llm): `letta/local_llm`
- [Tool management](https://github.com/subuzis/letta1/blob/main/letta/services/tool_manager.py): `letta/services/tool_manager.py`
- [Tool functions](https://github.com/subuzis/letta1/blob/main/letta/functions/functions.py): `letta/functions/functions.py`
- [Embedding service](https://github.com/subuzis/letta1/blob/main/letta/embeddings.py): `letta/embeddings.py`

### Other components

- **API user**
- **ADE**

## Connections

- API user → REST API: sends requests (evidence: `README.md`)
- API user → Python client: uses SDK (evidence: `README.md`)
- Python client → REST API: calls API (evidence: `README.md`)
- ADE → REST API: uses API (evidence: `README.md`)
- REST API → V1 routes: mounts routes (evidence: `letta/server/rest_api/app.py`)
- REST API → OpenAI routes: mounts routes (evidence: `letta/server/rest_api/app.py`)
- REST API → Server orchestration: uses server (evidence: `letta/server/rest_api/app.py`)
- WebSocket API → Server orchestration: uses server (evidence: `letta/server/ws_api/server.py`)
- Server orchestration → Agent reasoning: runs agents (evidence: `letta/server/server.py`)
- Server orchestration → Agent manager: manages agents (evidence: `letta/server/server.py`)
- Server orchestration → Chat-only agent: runs chat agents (evidence: `letta/server/server.py`)
- Agent manager → Message manager: initializes manager (evidence: `letta/services/agent_manager.py`)
- Agent manager → Source management: initializes manager (evidence: `letta/services/agent_manager.py`)
- Agent manager → Tool management: initializes manager (evidence: `letta/services/agent_manager.py`)
- Agent manager → SQL database: persists state
- Agent manager → Agent state schemas: builds state (evidence: `letta/services/agent_manager.py`)
- Agent reasoning → LLM dispatch: requests completion (evidence: `letta/agent.py`)
- LLM dispatch → Model providers: dispatches model call (evidence: `letta/llm_api/llm_api_tools.py`)
- LLM dispatch → Local model backends: dispatches local call (evidence: `letta/llm_api/llm_api_tools.py`)
- Agent reasoning → Tool management: executes tools
- Tool management → Tool functions: loads functions (evidence: `letta/services/tool_manager.py`)
- Passage manager → Embedding service: creates embeddings (evidence: `letta/services/passage_manager.py`)
- Passage manager → Passage schemas: uses passage schema (evidence: `letta/services/passage_manager.py`)
- Passage manager → SQL database: stores passages
- Agent reasoning → Streaming interface: streams output (evidence: `letta/agent.py`)
