Skip to main content

Agentic Memory: Structural Code Graph with Neo4j and MCP

Project description

๐Ÿง  Agentic Memory

https://github.com/jarmen423/codememory

Active, Structural Memory System for AI Coding Agents

Agentic Memory is not just "RAG" for code. It is an active, structural memory layer that understands code relationships (dependencies, imports, inheritance), not just text similarity.

Core Value Prop: "Don't let your Agent code blind. Give it a map."


โœจ Features

Feature Description
๐Ÿ“Š Structural Graph Understands imports, dependencies, call graphs - not just text similarity
๐Ÿ” Semantic Search Vector embeddings with contextual prefixing for accurate results
โšก Real-time Sync File watcher automatically updates the graph as you code
๐Ÿงฌ Git Graph (Opt-in) Adds commit/author/file-version history in the same Neo4j DB with separate labels
๐Ÿค– MCP Protocol Drop-in integration with Claude, Cursor, Windsurf, and any MCP-compatible AI
๐Ÿ’ฅ Impact Analysis See the blast radius of changes before you make them

๐Ÿš€ Quick Start (One Command Setup)

1. Install globally

# Recommended: Use pipx for isolated global installation
pipx install agentic-codememory

# Or with uv tooling
uv tool install agentic-codememory
uvx codememory --help

# Or use pip in a virtualenv
pip install agentic-codememory

2. Initialize in any repository

cd /path/to/your/repo
codememory init

The interactive wizard will guide you through:

  • Neo4j setup (local Docker, Aura cloud, or custom)
  • OpenAI API key (for semantic search)
  • File extensions to index

That's it! Your repository is now indexed and ready for AI agents.


๐Ÿ“– Usage

In any initialized repository:

# Show repository status and statistics
codememory status

# One-time full index (e.g., after major changes)
codememory index

# Watch for changes and continuously update
codememory watch

# Start MCP server for AI agents
codememory serve

# Test semantic search
codememory search "where is the auth logic?"

# Git graph (rollout build)
codememory git-init --repo /absolute/path/to/repo
codememory git-sync --repo /absolute/path/to/repo --full
codememory 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 now supports SQLite telemetry for MCP tool calls plus manual post-response labeling as prompted or unprompted.

codememory --prompted "check our auth"
codememory --unprompted "check our auth"

Full workflow and options: docs/TOOL_USE_ANNOTATION.md


๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     Watches      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  User Repositoryโ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€> โ”‚ Ingestion Serviceโ”‚
โ”‚                 โ”‚                  โ”‚ (Observer)       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                              โ”‚ Writes
                                              โ–ผ
                                       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                       โ”‚  Neo4j       โ”‚
                                       โ”‚  Cortex      โ”‚
                                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                              โ”‚ Reads
                                              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     MCP Protocol  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   AI Agent /    โ”‚ <โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€> โ”‚  MCP Server      โ”‚
โ”‚   Claude        โ”‚                   โ”‚  (Interface)     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Components

Component Role Description
Observer (watcher.py) The "Writer" Watches filesystem changes and keeps the graph in sync
Graph Builder (graph.py) The "Mapper" Parses code with Tree-sitter, builds Neo4j graph with embeddings
MCP Server (app.py) The "Interface" Exposes high-level skills to AI agents via MCP protocol

๐Ÿ”Œ MCP Tools Available to AI Agents

Tool Description
search_codebase(query, limit=5, domain="code") Semantic search for code, git, or hybrid domain routing
get_file_dependencies(file_path, domain="code") Returns imports and dependents for a file
identify_impact(file_path, max_depth=3, domain="code") Blast radius analysis for changes
get_file_info(file_path, domain="code") File structure overview (classes, functions)
create_memory_entities(entities) Create or update agent-authored memory nodes in Neo4j
create_memory_relations(relations) Create typed relationships between memory nodes
add_memory_observations(observations) Append observation strings to existing memory nodes
delete_memory_entities(entity_names) Delete memory nodes by name
delete_memory_relations(relations) Delete typed relationships between memory nodes
delete_memory_observations(observations) Remove observation strings from memory nodes
search_memory_nodes(query, limit=5) Search memory nodes by name, type, and observations
read_memory_graph() Read a summary of the current memory graph
get_git_file_history(file_path, limit=20, domain="git") File-level commit history and ownership signals (git rollout)
get_commit_context(sha, include_diff_stats=true) Commit metadata and change statistics (git rollout)
find_recent_risky_changes(path_or_symbol, window_days, domain="hybrid") Recent high-risk changes using hybrid signals (git rollout)

