mcpField
A
agentmem

agentmem

ローカル
github.com/oxgeneralメモリ・ナレッジ735 週間前に更新

agentmem について

agentmemは、セッションをまたいで記憶を保持するAIエージェント向けの、単一SQLiteファイルを使う軽量なメモリストアです。キーワード検索とセマンティック検索を組み合わせ、階層化や名前空間、事実の履歴管理に対応します。

主な機能

  1. 01キーワードと意味のハイブリッド検索
  2. 025種類のメモリ階層
  3. 03名前空間による分離
  4. 04事実のバージョン履歴
  5. 05エンティティと会話の自動抽出
  6. 06メモリ統合と重要度スコア

活用シーン

  1. 01セッションをまたぐ記憶の保存と検索
  2. 02ユーザーやプロジェクトごとの記憶分離
  3. 03会話履歴から事実やタスクを抽出
  4. 04事実の変化を追跡し重複を統合

MCP 対応

記憶の保存、検索、整理、エンティティ照会に使える16個のMCPツールを提供します。MCPクライアントはstdioで起動し、SQLiteデータベースに接続できます。

設定

ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。

インストール方法は未掲載です

このサーバーのパッケージやリモートエンドポイントはまだ取得できていません。プロジェクトの README の手順に従ってください。

リポジトリ

ツール

ツール一覧はまだ取得されていません

ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。

詳細

agentmem

mcp-name: io.github.oxgeneral/agentmem

AI エージェント向けの軽量な永続メモリです。SQLite ファイルは 1 つ。ハイブリッド検索(キーワード+セマンティック検索)。インストールサイズは 12MB 以下です。

PyTorch もクラウドもサーバーも不要です。メモリだけです。

ユニットテスト 206 件。実データを使った品質テスト 107 件。型付き API(TypedDict 16 種)。本番環境対応。

セッションごとに記憶なしで起動する AI エージェントが、記憶する方法を必要として開発しました。

理由

AI エージェントのセッションは毎回ゼロから始まります。コンテキストウィンドウは圧縮され、会話は終わり、記憶は消えてしまいます。agentmem は、1 つの SQLite ファイルにセッションをまたいで保持される永続メモリをエージェントに提供します。

  • ハイブリッド検索:FTS5 全文キーワード検索+ベクトルセマンティック検索を、適応型ランキングで統合
  • 4 つの動作モード:依存関係ゼロ(標準ライブラリのみ)から最高品質(12MB)まで
  • MCP ツール 16 種:recall、remember、save_state、compact、consolidate、entities など
  • HTTP REST API:エンドポイント 14 個、依存関係ゼロのサーバー、CORS 対応
  • メモリ階層 5 種:core、learned、episodic、working(自動期限切れ)、procedural(動作ルール)
  • 名前空間:複数ユーザー・複数エージェント間のメモリ分離
  • 時間的バージョニング:上書き追跡付きの事実の変遷チェーン
  • エンティティ抽出:@メンション、URL、IP、環境変数、金額を自動抽出
  • 会話抽出:チャット履歴から事実、決定事項、TODO を自動抽出
  • 重要度スコアリング:階層、長さ、具体性、構造に基づいてメモリを自動スコアリング
  • メモリの統合:類似度の高いメモリを検出して統合
  • 新しさによる加点:設定可能な減衰率に基づき、新しいメモリほど上位に表示
  • 多言語対応:FTS5 によるロシア語キーワード検索、埋め込みによる英語セマンティック検索
  • 高速:ハイブリッド検索は 1 回あたり <1ms、コールドスタートは <5ms、チャンクのインポートは <0.2ms

インストール

# Best quality (sqlite-vec + model2vec, 12MB total)
pip install agentmem-lite[all]

# Minimal (sqlite-vec + hash embeddings, 151KB)
pip install agentmem-lite

# Zero dependencies (pure Python, stdlib only)
pip install agentmem-lite --no-deps

# From source
git clone https://github.com/oxgeneral/agentmem && cd agentmem
pip install -e ".[all]"

クイックスタート

Python API
from agentmem import MemoryStore, get_embedding_model

# Auto-selects best available backend
embed = get_embedding_model()
store = MemoryStore("memory.db", embedding_dim=embed.dim)
store.set_embed_fn(embed)

# Store memories with namespaces
store.remember("Server costs $50/month", tier="core", namespace="infra")
store.remember("API returns 403 without auth", tier="learned", namespace="api")
store.remember("Deployed v2.1 at 15:30", tier="episodic")

# Search — hybrid keyword + semantic, with recency boost
results = store.recall("server costs", recency_weight=0.15)

# Namespace isolation
results = store.recall("server", namespace="infra")

