# rohitg00/agentmemory architecture

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

- Interactive diagram: https://gitdiagram.com/rohitg00/agentmemory
- Repository: https://github.com/rohitg00/agentmemory

## Overview

agentmemory provides persistent memory for AI coding agents through MCP, agent-specific integrations, and lifecycle hooks. The main workflow is an agent request entering the MCP server, which dispatches memory operations; observations and saved knowledge are managed, indexed, and later retrieved as context. The repository also documents graph and hybrid search, consolidation, a live viewer, and multiple provider options. The sampled source confirms selected MCP dispatches and startup wiring; links for unsampled subsystems are limited to documented capabilities.

Main entry points: [`src/mcp/server.ts`](https://github.com/rohitg00/agentmemory/blob/main/src/mcp/server.ts) (MCP server), [`src/state/kv.ts`](https://github.com/rohitg00/agentmemory/blob/main/src/state/kv.ts) (Persistent state), [`src/index.ts`](https://github.com/rohitg00/agentmemory/blob/main/src/index.ts) (Runtime startup), [`src/state/hybrid-search.ts`](https://github.com/rohitg00/agentmemory/blob/main/src/state/hybrid-search.ts) (Hybrid search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_integrations["Agent integrations"]
  node_connectors["Agent connectors<br/>[index.ts]"]
  node_pi["Pi integration<br/>[index.ts]"]
  node_hooks["Agent hooks"]
end

subgraph group_access["Runtime access"]
  node_runtime["Runtime startup<br/>[index.ts]"]
  node_mcp["MCP server<br/>[server.ts]"]
  node_transport["MCP transport<br/>[transport.ts]"]
  node_viewer["Memory viewer<br/>[server.ts]"]
end

subgraph group_memory["Memory lifecycle"]
  node_remember["Save and observe<br/>[remember.ts]"]
  node_context["Context assembly<br/>[context.ts]"]
  node_consolidation["Knowledge consolidation"]
  node_lifecycle["Retention and cleanup<br/>[retention.ts]"]
end

subgraph group_retrieval["Search and state"]
  node_search["Memory search<br/>[search.ts]"]
  node_graph["Graph retrieval<br/>[graph-retrieval.ts]"]
  node_hybrid["Hybrid search<br/>[hybrid-search.ts]"]
  node_index["Search indexes"]
  node_kv[("Persistent state<br/>[kv.ts]")]
end

subgraph group_providers["Models and viewer"]
  node_provider["LLM providers<br/>[index.ts]"]
  node_embedding["Embedding providers<br/>[index.ts]"]
end

node_agents(("Coding agents"))
node_external_llm(("LLM services"))
node_engine[("iii engine")]

node_agents -->|"request memory"| node_mcp
node_agents -->|"use tools"| node_pi
node_agents -->|"emit events"| node_hooks
node_connectors -->|"wire integration"| node_agents
node_pi -->|"call REST"| node_mcp
node_hooks -->|"send events"| node_mcp
node_runtime -->|"create provider"| node_provider
node_runtime -->|"initialize embeddings"| node_embedding
node_runtime -->|"initialize persistence"| node_index
node_runtime -->|"start runtime"| node_engine
node_transport -->|"deliver requests"| node_mcp
node_mcp -->|"dispatch context"| node_context
node_mcp -->|"dispatch graph query"| node_graph
node_mcp -->|"read and write"| node_kv
node_remember -->|"store memories"| node_kv
node_consolidation -->|"read and update"| node_kv
node_consolidation -->|"request summaries"| node_provider
node_lifecycle -->|"prune memories"| node_kv
node_search -->|"retrieve matches"| node_hybrid
node_hybrid -->|"query indexes"| node_index
node_hybrid -->|"embed queries"| node_embedding
node_graph -->|"read graph data"| node_kv
node_viewer -.->|"proxy requests"| node_mcp
node_provider -.->|"call model"| node_external_llm
node_embedding -.->|"request embeddings"| node_external_llm

click node_connectors "https://github.com/rohitg00/agentmemory/blob/main/src/cli/connect/index.ts"
click node_pi "https://github.com/rohitg00/agentmemory/blob/main/integrations/pi/index.ts"
click node_hooks "https://github.com/rohitg00/agentmemory/tree/main/src/hooks"
click node_runtime "https://github.com/rohitg00/agentmemory/blob/main/src/index.ts"
click node_mcp "https://github.com/rohitg00/agentmemory/blob/main/src/mcp/server.ts"
click node_transport "https://github.com/rohitg00/agentmemory/blob/main/src/mcp/transport.ts"
click node_viewer "https://github.com/rohitg00/agentmemory/blob/main/src/viewer/server.ts"
click node_remember "https://github.com/rohitg00/agentmemory/blob/main/src/functions/remember.ts"
click node_context "https://github.com/rohitg00/agentmemory/blob/main/src/functions/context.ts"
click node_consolidation "https://github.com/rohitg00/agentmemory/blob/main/src/functions/consolidation-pipeline.ts"
click node_lifecycle "https://github.com/rohitg00/agentmemory/blob/main/src/functions/retention.ts"
click node_search "https://github.com/rohitg00/agentmemory/blob/main/src/functions/search.ts"
click node_graph "https://github.com/rohitg00/agentmemory/blob/main/src/functions/graph-retrieval.ts"
click node_hybrid "https://github.com/rohitg00/agentmemory/blob/main/src/state/hybrid-search.ts"
click node_index "https://github.com/rohitg00/agentmemory/blob/main/src/state/index-persistence.ts"
click node_kv "https://github.com/rohitg00/agentmemory/blob/main/src/state/kv.ts"
click node_provider "https://github.com/rohitg00/agentmemory/blob/main/src/providers/index.ts"
click node_embedding "https://github.com/rohitg00/agentmemory/blob/main/src/providers/embedding/index.ts"

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_connectors,node_pi,node_hooks toneBlue
class node_runtime,node_mcp,node_transport,node_viewer,node_engine toneAmber
class node_remember,node_context,node_consolidation,node_lifecycle toneMint
class node_search,node_graph,node_hybrid,node_index,node_kv toneRose
class node_provider,node_embedding,node_agents,node_external_llm toneIndigo
```

## Components

### Agent integrations

- [Agent connectors](https://github.com/rohitg00/agentmemory/blob/main/src/cli/connect/index.ts): `src/cli/connect/index.ts`
- [Pi integration](https://github.com/rohitg00/agentmemory/blob/main/integrations/pi/index.ts): `integrations/pi/index.ts`
- [Agent hooks](https://github.com/rohitg00/agentmemory/tree/main/src/hooks): `src/hooks`

### Runtime access

- [Runtime startup](https://github.com/rohitg00/agentmemory/blob/main/src/index.ts): `src/index.ts`
- [MCP server](https://github.com/rohitg00/agentmemory/blob/main/src/mcp/server.ts): `src/mcp/server.ts`
- [MCP transport](https://github.com/rohitg00/agentmemory/blob/main/src/mcp/transport.ts): `src/mcp/transport.ts`
- [Memory viewer](https://github.com/rohitg00/agentmemory/blob/main/src/viewer/server.ts): `src/viewer/server.ts`

### Memory lifecycle

- [Save and observe](https://github.com/rohitg00/agentmemory/blob/main/src/functions/remember.ts): `src/functions/remember.ts`
- [Context assembly](https://github.com/rohitg00/agentmemory/blob/main/src/functions/context.ts): `src/functions/context.ts`
- [Knowledge consolidation](https://github.com/rohitg00/agentmemory/blob/main/src/functions/consolidation-pipeline.ts): `src/functions/consolidation-pipeline.ts`
- [Retention and cleanup](https://github.com/rohitg00/agentmemory/blob/main/src/functions/retention.ts): `src/functions/retention.ts`

### Search and state

- [Memory search](https://github.com/rohitg00/agentmemory/blob/main/src/functions/search.ts): `src/functions/search.ts`
- [Graph retrieval](https://github.com/rohitg00/agentmemory/blob/main/src/functions/graph-retrieval.ts): `src/functions/graph-retrieval.ts`
- [Hybrid search](https://github.com/rohitg00/agentmemory/blob/main/src/state/hybrid-search.ts): `src/state/hybrid-search.ts`
- [Search indexes](https://github.com/rohitg00/agentmemory/blob/main/src/state/index-persistence.ts): `src/state/index-persistence.ts`
- [Persistent state](https://github.com/rohitg00/agentmemory/blob/main/src/state/kv.ts): `src/state/kv.ts`

### Models and viewer

- [LLM providers](https://github.com/rohitg00/agentmemory/blob/main/src/providers/index.ts): `src/providers/index.ts`
- [Embedding providers](https://github.com/rohitg00/agentmemory/blob/main/src/providers/embedding/index.ts): `src/providers/embedding/index.ts`

### Other components

- **Coding agents**
- **LLM services**
- **iii engine**

## Connections

- Coding agents → MCP server: request memory
- Coding agents → Pi integration: use tools
- Coding agents → Agent hooks: emit events
- Agent connectors → Coding agents: wire integration
- Pi integration → MCP server: call REST
- Agent hooks → MCP server: send events
- Runtime startup → LLM providers: create provider
- Runtime startup → Embedding providers: initialize embeddings
- Runtime startup → Search indexes: initialize persistence
- Runtime startup → iii engine: start runtime
- MCP transport → MCP server: deliver requests
- MCP server → Context assembly: dispatch context
- MCP server → Graph retrieval: dispatch graph query
- MCP server → Persistent state: read and write
- Save and observe → Persistent state: store memories
- Knowledge consolidation → Persistent state: read and update
- Knowledge consolidation → LLM providers: request summaries
- Retention and cleanup → Persistent state: prune memories
- Memory search → Hybrid search: retrieve matches
- Hybrid search → Search indexes: query indexes
- Hybrid search → Embedding providers: embed queries
- Graph retrieval → Persistent state: read graph data
- Memory viewer → MCP server: proxy requests
- LLM providers → LLM services: call model
- Embedding providers → LLM services: request embeddings
