Skip to main content

Agentic Memory Management via MCP — Knowledge Graph for AI agents

Project description

agentic-memory-mcp

Agentic Memory Management via MCP — Knowledge Graph for AI agents.

PyPI version CI/CD Python

A Model Context Protocol (MCP) server that gives AI agents persistent, structured, and queryable memory via a Knowledge Graph. Designed to be used standalone, embedded in any agentic framework, or served as an MCP tool server.

Architecture

agentic_memory/
├── core/
│   ├── graph.py      # KnowledgeGraph — nodes, edges, JSON persistence
│   ├── score.py      # Score & ScoreStore — reputation / relevance scoring
│   └── prune.py      # AutoPruner — maintenance & auto-pruning
├── mcp/
│   └── server.py     # MCP server (stdio transport)
├── cli/
│   └── main.py       # Click CLI (memory-cli command)
├── api.py            # MemorySkills — Python API (standalone use)
└── hermes/           # Hermes Agent plugin integration

Persistence: JSON files (memory_graph.json, memory_scores.json) — no external database required.

Installation

# From PyPI
pip install agentic-memory-mcp

# Development
git clone https://github.com/alexandrerodenas/agentic-memory-mcp.git
cd agentic-memory-mcp
uv sync

Quick Start

CLI

# Add a memory entry
memory-cli --graph memory.json node add --id alice --label Person --content "Alice lives in Paris"

# Search
memory-cli retrieve --query "Paris"

# Link two entries
memory-cli --graph memory.json edge add --id e1 --source alice --target paris --label lives_in

# Get stats
memory-cli --graph memory.json stats

# Prune old entries
memory-cli --graph memory.json prune --max-nodes 500 --strategy oldest

MCP Server

# Start the MCP server (stdio)
memory-mcp

# Or with custom paths
MEMORY_GRAPH_PATH=/data/memory.json MEMORY_SCORES_PATH=/data/scores.json memory-mcp

Then connect any MCP-compatible AI agent (Claude Code, OpenCode, etc.) to use the tools:

  • memory_node_add — Add a fact or entity
  • memory_node_update — Update an entry
  • memory_node_delete — Delete an entry
  • memory_node_get — Retrieve by ID
  • memory_retrieve — Token-optimized top-N retrieval by score (with optional text filter)
  • memory_edge_add — Create a relationship
  • memory_corroborate — Reinforce a memory (increases score)
  • memory_prune — Manual pruning
  • memory_stats — Graph statistics

Hermes Agent Plugin

# Install
hermes plugin install agentic-memory-mcp

# Use in Hermes
/memory add alice "Alice works at Acme Corp"
/memory retrieve --query Acme --limit 10
/memory retrieve --limit 10
/memory corroborate alice
/memory prune --max-nodes 500

Or import in your own agent:

from agentic_memory.hermes import setup

setup(agent=your_agent_instance)

Scoring System

Each memory entry gets a composite relevance score:

score = (3 × corroborations) + (1 × read_count) + (0.5 × recency_bonus)
  • Corroborations increase when the same fact is reinforced (e.g., mentioned again by the user or confirmed by another source).
  • Read count increases each time the memory is retrieved.
  • Recency bonus decays over time — recently accessed memories score higher.

This ensures the most relevant, most frequently accessed, and most corroborated memories bubble up to the top during retrieval, keeping LLM context windows tight.

Auto-Pruning

Auto-prune runs as a background scheduler inside the MCP server process, controlled entirely via environment variables:

# Activate auto-prune: max 1000 nodes, prune when file > 5 MB, every 30 min
MEMORY_AUTO_PRUNE_ENABLED=1 \
MEMORY_AUTO_PRUNE_MAX_NODES=1000 \
MEMORY_AUTO_PRUNE_MAX_SIZE_MB=5 \
MEMORY_AUTO_PRUNE_INTERVAL_SECONDS=1800 \
  memory-mcp
Variable Default Description
MEMORY_AUTO_PRUNE_ENABLED 0 Set to 1 to enable the background scheduler
MEMORY_AUTO_PRUNE_MAX_NODES None Max nodes before pruning
MEMORY_AUTO_PRUNE_MAX_SIZE_MB None Max file size (MB) before pruning
MEMORY_AUTO_PRUNE_INTERVAL_SECONDS 3600 Seconds between auto-prune runs

Manual prune is also available via CLI or memory_prune tool.

Configuration

Variable Default Description
MEMORY_GRAPH_PATH memory_graph.json Path to graph JSON file
MEMORY_SCORES_PATH memory_scores.json Path to scores JSON file

Development

# Install dev deps
uv sync --all-extras

# Run tests
uv run pytest tests/ -v

# Lint
uv run ruff check src/

License

MIT — Alexandre Rodenas

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_memory_mcp-0.6.0.tar.gz (79.2 kB view details)

Uploaded Source

Built Distribution

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

agentic_memory_mcp-0.6.0-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file agentic_memory_mcp-0.6.0.tar.gz.

File metadata

  • Download URL: agentic_memory_mcp-0.6.0.tar.gz
  • Upload date:
  • Size: 79.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for agentic_memory_mcp-0.6.0.tar.gz
Algorithm Hash digest
SHA256 ac7384440324b8949e34605ef4885e91c1426d3e260911746dcdf8a3b36f4f1e
MD5 e3b72945508e918cbf2be29c2997012d
BLAKE2b-256 d3bfac3ff022f57936f13e7941e01216d6c97dc8052f442cf90e688a2a12f6ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentic_memory_mcp-0.6.0.tar.gz:

Publisher: publish.yml on alexandrerodenas/agentic-memory-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agentic_memory_mcp-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agentic_memory_mcp-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28c214fb311080a1ebcad10d3ec83b812bfbf06426ab92522a6474a6748574ef
MD5 70d723771be814b2dd7c5eb3bc9ac9ba
BLAKE2b-256 d9e5de9f5eb64901bfd6e9aabc50158dcbcff9c4528177228330d270acf7d02d

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentic_memory_mcp-0.6.0-py3-none-any.whl:

Publisher: publish.yml on alexandrerodenas/agentic-memory-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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