Communityコーディング&開発github.com

memory-systems

このスキルは、エージェントシステムにおける永続的なセマンティックメモリ(セッションをまたいだ知識保持、エンティティ追跡、時間的妥当性、グラフ/ベクトル検索、メモリ統合、メモリベンチマーク選択)に使用します。ファイルベースのスクラッチパッドはfilesystem-contextに、引き継ぎサマリーはcontext-compressionに、トークン効率化戦術はcontext-optimizationにルーティングします。

memory-systems とは?

このスキルは、AIエージェントがセッションを超えて知識を永続化し、蓄積された情報に基づいて推論するためのメモリシステム設計を包括的にガイドします。Mem0、Zep/Graphiti、Letta、Cognee、LangMemなどの主要なフレームワークを比較し、ベンチマークデータ(LoCoMo、LongMemEval、DMR)を基にした選択指針を提供します。ファイルシステムのような単純な層から始め、検索品質の低下に応じて時間的知識グラフなどの複雑な構造を段階的に追加する階層的アプローチを推奨します。また、メモリ統合、エラーリカバリ、コンテキスト統合のベストプラクティスや、エンベディングモデルの不一致やグラフスキーマの硬直性といった落とし穴についても解説します。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering/tree/main/skills/memory-systems

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

メモリシステム設計

メモリは、エージェントがセッションをまたいで継続性を維持し、蓄積された知識に基づいて推論するための永続化層を提供します。単純なエージェントはコンテキストのみに依存してメモリを保持するため、セッション終了時にすべての状態が失われます。洗練されたエージェントは、即時のコンテキストニーズと長期的な知識保持のバランスをとる階層型メモリアーキテクチャを実装します。ベクトルストアから知識グラフ、時間的知識グラフへの進化は、検索と推論の向上を目的とした構造化メモリへの投資の増大を表しています。

アクティベーション条件

以下の場合にこのスキルをアクティベートします。

  • セッションをまたいで知識を永続化するエージェントを構築する場合
  • メモリフレームワーク(Mem0、Zep/Graphiti、Letta、LangMem、Cognee)を選択する場合
  • 複数の会話にわたってエンティティの一貫性を維持する必要がある場合
  • 蓄積された知識に基づく推論を実装する場合
  • 本番環境でスケールするメモリアーキテクチャを設計する場合
  • ベンチマーク(LoCoMo、LongMemEval、DMR)に対してメモリシステムを評価する場合
  • 自動エンティティ/関係抽出と自己改善メモリ(Cognee)を備えた動的メモリを構築する場合

他のスキルが担当する隣接作業にはこのスキルをアクティベートしないでください。

  • ファイルベースのスクラッチパッド、実行ログ、ツール出力のオフロード:filesystem-context
  • 会話の圧縮や人間が読める引き継ぎサマリー:context-compression
  • マスキング、プレフィックスキャッシュ、トークンバジェット、単一軌道内の検索スコーピング:context-optimization
  • RDF状態に基づく形式的な信念/欲求/意図モデル:bdi-mental-states

コアコンセプト

メモリを、揮発性のコンテキストウィンドウから永続ストレージに至るスペクトラムとして考えてください。検索ニーズを満たす最も単純な層をデフォルトとします。なぜなら、ベンチマークの証拠(claim-memory-locomo-filesystem-baseline)によれば、一部のメモリワークロードではツールの複雑さよりも信頼性の高い検索の方が重要であるためです。構造(グラフ、時間的妥当性)は、検索品質が低下した場合、またはエージェントがマルチホップ推論、関係トラバーサル、タイムトラベルクエリを必要とする場合にのみ追加します。

詳細トピック

プロダクションフレームワークの状況

エージェントが必要とする主要な検索パターンに基づいてフレームワークを選択します。以下の表を使用して候補を絞り込み、その後、以下のベンチマークデータで検証します。

フレームワークアーキテクチャ最適な用途トレードオフ
Mem0ベクトルストア+グラフメモリ、プラグ可能なバックエンドマルチテナントシステム、幅広い統合マルチエージェントには特化していない
Zep/Graphiti時間的知識グラフ、二時間モデル関係モデリング+時間的推論を必要とするエンタープライズ高度な機能はクラウドロック
Letta自己編集型メモリと階層型ストレージ(インコンテキスト/コア/アーカイブ)完全なエージェント内省、ステートフルサービス単純なユースケースには複雑
Cogneeカスタマイズ可能なECLパイプラインとカスタマイズ可能なタスクによる多層セマンティックグラフ適応して学習する進化するエージェントメモリ、マルチホップ推論インジェスト時の処理負荷が高い
LangMemLangGraphワークフロー用のメモリツールすでにLangGraphを使用しているチームLangGraphに密結合
ファイルシステム命名規則を持つプレーンファイル単純なエージェント、プロトタイピングセマンティック検索なし、関係なし

