Agent Memory & Context Management Protocol
$0.05 / access
SKILL.md
Claude Code · Cursor · AutoGen · CrewAI · LangGraph
agent-memory-context-skill is a 7-phase behavioral protocol for AI agents that prevents the context overflow death spiral — the failure mode where an agent's context window fills, it loses its task state, and it loops or halts indefinitely. The protocol covers working vs. long-term memory taxonomy, context window budget allocation, compression thresholds, RAG integration patterns, session persistence, multi-agent context sharing, and memory decay policies. Load it at task start via x402; your agent has the full instruction set for the session.
The context overflow death spiral: As agents run longer tasks, conversation history grows until the context window fills. Without a compression and persistence strategy, agents start dropping critical task state, tools, or prior decisions — leading to repeated work, contradictory outputs, or outright task failure. This protocol defines exactly when to summarize vs. store verbatim, how to allocate the context budget across task state / history / tools / output reserve, and how to persist across session restarts.
What This Protocol Covers (7 Phases)
- Memory Taxonomy — Working vs. long-term memory model: task state, conversation history, tool definitions, episodic memory, semantic memory, and procedural memory. TypeScript interface included.
- Context Window Budget Allocation — The 4-bucket budget model: 15% task state / 40% history / 25% tool definitions / 20% output reserve. Token estimation and enforcement logic.
- Compression Thresholds — Decision tree: summarize vs. store verbatim. Compression policy with verbatim patterns (transaction hashes, code blocks, error messages). Rolling 20-turn window with LLM summarization above 8K tokens.
- RAG Integration Patterns — Embedding, retrieval, and deduplication with vector stores (Pinecone). Cosine similarity deduplication threshold. Context augmentation with memory injection up to token budget.
- Session Persistence — Checkpoint pattern: what survives restarts (critical/resumable) vs. what must be invalidated (ephemeral). Resume-on-restart logic with 24h staleness check.
- Multi-Agent Context Sharing — What to pass downstream vs. keep private. Context handoff pattern for orchestrators. 30% token slice for sub-agents. Result merge back to parent state.
- Memory Decay & Staleness Policies — TTL by memory type: 7 days (episodic), 90 days (semantic), permanent (procedural). Importance-based eviction with decay rate. 10,000-entry hard cap per agent.
Agent Use Cases
- Long-running autonomous agents — multi-hour or multi-day tasks that would otherwise hit context limits mid-execution; this protocol defines the compression and persistence checkpoints that prevent task state loss
- Multi-agent orchestrators — sub-agent context handoff, downstream context scoping, and result merge patterns for systems running 5–50 parallel agents
- Coding agents (Claude Code, Cursor, Codex CLI) — codebase context management: what to keep verbatim (exact file paths, error messages, commit hashes) vs. what to summarize (reasoning, background context)
- Research agents — episodic memory across sessions (what was researched, what conclusions were reached) combined with semantic memory (embedded fact index) for multi-session research workflows
- LLM cost optimization — tool definition injection strategy: route to task-relevant tools only instead of injecting all MCP tools every call; saves 100–800 tokens per injected tool definition
How to Access via x402
# Step 1: Free preview — inspect the protocol structure
curl https://clawmerchants.com/v1/preview/agent-memory-context-skill
# Step 2: Probe the endpoint — receive 402 with payment details
curl https://clawmerchants.com/v1/data/agent-memory-context-skill
# → HTTP 402: X-Payment-Required: 0.05 USDC on Base L2
# Step 3: Pay and receive
# Send 0.05 USDC on Base L2 (chain ID 8453) → resend with X-PAYMENT header
curl -H "X-PAYMENT: <base64-proof>" \
https://clawmerchants.com/v1/data/agent-memory-context-skill
# → HTTP 200: full SKILL.md protocol text
Protocol Specification Summary
| Dimension | Value |
| Protocol phases | 7 |
| Memory tiers | Working (context) + Long-term (external) |
| Context budget model | 15% task / 40% history / 25% tools / 20% output |
| Compression threshold | Summarize above 8,000 tokens; 20-turn verbatim window |
| Session persistence | Checkpoint every major step; 24h staleness TTL |
| Memory decay TTL | Episodic: 7d · Semantic: 90d · Procedural: permanent |
| Compatible runtimes | Claude Code, Cursor, Codex CLI, AutoGen, CrewAI, LangGraph, ChatGPT, Gemini CLI |
| Price | $0.05 USDC / access · x402 on Base L2 |
Pricing
$0.05 USDC per access — no subscription, no API key, no account. Each agent session loads the protocol once via x402 at task start. At $0.05/access, a team running 100 agent sessions/day pays $5/day for the full memory management protocol — less than the cost of one redundant LLM call caused by context overflow.
ClawMerchants — agent memory management protocol | context overflow agent | AI agent context limit | LLM context window management | agent memory protocol | context overflow death spiral | x402 + USDC + Base L2