# Save working state before context compression
store.save_state("Working on auth fix, step 3/5, blocked by CORS")

# Add behavioral rules (procedural memory)
store.add_procedure("Always use HTTPS in production")
store.add_procedure("Never expose debug endpoints")
rules = store.get_procedures()  # → formatted for system prompt

# Update facts with version chain
store.update_memory(old_id=1, new_content="Server costs $75/month")
history = store.history(memory_id=2)  # → trace fact evolution

# Find related memories by entity
related = store.related("10.0.0.1")  # → all memories mentioning this IP
entities = store.entities(entity_type="ip")  # → list all known IPs

# Auto-extract from conversations
messages = [
    {"role": "user", "content": "Set API_KEY to sk-abc123. Always validate input."},
    {"role": "assistant", "content": "Noted. I decided to use pydantic for validation."},
]
result = store.process_conversation(messages, namespace="project")
# → extracts config, preferences, decisions automatically

# Maintenance
store.compact(max_age_days=90)  # archive old low-value memories
store.consolidate(similarity_threshold=0.85)  # merge near-duplicates

# Import markdown files
store.import_markdown("MEMORY.md", tier="core")
CLI
# Initialize database
agentmem init --db memory.db

# Import markdown files
agentmem import MEMORY.md --tier core -n my-agent
agentmem import-dir ./daily-logs/ --tier episodic

# Search with namespace filter
agentmem search "deployment process" --limit 5 -n infra

# Manage procedures
agentmem add-procedure "Always use markdown formatting"
agentmem procedures

# View entities and relations
agentmem entities --type ip
agentmem related 10.0.0.1

# Maintenance
agentmem compact --max-age-days 90 --dry-run
agentmem consolidate --threshold 0.85

# Process conversation
agentmem process chat.json -n project

# Stats and export
agentmem stats
agentmem export --tier core
MCP サーバー(stdio)
python -m agentmem --db memory.db

MCP クライアントの設定に追加します。

{
  "mcpServers": {
    "memory": {
      "command": "python",
      "args": ["-m", "agentmem", "--db", "/path/to/memory.db"]
    }
  }
}
HTTP REST API
# Start HTTP server
agentmem serve-http --port 8422

# Or directly
agentmem-http --port 8422 --db memory.db
# Store a memory
curl -X POST http://localhost:8422/remember \
  -H "Content-Type: application/json" \
  -d '{"content": "Server IP is 10.0.0.1", "tier": "core", "namespace": "infra"}'

# Search
curl "http://localhost:8422/recall?query=server+IP&namespace=infra"

# Health check
curl http://localhost:8422/health

MCP ツール 16 個/HTTP エンドポイント 14 個:

ツールHTTP説明
recallGET /recallキーワード+セマンティックのハイブリッド検索
rememberPOST /remember新しいメモリを保存
save_statePOST /save_stateコンテキスト圧縮前の緊急保存
todayGET /today今日のメモリをすべて取得
forgetPOST /forgetメモリをアーカイブ(ソフト削除)
unarchivePOST /unarchiveアーカイブしたメモリを復元
statsGET /statsメモリの統計情報と健全性
compactPOST /compact価値の低いメモリをアーカイブ
consolidatePOST /consolidate類似度の高いメモリを統合
update_memoryPOST /update_memoryバージョンチェーン付きでメモリを置換
historyGET /history事実のバージョン履歴を追跡
relatedGET /relatedエンティティからメモリを検索
entitiesGET /entities抽出されたエンティティをすべて一覧表示
get_procedures—システムプロンプト用の動作ルールを取得
add_procedure—動作ルールを追加
process_conversation—チャット履歴から自動抽出

メモリ階層

階層用途自動整理例
core永続的な事実なし"Server IP is 10.0.0.1"
procedural動作ルールなし"Always use HTTPS"
learned発見した知識90 日後"API returns 403 without auth"
episodic出来事90 日後"Deployed v2.1 at 15:30"
working現在のタスク状態24 時間後"Working on step 3/5"

名前空間

ユーザー、エージェント、プロジェクトごとにメモリを分離します。

# Store in namespaces
store.remember("Alice's API key", namespace="user/alice")
store.remember("Bob's config", namespace="user/bob")
store.remember("Shared fact", namespace="team")

# Search within namespace (prefix matching)
store.recall("API", namespace="user/alice")  # only Alice's memories
store.recall("API", namespace="user")  # Alice + Bob (prefix match)
store.recall("API")  # everything

時間的バージョニング

事実が時間とともにどのように変化するかを追跡します。

# Initial fact
r1 = store.remember("Server costs $50/month", tier="core")

# Fact changes — old version archived, linked via supersedes
r2 = store.update_memory(r1["id"], "Server costs $75/month")