エージェントが二時間モデリング(イベントが発生した時刻とインジェストされた時刻の両方を追跡)を必要とする場合はZep/Graphitiを選択します。その3層知識グラフ(エピソード、セマンティックエンティティ、コミュニティサブグラフ)が時間的クエリに優れているためです。マネージドインフラストラクチャで迅速なプロダクション化が優先される場合はMem0を選択します。エージェントがエージェント開発環境を通じて深い自己内省を必要とする場合はLettaを選択します。エージェントが高密度の多層セマンティックグラフを構築する必要がある場合はCogneeを選択します。Cogneeはテキストチャンクとエンティティタイプを詳細な関係エッジを持つノードとして階層化し、すべてのコア要素(インジェスト、エンティティ抽出、後処理、検索)がカスタマイズ可能です。

ベンチマークパフォーマンス比較

以下のベンチマークを参照して期待値を設定しますが、絶対的なランキングではなく、検索次元に関するソース固有のシグナルとして扱ってください。単一のベンチマークが決定的とは限りません。

システムDMR精度LoCoMoHotPotQA(マルチホップ)レイテンシ
Cognee——公開高スコア変動あり
Zep(時間的KG)公開高スコア—メトリクス全体で中程度低レイテンシ報告
Letta(ファイルシステム)—公開ファイルシステムベースライン——
Mem0—公開特化ツールベースラインある比較では低い—
MemGPT公開高スコア——変動あり
GraphRAG公開中/高範囲——変動あり
ベクトルRAGベースライン公開低範囲——高速

重要なポイント:メモリシステムはブランドではなく検索の形状で比較します。ベンチマーク数値は、製品の主張を行う前に再確認が必要な過去の証拠として扱います。安定した設計ルールは、浅く始め、検索品質を測定し、より単純な層が失敗した場合にのみセマンティックまたはグラフ構造を追加することです。

メモリ層(決定ポイント)

永続化要件を満たす最も浅いメモリ層を選択します。深い層ほどインフラコストと運用の複雑さが増すため、浅い層が検索または耐久性のニーズを満たせない場合にのみレベルを上げてください。

層永続性実装使用タイミング
ワーキングコンテキストウィンドウのみシステムプロンプト内のスクラッチパッド常に — 注意が向きやすい位置で最適化
短期セッションスコープファイルシステム、インメモリキャッシュ中間ツール結果、会話状態
長期セッション間キーバリューストア → グラフDBユーザー設定、ドメイン知識、エンティティレジストリ
エンティティセッション間エンティティレジストリ+プロパティ同一性の維持(「山田太郎」が複数の会話で同じ人物であること)
時間的KGセッション間+履歴有効性インターバルを持つグラフ時間とともに変化する事実、タイムトラベルクエリ、コンテキスト競合の防止

検索戦略

クエリの形状に合わせて検索戦略を選択します。セマンティック検索は直接的な事実検索に適していますが、マルチホップ推論では精度が低下します。エンティティベースのトラバーサルは「Xに関するすべて」のクエリを処理しますが、グラフ構造が必要です。時間的フィルタリングは変化する事実を処理しますが、有効性メタデータが必要です。精度が最重要でインフラ予算が許せば、戦略を組み合わせてハイブリッド検索にします。

戦略使用タイミング制限
セマンティック(埋め込み類似度)直接的な事実クエリマルチホップ推論で精度低下
エンティティベース(グラフトラバーサル)「Xについてすべて教えて」グラフ構造が必要
時間的(有効性フィルタ)時間とともに変化する事実有効性メタデータが必要
ハイブリッド(セマンティック+キーワード+グラフ)全体的に最高の精度最もインフラが必要

ハイブリッドアプローチは、関連するサブグラフまたはメモリのみを検索することでアクティブコンテキストを削減します。Cogneeは、グラフ、ベクトル、リレーショナルストアにわたる複数の検索モードを通じてハイブリッド検索を実装し、エージェントが汎用的なアプローチではなくクエリタイプに合った検索戦略を選択できるようにします。

メモリ統合