Note: domain routing and git-domain tools are part of the git graph rollout. If they are missing in your installed build, use code-domain tools only and upgrade to a git-enabled release.


โœ… Integration Recommendation Policy (PR7)

Current recommendation policy is explicit:

  1. Recommended default: mcp_native integration for production reliability.
  2. Optional path: skill_adapter workflow for shell/script-driven operators.
  3. Promotion rule: skill_adapter becomes first-class only after parity evidence is captured versus mcp_native across success rate, latency, token cost, retries, and operator steps.

Reference docs and evaluation artifacts:


๐Ÿณ Docker Setup (Neo4j)

Quick Start

# 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 .codememory/config.json:

{
  "neo4j": {
    "uri": "bolt://localhost:7687",
    "user": "neo4j",
    "password": "password"
  },
  "openai": {
    "api_key": "sk-..."  // Optional - can use OPENAI_API_KEY env var
  },
  "indexing": {
    "ignore_dirs": ["node_modules", "__pycache__", ".git"],
    "extensions": [".py", ".js", ".ts", ".tsx", ".jsx"],
    "include_paths": ["systemd/AGENTS.md", "docs/runbooks/*.md"]
  }
}

include_paths is an explicit allowlist for files that should be indexed even when their extension is not in indexing.extensions. This is useful for selectively indexing a few high-value docs such as AGENTS.md, runbooks, or systemd unit companions without turning on all Markdown files.

Note: .codememory/ is gitignored by default to prevent committing API keys.


๐Ÿ”ง Installation from Source

# Clone the repository
git clone https://github.com/jarmen423/codememory.git
cd codememory

# Install in editable mode
pip install -e .

# Run the init wizard in any repo
codememory init

๐Ÿงช Development

# Install in editable mode
pip install -e .

# Run type checking (when mypy is configured)
mypy src/codememory

# Run tests (when added)
pytest

๐Ÿ“Š What Gets Indexed?

Entity Description Relationships
Files Source code files [:DEFINES]โ†’ Functions/Classes, [:IMPORTS]โ†’ Files
Functions Function definitions [:CALLS]โ†’ Functions, [:HAS_METHOD]โ† Classes
Classes Class definitions [:HAS_METHOD]โ†’ Methods
Chunks Semantic embeddings [:DESCRIBES]โ†’ Functions/Classes

๐Ÿ”Œ MCP Integration

Claude Desktop

{
  "mcpServers": {
    "agentic-memory": {
      "command": "codememory",
      "args": ["serve", "--repo", "/absolute/path/to/your/project"]
    }
  }
}

Cursor IDE

{
  "mcpServers": {
    "agentic-memory": {
      "command": "codememory",
      "args": ["serve", "--repo", "/absolute/path/to/your/project", "--port", "8000"]
    }
  }
}

Windsurf

Add to your MCP configuration file.

Note: --repo requires the upcoming release that adds explicit repo targeting for serve. If your installed version does not support --repo, use your client's cwd setting (if supported) or launch via a wrapper script that runs cd /absolute/path/to/project && codememory serve.


๐Ÿ“ 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
  • OpenAI - Embeddings for semantic search
  • MCP (Model Context Protocol) - Standard interface for AI tools

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

agentic_codememory-0.2.1.tar.gz (250.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentic_codememory-0.2.1-py3-none-any.whl (65.0 kB view details)

Uploaded Python 3

File details

Details for the file agentic_codememory-0.2.1.tar.gz.

File metadata

  • Download URL: agentic_codememory-0.2.1.tar.gz
  • Upload date:
  • Size: 250.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for agentic_codememory-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d3cc9e6394a3794d28d38eb6b17fc0388365f6289c59246e15d83ccdf1e089a3
MD5 f17080f1294ac0c8ce207b494f701b5b
BLAKE2b-256 18448847f4984bb494ffd475fbec5724b699e98f5601211207aac8ad48d58fdd

See more details on using hashes here.

File details

Details for the file agentic_codememory-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for agentic_codememory-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 334203ec031407382726149b6d7c826a3e8b1c2785a232ba2205eaa97af60f8e
MD5 fece522dac7dcd805073e8c28efa727a
BLAKE2b-256 c5249890b251182002575ec157e0cf042e4c2fd3b2ca78a6c5da57b349ae65d8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page