Agentic Memory: Structural Code Graph with Neo4j and MCP
Project description
๐ง Agentic Memory
https://github.com/jarmen423/agentic-memory
Multi-Domain Memory Layer for AI Agents
Agentic Memory gives AI agents persistent, searchable memory across four domains: code, git history, web research, and conversations โ all stored in a unified Neo4j graph and exposed via MCP.
Core Value Prop: "Don't let your agent work from a blank slate. Give it memory."
โจ Features
| Feature | Description |
|---|---|
| ๐ Code Graph | Structural understanding of files, entities, imports, and on-demand execution tracing โ not just text similarity |
| ๐ฌ Conversation Memory | Stores and retrieves past agent/user exchanges by semantic similarity |
| ๐ Research & Web Memory | Ingests URLs, PDFs, and research reports as searchable findings |
| ๐งฌ Git Graph (Opt-in) | Adds commit/author/file-version history in the same Neo4j DB |
| ๐ Unified Search | search_all_memory spans all domains in a single query |
| โก Real-time Sync | File watcher automatically updates the code graph as you work |
| ๐ค MCP Protocol | Drop-in integration with Claude, Cursor, Windsurf, and any MCP-compatible AI |
| โฑ๏ธ Temporal GraphRAG | Time-aware graph layer for deterministic retrieval at any point in time |
๐ Quick Start
1. Install globally
# Recommended: Use pipx for isolated global installation
pipx install agent-memory-labs
# Or with uv tooling
uv tool install agent-memory-labs
uvx --from agent-memory-labs agent-memory --help
# Or use pip in a virtualenv
pip install agent-memory-labs
After a pipx install:
agent-memoryis available globally on that machine- you install the CLI once, not once per repository
- each repository keeps its own local Agentic Memory config under
.agentic-memory/
2. Initialize in any repository
cd /path/to/your/repo
agent-memory init
The interactive wizard will guide you through:
- Neo4j setup (local Docker, Aura cloud, or custom)
- Code embedding provider selection
- Gemini API key by default for code semantic search
- File extensions to index
By default, agent-memory init configures the code module to use
gemini-embedding-2-preview so code memory stays aligned with the rest of the
multimodal Agentic Memory system. If you want code memory completely separate,
you can switch the code module to another text embedding provider such as
OpenAI.
Multi-Repo Workflow
If a machine hosts more than one repository, the normal flow is still:
cd /path/to/repo-a
agent-memory init
cd /path/to/repo-b
agent-memory init
After that, Agentic Memory discovers the active repository from your current working directory. In practice that means:
cd /path/to/repo-a && agent-memory indexworks against repo Acd /path/to/repo-b && agent-memory serveworks against repo B- you do not need
--repofor normal day-to-day use once each repo is initialized
For no-flags multi-repo operation, store Agentic Memory credentials in the repo's own control directory:
/path/to/repo/.agentic-memory/.env
Agentic Memory intentionally does not auto-load the repo root .env, because
application-level env files often contain unrelated variables that can override
memory configuration in surprising ways.
If you change the embedding model, dimensions, or task-format configuration and need fresh vectors for the whole repo, run:
agent-memory index --full
That clears only the current repo's code graph, then rebuilds it from source.
That's it! Your repository is now indexed and ready for AI agents.
Running Agentic Memory On This Repository
If you are working inside the agentic-memory repo itself, this checkout is
already initialized through:
D:\code\agentic-memory\.codememory\config.json
So you normally do not need to run agent-memory init again.
On this machine, the practical local flow is:
cd D:\code\agentic-memory
docker compose up -d neo4j
.\.venv-agentic-memory\Scripts\python.exe -m agentic_memory.cli status --json
.\.venv-agentic-memory\Scripts\python.exe -m agentic_memory.cli index --json
Why the commands use python -m agentic_memory.cli instead of agent-memory:
- the console script may not be on
PATH - the repo-local virtualenv path is explicit and avoids shell ambiguity
Current local config expectations for this repo:
- Neo4j:
bolt://localhost:7687 - Neo4j user:
neo4j - Neo4j password:
password - code embedding provider: Gemini (
gemini-embedding-2-preview)
If status fails before indexing starts, the most likely immediate cause is
that Neo4j is not running locally yet.
๐ Usage
Code memory
# Setup/config for code memory in this repo
agent-memory init
# Show repository status and statistics
agent-memory status
# One-time structural code ingest (files, entities, imports)
agent-memory index
# Full repo rebuild after embedding-model or task-format changes
agent-memory index --full
# Continuous structural code ingest on file changes
agent-memory watch
# Experimental old repo-wide CALLS build
agent-memory build-calls
# JIT trace one function's likely execution neighborhood
agent-memory trace-execution src/app.py:run_checkout --json
# Start MCP server for AI agents
agent-memory serve
# Semantic search across code
agent-memory search "where is the auth logic?"
If the console script is not on PATH, use the module form instead:
.\.venv-agentic-memory\Scripts\python.exe -m agentic_memory.cli status --json
.\.venv-agentic-memory\Scripts\python.exe -m agentic_memory.cli index --json
Code-memory behavior model
The default code pipeline now stops after structural graph construction:
- Pass 1: structure scan and changed-file detection
- Pass 2: entities, chunks, and embeddings
- Pass 3: import graph construction
What it does not do by default:
- repo-wide
CALLSreconstruction
Behavioral tracing is now handled just in time with:
- CLI:
agent-memory trace-execution ... - MCP:
trace_execution_path(...)
The older repo-wide analyzer-backed CALLS flow is still available explicitly:
- CLI:
agent-memory build-calls
Detailed explanation:
docs/JIT_TRACING.mddocs/PUBLIC_PLUGIN_SURFACES.md
Public plugin surfaces
Agentic Memory now supports a hosted remote-MCP plugin architecture for public AI surfaces. The publication model is:
- OpenAI / ChatGPT: OpenAI app review and publish, backed by the hosted OpenAI MCP surface
- Codex: distribution derived from the approved OpenAI app;
.codex-plugin/plugin.jsonis the local preflight package - Claude: Anthropic directory submission backed by the hosted Claude MCP surface
Default hosted/public MCP mounts:
/mcp/mcp-openai/mcp-codex/mcp-claude
Internal/self-hosted full MCP mount:
/mcp-full
Canonical publication/legal URLs:
https://mcp.agentmemorylabs.com/publication/agentic-memoryhttps://mcp.agentmemorylabs.com/publication/privacyhttps://mcp.agentmemorylabs.com/publication/termshttps://mcp.agentmemorylabs.com/publication/supporthttps://mcp.agentmemorylabs.com/publication/dpa
Publication packets:
docs/publication/openaidocs/publication/anthropicdocs/publication/shared
For the public surface contract and auth details, see docs/PUBLIC_PLUGIN_SURFACES.md.
Web & research memory
# Setup/index repair for research memory
agent-memory web-init
# Actual ad hoc research ingest from a URL or PDF
agent-memory web-ingest https://example.com/paper.pdf
# Search research memory
agent-memory web-search "transformer attention mechanisms"
# Create future ingest triggers
agent-memory web-schedule --project my-project --query "LLM memory" --interval 24h
# Actual scheduled or ad hoc research ingest execution
agent-memory web-run-research --project my-project
Conversation memory
# Setup/index repair for conversation memory
agent-memory chat-init
# Actual conversation ingest
agent-memory chat-ingest /path/to/conversation.json
# Search past conversations
agent-memory chat-search "what did we decide about the auth flow?"
Optional learned reranking
Agentic Memory can optionally apply a shared learned reranking layer across code, research, and conversation search:
- first-stage retrieval still gathers candidates with the domain's normal dense / lexical / temporal logic
- reranking only reorders the candidate pool that survived those filters
- if the hosted reranker is disabled or unavailable, the system falls back to baseline ordering and records that fallback in retrieval provenance
The current hosted backend is Cohere Rerank v2. Configure it with:
AM_RERANK_ENABLED=true
AM_RERANK_PROVIDER=cohere
AM_RERANK_MODEL=rerank-v4.0-fast
COHERE_API_KEY=...
Optional per-domain candidate caps and timeout settings live in .env.example.
If you want a backup path for retryable provider failures, you can keep direct Cohere as primary and configure OpenRouter as a narrow failover:
AM_RERANK_FALLBACK_PROVIDER=openrouter
AM_RERANK_FALLBACK_MODEL=cohere/rerank-4-fast
OPENROUTER_API_KEY=...
The fallback is only used for retryable provider-side failures such as
timeouts, HTTP 429, and 5xx responses.
Git graph (opt-in)
agent-memory git-init --repo /absolute/path/to/repo --mode local --full-history
agent-memory git-sync --repo /absolute/path/to/repo --incremental
agent-memory git-status --repo /absolute/path/to/repo --json
Git graph command details and rollout notes: docs/GIT_GRAPH.md
๐งพ Tool-Use Annotation (Research)
Agentic Memory supports SQLite telemetry for MCP tool calls plus manual post-response labeling as prompted or unprompted.
agent-memory --prompted "check our auth"
agent-memory --unprompted "check our auth"
Full workflow and options: docs/TOOL_USE_ANNOTATION.md
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ Code Repository โ โ Web / PDFs / โ โ Conversation โ โ Git Commits / โ
โ (file watcher) โ โ Research Reportsโ โ Logs โ โ Blame / History โ
โโโโโโโโโโฌโโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโโ
โ โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
Ingestion Pipelines
โ
โผ
โโโโโโโโโโโโโโโโ
โ Neo4j โ
โ Memory Graphโ
โโโโโโโโฌโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโ MCP Protocol โโโโโโโโโโโโโโโโโโโโ
โ AI Agent / โ <โโโโโโโโโโโโโโโ> โ MCP Server โ
โ Claude โ โ (Interface) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
Components
| Component | Role | Description |
|---|---|---|
Code Watcher (watcher.py) |
The "Code Writer" | Watches filesystem changes, keeps the code graph in sync |
Graph Builder (graph.py) |
The "Code Mapper" | Parses code with Tree-sitter, builds Neo4j graph with embeddings |
Research Pipeline (web/pipeline.py) |
The "Research Writer" | Ingests URLs, PDFs, and findings into the memory graph |
Chat Pipeline (chat/pipeline.py) |
The "Conversation Writer" | Stores conversation turns with semantic embeddings |
MCP Server (server/app.py) |
The "Interface" | Exposes all memory domains to AI agents via MCP protocol |
๐ MCP Tools Available to AI Agents
Unified search
| Tool | Description |
|---|---|
search_all_memory(query) |
Search across all domains โ code, research, and conversations โ in one call |
Code domain
| Tool | Description |
|---|---|
search_codebase(query, limit=5) |
Semantic search over code |
get_file_dependencies(file_path) |
Returns imports and dependents for a file |
identify_impact(file_path, max_depth=3) |
Blast radius analysis for changes |
get_file_info(file_path) |
File structure overview (classes, functions) |
trace_execution_path(start_symbol, max_depth=2, force_refresh=false) |
On-demand behavioral tracing for one function root |
Conversation domain
| Tool | Description |
|---|---|
search_conversations(query, limit=5) |
Semantic search over past conversation turns |
get_conversation_context(session_id) |
Retrieve a full conversation context window |
add_message(role, content, session_id) |
Store a new message in conversation memory |
Research domain
| Tool | Description |
|---|---|
schedule_research(project_id, query, interval) |
Schedule recurring research sessions |
run_research_session(project_id) |
Run a research session immediately |
list_research_schedules(project_id) |
List active research schedules |
Git domain (opt-in)
| Tool | Description |
|---|---|
get_git_file_history(file_path, limit=20) |
File-level commit history and ownership signals |
get_commit_context(sha, include_diff_stats=true) |
Commit metadata and change statistics |
find_recent_risky_changes(path_or_symbol, window_days) |
Recent high-risk changes using hybrid signals |
Note: Git-domain tools are part of the git graph rollout. If missing in your build, run
agent-memory git-initfirst.
๐๏ธ Memory Domains
| Domain | What Gets Stored | Graph Nodes |
|---|---|---|
| Code | Source files, functions, classes, imports | File, Function, Class, Chunk |
| Conversations | Agent/user message turns, session context | ConversationTurn, Session |
| Research | Web pages, PDFs, reports, findings, claims | Report, Finding, Chunk, Source |
| Git | Commits, authors, file versions, diffs | Commit, Author, FileVersion |
โฑ๏ธ Experimental Temporal GraphRAG
Phase 8 adds a shadow-mode temporal maintenance layer alongside the existing Neo4j graph:
packages/am-temporal-kg/โ SpacetimeDB TypeScript module for temporal edge ingest, scheduled maintenance, and deterministic temporal retrievalpackages/am-sync-neo4j/โ subscription worker that mirrors curated temporal rows back into Neo4j
This layer is additive. Existing retrieval paths remain unchanged until the later retrieval cutover phase.
๐ฅ๏ธ Full-Stack Local Flow
A unified search surface spans code, research, and conversation memory:
- MCP:
search_all_memory(...) - REST:
GET /search/all
A local product control plane handles install and dogfood loops:
- CLI:
agent-memory product-status,agent-memory product-repo-add,agent-memory product-integration-set,agent-memory product-component-set,agent-memory product-event-record - REST:
GET /product/status,POST /product/repos,POST /product/integrations,POST /product/components/{component},POST /product/events,POST /product/onboarding - Workflow: docs/PRODUCT_DOGFOODING.md
A lightweight local FastAPI app in desktop_shell/ provides a browser-based control plane:
python -m am_server.server
python -m desktop_shell --backend-url http://127.0.0.1:8765
Reference docs:
- docs/SETUP_FULL_STACK.md
- docs/MCP_TOOL_REFERENCE.md
- docs/PROVIDER_CONFIGURATION.md
- docs/research/RERANKERS_PRIMER.md
- docs/research/RERANKERS_CROSS_DOMAIN_USE_CASES.md
- docs/research/RERANKING_DECISION_MEMO.md
- docs/SPACETIMEDB_OPERATIONS.md
- docs/PRODUCT_DOGFOODING.md
โ Integration Recommendation Policy
Current recommendation policy is explicit:
- Recommended default:
mcp_nativeintegration for production reliability. - Optional path:
skill_adapterworkflow for shell/script-driven operators. - Promotion rule:
skill_adapterbecomes first-class only after parity evidence is captured versusmcp_nativeacross success rate, latency, token cost, retries, and operator steps.
Reference docs and evaluation artifacts:
- docs/evaluation-decision.md
- evaluation/README.md
- evaluation/tasks/benchmark_tasks.json
- evaluation/schemas/benchmark_results.schema.json
- evaluation/skills/skill-adapter-workflow.md
๐ณ Docker Setup (Neo4j)
# Start Neo4j
docker-compose up -d neo4j
# Neo4j will be available at:
# HTTP: http://localhost:7474
# Bolt: bolt://localhost:7687
# Username: neo4j
# Password: password (change this in production!)
Neo4j Aura (Cloud)
Get a free instance at neo4j.com/cloud/aura/
๐ Configuration
Per-repository configuration is stored in .agentic-memory/config.json:
{
"neo4j": {
"uri": "bolt://localhost:7687",
"user": "neo4j",
"password": "password"
},
"openai": {
"api_key": "sk-..."
},
"indexing": {
"ignore_dirs": ["node_modules", "__pycache__", ".git"],
"extensions": [".py", ".js", ".ts", ".tsx", ".jsx"]
}
}
Note: .agentic-memory/ is gitignored by default to prevent committing API keys.
๐ MCP Integration
Claude Desktop
{
"mcpServers": {
"agentic-memory": {
"command": "agent-memory",
"args": ["serve", "--repo", "/absolute/path/to/your/project"]
}
}
}
Cursor IDE
{
"mcpServers": {
"agentic-memory": {
"command": "agent-memory",
"args": ["serve", "--repo", "/absolute/path/to/your/project", "--port", "8000"]
}
}
}
Windsurf
Add to your MCP configuration file.
Note: If your installed version does not support
--repo, use your client'scwdsetting or launch via a wrapper script:cd /absolute/path/to/project && agent-memory serve.
๐ง Installation from Source
git clone https://github.com/jarmen423/agentic-memory.git
cd agentic-memory
pip install -e .
agent-memory init
๐งช Development
pip install -e .
mypy src/agentic_memory
pytest
๐ License
MIT License - see LICENSE file for details.
๐ค Contributing
Contributions welcome! Please see TODO.md for the roadmap.
๐ Acknowledgments
- Neo4j - Graph database with vector search
- Tree-sitter - Incremental parsing for code
- Google Gemini - Default embedding provider for multimodal memory alignment
- MCP (Model Context Protocol) - Standard interface for AI tools
- SpacetimeDB - Temporal graph layer
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agent_memory_labs-0.1.8.tar.gz.
File metadata
- Download URL: agent_memory_labs-0.1.8.tar.gz
- Upload date:
- Size: 452.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3153ad4aa351af88f0caafb131f515124e2acc86cf2bcc34e8418fb96d4b56c
|
|
| MD5 |
70e660b74ea1868ed150ea40dd64e1f0
|
|
| BLAKE2b-256 |
407ece1205de020832a8b1e29c3a2759f7da17040d4eee8ad1f3ab09aaad38ea
|
File details
Details for the file agent_memory_labs-0.1.8-py3-none-any.whl.
File metadata
- Download URL: agent_memory_labs-0.1.8-py3-none-any.whl
- Upload date:
- Size: 520.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82f1b4fbe99084cbb14bf3a07167e9723c693fdc050d5ef7e835acdda4581ec1
|
|
| MD5 |
9ba816cdf98d22e9ccd394d984d81955
|
|
| BLAKE2b-256 |
6fe2a69a50eaaccf4d6e551972a555ce2d0bb00ad929458b58f97783e3f85400
|