無制限のメモリ蓄積は時間の経過とともに検索品質を低下させるため、定期的に統合を実行して無制限の成長を防ぎます。無効化しても破棄しないでください — 過去の状態を再構築する必要がある時間的クエリには履歴の保存が重要です。メモリ数のしきい値、検索品質の低下、またはスケジュールされた間隔で統合をトリガーします。動作する統合コードについては、実装リファレンスを参照してください。

実践的なガイダンス

メモリアーキテクチャの選択

最も単純な実行可能な層から始め、検索品質が低下した場合にのみ複雑さを追加します。 ほとんどのエージェントは初日から時間的知識グラフを必要としません。以下のエスカレーションパスに従ってください。

  1. プロトタイプ:ファイルシステムメモリを使用します。事実をタイムスタンプ付きの構造化JSONとして保存します。これにより、インフラストラクチャにコミットする前にエージェントの動作を検証できます。
  2. スケール:エージェントがセマンティック検索とマルチテナント分離を必要とする場合、ファイルベースのルックアップでは類似度クエリを処理できないため、Mem0またはメタデータ付きベクトルストアに移行します。
  3. 複雑な推論:エージェントが関係トラバーサル、時間的妥当性、またはセッション間の合成を必要とする場合、Zep/Graphitiを追加します。Graphitiは汎用的な関係を持つ構造化された関連を使用し、グラフをシンプルで推論しやすく維持します。Cogneeはより高密度な多層セマンティックグラフを詳細な関係エッジとともに構築します。エージェントが時間的二重モデリング(Graphiti)を必要とするか、よりリッチな相互接続知識構造(Cognee)を必要とするかに基づいて選択します。
  4. 完全な制御:エージェントが深い内省を通じて自身のメモリを自己管理する必要がある場合、LettaまたはCogneeを使用します。これらのフレームワークはメモリ操作を第一級のエージェントアクションとして公開するためです。

コンテキストとの統合

すべてを事前にロードするのではなく、ジャストインタイムでメモリをロードします。大きなコンテキストペイロードはコストがかかり、アテンション品質を低下させるためです。検索したメモリは、コンテキスト内の注意が向きやすい位置(先頭または末尾)に配置して、生成への影響を最大化します。

エラーリカバリ

メモリシステムは本質的にノイズが多いため、検索の失敗を優雅に処理します。以下のリカバリ戦略を順に適用します。

  • 空の検索結果:より広い検索にフォールバック(エンティティフィルタを削除、時間範囲を拡大)。それでも空の場合は、ユーザーに明確化を促します。
  • 古い結果:valid_untilタイムスタンプをチェックします。ほとんどの結果が期限切れの場合は、再試行する前に統合をトリガーします。
  • 矛盾する事実:最も新しいvalid_fromを持つ事実を優先します。確信度が低い場合は、矛盾をユーザーに提示します。
  • ストレージ障害:書き込みをキューに入れて再試行します。メモリ書き込みでエージェントの応答をブロックしないでください。

例

例1:Mem0統合

from mem0 import Memory

m = Memory()
m.add("ユーザーはダークモードとPython 3.12を好みます", user_id="alice")
m.add("ユーザーがライトモードに切り替えました", user_id="alice")

# 古いものではなく、現在の設定(ライトモード)を取得
results = m.search("ユーザーはどのテーマを好みますか?", user_id="alice")

例2:時間的クエリ

# 有効期間を持つエンティティを追跡
graph.create_temporal_relationship(
    source_id=user_node,
    rel_type="LIVES_AT",
    target_id=address_node,
    valid_from=datetime(2024, 1, 15),
    valid_until=datetime(2024, 9, 1),  # 転居
)

# クエリ:ユーザーは2024年3月1日にどこに住んでいましたか?
results = graph.query_at_time(
    {"type": "LIVES_AT", "source_label": "User"},
    query_time=datetime(2024, 3, 1)
)

例3:Cogneeメモリインジェストと検索

import cognee
from cognee.modules.search.types import SearchType

# インジェストしてナレッジグラフを構築
await cognee.add("./docs/")
await cognee.add("任意のデータ")
await cognee.cognify()

# メモリを豊かにする
await cognee.memify()

# エージェントが関係を認識したコンテキストを取得
results = await cognee.search(
    query_text="メモリに関する任意のクエリ",
    query_type=SearchType.GRAPH_COMPLETION,
)

