Ai Agent Memory Systemsのロゴ

Ai Agent Memory Systems

コミュニティ
j4flmao
ai-agent-memory-systems

Use this skill when the user says 'agent memory', 'long-term memory', 'conversation memory', 'remember user preferences', 'context window full', 'summarize history', 'episodic memory', 'semantic memory'. Designs what an agent keeps in its context window, what it stores externally, how it writes and retrieves memories, and how memories expire. Do NOT use for: document RAG pipelines (ai/llm-engineering/rag-architecture), vector DB operations (data or ai vector-database skills), or the agent loop itself (ai/ai-agents/core-architectures).

概要

公開者j4flmao
リポジトリagent-skills
スキル名ai-agent-memory-systems
スター
41
フォーク
6
同梱ファイル
指示のみ
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    j4flmaoがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Ai Agent Memory Systems」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/j4flmao/agent-skills/tree/main/skills/ai/ai-agents/memory-systems
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/j4flmao/agent-skills.git /tmp/agent-skills
mkdir -p .claude/skills
cp -r /tmp/agent-skills/skills/ai/ai-agents/memory-systems .claude/skills/ai-agent-memory-systems
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでAi Agent Memory Systemsを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にAi Agent Memory Systemsを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Ai Agent Memory Systemsは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Agent Memory Systems

Purpose

An LLM is stateless between calls; anything the agent "remembers" is either placed in the context window or retrieved into it. Memory design is therefore a set of policies: what stays verbatim in context, what gets compressed, what is persisted to external stores, how it is retrieved, and when it is updated or deleted. Bad memory design shows up as forgotten constraints, contradictory facts, and leaked data between users.

Agent Protocol

Trigger

"agent memory", "long-term memory", "remember across sessions", "context window full", "conversation summarization", "user profile memory", "episodic memory", "memory leaks between users".

Input Context

  • Session length and turn count; model context size.
  • What must persist across sessions (preferences, facts, past task outcomes).
  • Privacy/tenancy constraints and retention requirements.
  • Existing storage (Postgres, Redis, vector DB).

Output Artifact

Memory design: tiers, schemas, write/read/eviction policies, isolation and retention rules.

Response Format

Working memory: pinned={...} window={n turns} compression={summary|drop}
Semantic store: {schema} retrieval={hybrid+rerank} k={n}
Episodic store: {schema} written on={event}
Profile/facts: {key-value schema} update={upsert w/ provenance}
Isolation: {tenant/user key}  Retention: {ttl}  Deletion: {API}

Completion Criteria

  • Pinned context (instructions, goal, constraints) never evicted.
  • Every stored memory carries owner id, source, timestamp.
  • Retrieval is scoped by owner before similarity search.
  • Conflicting facts resolved by recency/provenance, not duplicated.
  • User-facing delete path exists.

Memory Tiers

TierLives inContentRetrievalTypical store
WorkingContext windowSystem prompt, goal, plan, recent turns, tool resultsAlways presentIn-process
SemanticExternalFacts, documents, user profileSimilarity + filtersPostgres/pgvector, vector DB, KV
EpisodicExternalPast tasks: what was tried, outcome, lessonBy task similarity or recencyTable + embeddings
ProceduralPrompt/codeLearned instructions, tool usage rulesLoaded at startVersioned prompt files

Semantic memory answers "what is true"; episodic memory answers "what happened when I tried". Raw transcripts are not episodic memory: distill them into short records (task, actions, outcome, lesson).

Working Memory Management

Context is finite and long contexts degrade attention to the middle, so budget it explicitly:

[pinned]     system prompt, tool definitions, goal, constraints     ~fixed
[state]      current plan, key facts extracted so far              small, rewritten each step
[retrieved]  top-k memories for this step                          capped tokens
[window]     last N turns verbatim                                 sliding
[summary]    rolling summary of older turns                        rewritten when window overflows
python
from __future__ import annotations

from dataclasses import dataclass, field


@dataclass
class WorkingMemory:
    pinned: str
    max_window_tokens: int
    window: list[dict] = field(default_factory=list)
    summary: str = ""

    def add(self, message: dict, count_tokens, summarize) -> None:
        self.window.append(message)
        while sum(count_tokens(m["content"]) for m in self.window) > self.max_window_tokens:
            # Evict oldest turns into the rolling summary; never touch pinned content.
            oldest = self.window[:4]
            self.window = self.window[4:]
            self.summary = summarize(self.summary, oldest)

    def render(self, retrieved: list[str]) -> list[dict]:
        preamble = self.pinned
        if self.summary:
            preamble += f"\n\n<conversation_summary>\n{self.summary}\n</conversation_summary>"
        if retrieved:
            preamble += "\n\n<memories>\n" + "\n".join(retrieved) + "\n</memories>"
        return [{"role": "system", "content": preamble}, *self.window]

