How rohitg00/agentmemory works
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: server.ts MCP server · kv.ts Persistent state · index.ts Runtime startup · hybrid-search.ts Hybrid search
Components 21
Agent integrations
- Agent connectors
src/cli/connect/index.ts - Pi integration
integrations/pi/index.ts - Agent hooks
src/hooks
Runtime access
- Runtime startup
src/index.ts - MCP server
src/mcp/server.ts - MCP transport
src/mcp/transport.ts - Memory viewer
src/viewer/server.ts
Memory lifecycle
- Save and observe
src/functions/remember.ts - Context assembly
src/functions/context.ts - Knowledge consolidation
src/functions/consolidation-pipeline.ts - Retention and cleanup
src/functions/retention.ts
Search and state
- Memory search
src/functions/search.ts - Graph retrieval
src/functions/graph-retrieval.ts - Hybrid search
src/state/hybrid-search.ts - Search indexes
src/state/index-persistence.ts - Persistent state
src/state/kv.ts
Models and viewer
- LLM providers
src/providers/index.ts - Embedding providers
src/providers/embedding/index.ts
Other components
- Coding agents
- LLM services
- iii engine
Connections 25
- 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