ガイドライン

  1. ファイルシステムメモリから開始し、検索品質が要求する場合にのみ複雑さを追加する
  2. 時間とともに変化する可能性のある事実には時間的妥当性を追跡する
  3. 最高の精度を得るにはハイブリッド検索(セマンティック+キーワード+グラフ)を使用する
  4. メモリを定期的に統合する — 無効化しても破棄しない
  5. 検索失敗に備えて設計する:メモリルックアップで何も返されなかった場合のフォールバックを常に用意する
  6. 永続メモリのプライバシーへの影響を考慮する(保持ポリシー、削除権利)
  7. 変更の前後で、メモリシステムをLoCoMoまたはLongMemEvalに対してベンチマークする
  8. 本番環境でメモリの増加と検索レイテンシを監視する

落とし穴

  1. すべてをコンテキストに詰め込む:利用可能なすべてのメモリをプロンプトにロードするとコストがかかり、アテンション品質が低下します。代わりに関連性フィルタリングを使用したジャストインタイム検索を使用します。
  2. 時間的妥当性を無視する:事実は古くなります。有効性追跡がないと、古い情報がコンテキストを汚染し、エージェントが誤った前提で行動します。
  3. 早すぎる過剰エンジニアリング:単純なファイルシステムベースのメモリは、一部のベンチマーク(claim-memory-locomo-filesystem-baseline)でより特殊なツールよりも優れたパフォーマンスを発揮する可能性があります。単純なアプローチが明らかに失敗した場合にのみ、高度化を追加します。
  4. 統合戦略がない:無制限のメモリ増加は時間の経過とともに検索品質を低下させます。メモリ数のしきい値またはスケジュールされた間隔を設定して統合をトリガーします。
  5. 埋め込みモデルの不一致:ある埋め込みモデルでメモリを書き込み、別のモデルで読み取ると、ベクトル空間が交換可能でないため検索が低下します。各メモリストアに単一の埋め込みモデルを固定し、モデルが変更された場合はすべてのエントリを再埋め込みします。
  6. グラフスキーマの硬直性:過度に構造化されたグラフスキーマ(固定ノードタイプ、固定関係ラベル)は、ドメインが進化すると機能しなくなります。新しいエンティティ種類がスキーマ移行を必要としないように、汎用的な関係タイプと柔軟なプロパティバッグを優先します。
  7. 古いメモリの汚染:現在の状態と矛盾する古いメモリは、エージェントの動作を静かに破壊します。期限切れポリシーまたは信頼度減衰を実装してエージェントが古い事実を優先しないようにし、矛盾が検出された場合は明示的に表面化します。
  8. メモリとコンテキストの不一致:トピック的には関連しているが、コンテキスト的に間違っているメモリを取得する(例:エージェントがPythonプログラミング言語について議論しているときに「Python」というヘビに関するメモリを取得する)。メモリエントリにセッションまたはドメインメタデータを含め、検索時にフィルタリングすることで軽減します。

統合

このスキルは永続的なセマンティックメモリを担当します。隣接するスキルはスクラッチストレージ、圧縮、コンテキスト戦術を担当します。

  • filesystem-context:ファイルベースのスクラッチパッド、ログ、および単純な実行

…

[翻訳のために切り詰め]

Individual skills in this repo

This repo contains 19 individual skills — each has its own dedicated page.

advanced-evaluation

This skill should be used for advanced LLM evaluation: LLM-as-judge systems, direct scoring, pairwise comparison, rubric calibration, evaluator bias mitigation, confidence scoring, and automated quality assessment.

bdi-mental-states

This skill should be used when modeling agent mental states with BDI concepts: beliefs, desires, intentions, RDF-to-belief transformations, rational agency traces, cognitive agents, BDI ontologies, and neuro-symbolic AI integration.

book-sft-pipeline

This skill should be used for book-to-SFT pipelines: ePub extraction, literary segmentation, author-voice dataset construction, style-transfer training, LoRA workflows, and model evaluation for voice replication.

comprehensive-research-agent

Ensure thorough validation, error recovery, and transparent reasoning in research tasks with multiple tool calls

context-compression

This skill should be used when long-running agent sessions need context compression, structured summarization, compaction, token-per-task optimization, or durable handoff summaries that preserve decisions, files, risks, and next actions.

context-degradation

This skill should be used for diagnosing and mitigating context degradation: lost-in-middle failures, context poisoning, context clash, context confusion, attention-pattern issues, and agent performance degradation caused by accumulated or conflicting context.

context-fundamentals

This skill should be used to explain or reason about the foundational concepts of context engineering: what context is, the anatomy of a context window, how attention mechanics work, the U-shaped attention curve, why context quality matters more than quantity, and the mental models needed to interpret every other context-engineering decision. Use this for conceptual explanation, onboarding, and background reading. Route operational work to the specialized skills: debugging attention failures goes to context-degradation, token-efficiency work goes to context-optimization, conversation summarization goes to context-compression, and project-shape decisions go to project-development.