# Trace the history
history = store.history(r2["id"])
# → [{"id": 2, "content": "...$75..."}, {"id": 1, "content": "...$50..."}]

エンティティ抽出

remember() が呼び出されるたびに、正規表現ベースの NER で自動抽出します。

種類パターン例
mention@username@alice
urlhttps://...https://api.example.com
ipN.N.N.N10.0.0.1
port:NNNN:8080
emailuser@domain[email protected]
env_varALL_CAPSOPENAI_API_KEY
money$NNN$50
path/unix/path/etc/nginx/conf.d
hashtag#tag#deployment
# Find all memories mentioning an entity
store.related("10.0.0.1")
store.related("@alice", entity_type="mention")

# List all known entities
store.entities()  # sorted by memory count
store.entities(entity_type="ip")

会話からの自動抽出

チャット履歴からメモリを自動抽出します(正規表現のみ、LLM は使用しません)。

messages = [
    {"role": "user", "content": "Set DATABASE_URL to postgres://localhost/mydb"},
    {"role": "assistant", "content": "I decided to use connection pooling. Important: max 20 connections."},
    {"role": "user", "content": "Always validate input. TODO: add rate limiting."},
]
result = store.process_conversation(messages)
# Extracts: config→core, decisions→episodic, preferences→procedural, todos→working, important→core

動作モード

agentmem は、利用可能な最適なモードを自動的に選択します。

モードインストールサイズ初期化時間クエリ時間依存関係
sqlite-vec + model2vec12 MB~5ms*~1mssqlite-vec, model2vec, numpy
sqlite-vec + hash151 KB~5ms~0.8mssqlite-vec
pure Python + hash0 KB~3ms~1.8msなし(標準ライブラリのみ)
pure + int8 quantize0 KB~3ms~3msなし(標準ライブラリのみ)

*遅延読み込みの場合 — model2vec は初期化時ではなく、最初のクエリ時に読み込まれます

アーキテクチャ

┌──────────────────────────────────────────────┐
│              MemoryStore                      │
│  ┌──────────┐  ┌──────────┐  ┌────────────┐  │
│  │  FTS5    │  │  Vector  │  │  Entity    │  │
│  │ keywords │  │  Index   │  │  Index     │  │
│  │ + BM25   │  │ cosine   │  │  regex NER │  │
│  └────┬─────┘  └────┬─────┘  └─────┬──────┘  │
│       └──────┬───────┘              │         │
│    Adaptive Hybrid Scorer           │         │
│  (query classify + recency +        │         │
│   importance boost)                 │         │
│  ┌──────────────────────────────────┴───────┐ │
│  │            SQLite + WAL                  │ │
│  │  memories │ memories_fts │ vecs │ entities│ │
│  └──────────────────────────────────────────┘ │
│            One file: memory.db                │
└───────────────────────────────────────────────┘

比較

機能agentmemChromaDBLanceDBmem0Zep
インストールサイズ0-12 MB400+ MB100+ MB500+ MBクラウド
コールドスタート3-5 ms数秒数秒数秒該当なし
PyTorch が必要いいえはいいいえはい該当なし
クラウドが必要いいえいいえいいえはいはい
依存関係ゼロのモードはいいいえいいえいいえいいえ
キーワード検索FTS5 (BM25)いいえいいえいいえはい
MCP サーバー16 個のツールいいえいいえはいいいえ
HTTP API組み込みはいいいえはいはい
単一ファイルの DBはいいいえはいいいえいいえ
名前空間はいはいはいはいはい
時系列バージョン管理はいいいえはいいいえはい
エンティティ抽出自動(正規表現)いいえいいえいいえいいえ
手続き的メモリはいいいえいいえいいえいいえ
重要度スコアリング自動いいえいいえいいえいいえ
会話からの抽出自動(正規表現)いいえいいえはい(LLM)はい(LLM)
メモリの統合はいいいえいいえはい(LLM)いいえ

テスト済み

  • 206 件のユニットテストで、コア CRUD、名前空間、時系列バージョン管理、エンティティ抽出、統合、WAL 管理、HTTP サーバー、エラー処理を網羅
  • 107 件の品質テストを実際のエージェントメモリデータで実施(10 カテゴリにわたる検索クエリ 100 件、すべて合格)
  • ベンチマークスイートで再現可能な数値を測定:ハイブリッドクエリ <1ms、挿入 10K+ 件/秒、メモリあたり約 835 バイト
  • 多言語クエリの自動翻訳(deep-translator によるロシア語 → 英語:4/10 → 10/10)
  • Python 3.10、3.11、3.12

ライセンス

MIT

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。