Keep tool-call/tool-result pairs together when evicting; most APIs reject a tool result whose call was removed.

Long-Term Memory Store

sql
CREATE TABLE agent_memory (
    id            BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    tenant_id     TEXT NOT NULL,
    user_id       TEXT NOT NULL,
    kind          TEXT NOT NULL CHECK (kind IN ('fact', 'preference', 'episode')),
    subject_key   TEXT,                       -- e.g. 'preferred_language' for upserts
    content       TEXT NOT NULL,
    embedding     vector(1024),               -- pgvector; dimension = your embedding model
    source        TEXT NOT NULL,              -- message id / tool / user-stated
    confidence    REAL NOT NULL DEFAULT 1.0,
    created_at    TIMESTAMPTZ NOT NULL DEFAULT now(),
    expires_at    TIMESTAMPTZ,
    deleted_at    TIMESTAMPTZ,
    UNIQUE (tenant_id, user_id, kind, subject_key)
);
CREATE INDEX ON agent_memory USING hnsw (embedding vector_cosine_ops);
CREATE INDEX ON agent_memory USING gin (to_tsvector('english', content));

Retrieval: filter by tenant_id, user_id, deleted_at IS NULL, expires_at first; then hybrid search (vector + full-text, fused with reciprocal rank fusion) and rerank; inject only the top few with their timestamps so the model can judge freshness.

Write Policies

PolicyWhenRisk
Explicit ("remember that...")User asksLow
Extraction after each sessionBackground job extracts facts/preferencesHallucinated or sensitive facts stored
Episode on task completionStore task, outcome, lessonStoring failed approaches as advice
Agent-initiated tool (save_memory)Model decidesNoise, prompt-injected writes

Rules: upsert by subject_key so a new preference replaces the old one; store provenance; never persist secrets or content from untrusted documents as "facts" without review; treat retrieved memories as data, not instructions.

Anti-Patterns

  • Stuffing the entire history until the context limit; cost and latency balloon and quality drops.
  • Similarity search without owner filters: cross-user leakage.
  • Append-only facts with no conflict resolution ("likes tea", "likes coffee", both returned).
  • Summaries that drop constraints ("budget under $500"); pin constraints in state instead.
  • Memories with no expiry or deletion path (privacy and GDPR issues).

Checklist

  • Token budget per working-memory section.
  • Rolling summary keeps decisions, constraints, open questions.
  • Store schema with owner, kind, provenance, timestamps, expiry, soft delete.
  • Scoped hybrid retrieval with reranking; k and token cap set.
  • Upsert semantics for facts/preferences.
  • Deletion and export endpoints; retention job.
  • Eval: questions that require recalling facts from earlier sessions.

References

  • Packer et al., "MemGPT: Towards LLMs as Operating Systems" (2023) — tiered memory paging.
  • Park et al., "Generative Agents" (UIST 2023) — recency/importance/relevance retrieval scoring.
  • Liu et al., "Lost in the Middle" (TACL 2024) — position effects in long contexts.

Shared References

Additional reference material for this skill, stored outside its own references/ folder.

  • ../../../harness-engineering/context-engineering/references/context-drift-mitigation.md — Context Drift Mitigation
  • ../../../harness-engineering/context-engineering/references/dynamic-injection-patterns.md — Dynamic Injection Patterns
  • ../../../harness-engineering/context-engineering/references/memory-retrieval-architectures.md — Memory Retrieval Architectures
  • ../../../harness-engineering/context-engineering/references/priority-scoring-algorithms.md — Priority Scoring Algorithms
  • ../../../harness-engineering/context-engineering/references/prompt-token-optimization.md — Prompt Token Optimization

よくある質問

AIスキル「Ai Agent Memory Systems」では何ができますか?

Use this skill when the user says 'agent memory', 'long-term memory', 'conversation memory', 'remember user preferences', 'context window full', 'summarize history', 'episodic memory', 'semantic memory'. Designs what an agent keeps in its context window, what it stores externally, how it writes and retrieves memories, and how memories expire. Do NOT use for: document RAG pipelines (ai/llm-engineering/rag-architecture), vector DB operations (data or ai vector-database skills), or the agent loop itself (ai/ai-agents/core-architectures).

TypingMindでAi Agent Memory Systemsを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Ai Agent Memory Systemsはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにAi Agent Memory Systemsをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/j4flmao/agent-skills/tree/main/skills/ai/ai-agents/memory-systemsを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Ai Agent Memory Systemsを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Ai Agent Memory Systemsで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもAi Agent Memory Systemsを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Ai Agent Memory Systems」は無料ですか?

はい。j4flmaoがMITライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