context-optimization

This skill should be used for improving context efficiency: context budgeting, observation masking, prefix or KV-cache strategy, partitioning, token-cost reduction, retrieval scoping, and extending effective context capacity without lowering answer quality.

evaluation

This skill should be used when building agent evaluation systems: deterministic checks, regression suites, multi-dimensional rubrics, quality gates, production monitoring, baseline comparison, and outcome measurement for agent pipelines.

filesystem-context

This skill should be used when agent work needs file-backed context: durable scratchpads, tool-output offloading, just-in-time discovery, cross-agent handoff files, filesystem memory, or cleanup policies for context stored outside the prompt.

harness-engineering

This skill should be used when designing autonomous agent harnesses: research loops, evaluation scaffolds, locked and editable surfaces, durable logs, novelty gates, pruning, rollback, PR preparation, and human approval boundaries.

hosted-agents

This skill should be used when designing hosted or background agent infrastructure: sandboxed execution, remote coding environments, warm pools, session persistence, multiplayer collaboration, self-spawning agents, or Modal-style sandboxes.

latent-briefing

This skill should be used when the user asks to "share memory between agents", "KV cache compaction for multi-agent", "orchestrator worker context", "latent briefing", "reduce worker tokens", "cross-agent memory without summarization", or discusses Attention Matching compaction, recursive language models with workers, or token explosion in hierarchical agents.

long-horizon-prompting

This skill should be used when writing, enhancing, or evaluating the launch prompt for a long-running autonomous agent or a parallel multi-agent orchestration attacking a hard problem: pseudo-formal task briefs that define terms and an exact success predicate linguistically, enumerate non-counting outcomes, set persistence rules with explicit stop and return conditions and effort floors, manage a diverse portfolio of parallel approaches with an approach registry and blocked-route bookkeeping, and gate the return on adversarial audit. Route agent topology and coordination protocols to multi-agent-patterns, runtime control surfaces and loop governance to harness-engineering, evaluator and quality-gate construction to evaluation, judge design to advanced-evaluation, and compaction or memory mechanics to context-compression and memory-systems.

multi-agent-patterns

This skill should be used when designing multi-agent systems that need context isolation, supervisor or swarm coordination, explicit handoffs, parallel execution, or a decision on whether multiple agents are justified.

project-development

This skill should be used for project-level decisions about LLM-powered systems: whether an LLM is the right primitive for the task at hand, the shape of a multi-stage batch or agent pipeline, token and cost estimation, choosing between single-agent and multi-agent at the project level, structured output design for downstream parsing, and structuring agent-assisted iteration. Use this when the unit of work is a whole project or a multi-stage pipeline. Route individual tool design to tool-design and individual skill-loading or context-budget tactics to context-optimization.

self-improvement-loops

This skill should be used when the harness, scaffold, workflow, or optimizer itself is the optimization target: recursive self-improvement (RSI) loops, meta-harnesses, self-improving harnesses that mine their own failures and propose bounded edits, evolutionary or population-based search over agent scaffolds, acceptance gates for self-modifying systems, and agentic context evolution where the mechanism that produces context is versioned and evolved. Route governance of a single autonomous loop (locked surfaces, durable logs, rollback, novelty gates, approval boundaries) to harness-engineering, measurement and quality-gate design to evaluation, judge design to advanced-evaluation, and remote sandbox infrastructure to hosted-agents.

self-managed-context

This skill should be used when a model gets read-write control over its own live context window instead of a harness-scheduled compaction policy: the context exposed as an editable file the model rewrites with code tools, model-driven eviction and in-place updates, the harness invariants that keep self-editing safe (pinned prefix, edit gate, edit receipts, budget readouts, rollback on overflow), the prefix-cache cost of mid-context edits, and steering or training the model's own context-editing strategy. Route note content and fixed-threshold summarization to context-compression, cache-stable layout under harness control to context-optimization, file offloading to filesystem-context, and loop governance to self-improvement-loops.

tool-design

This skill should be used for the tool-interface layer of an agent system specifically: writing tool descriptions agents can route on, designing tool schemas and response formats, naming conventions, actionable error recovery messages, MCP server design, tool-set consolidation, and deciding when to add or remove an individual tool. Use this when the unit of work is a single tool or a set of tools. Route project-shape, pipeline architecture, and task-model-fit decisions to project-development; route deciding whether to introduce sub-agents to multi-agent-patterns.

関連スキル