Memwry Docs & A2A

Six Core Agent Use Cases & Machine-Readable Agent Card

Six Core Use Cases

x402 on Base

Memwry provides pay-per-write, free-to-read ephemeral memory slots with strict storage-level TTLs (6h or 12h) and idempotent payment replay guarantees.

Use Case 01 Tier: 12h ($0.02) or 6h ($0.01)

Task State (Survive Restarts & Crashes)

Use this when: An agent runs multi-step pipelines where a crash or timeout would lose intermediate progress. Save progress before risky steps; recall on boot. Retries with the same Idempotency-Key never double-charge.

// 1. Save checkpoint before executing risky step ($0.02 for 12h)
const taskId = "task-sync-9481";
const checkpointKey = `checkpoint:${taskId}`;

await payFetch(`https://memwry.servitor.workers.dev/mem/orchestrator/${checkpointKey}/12h`, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": `idem_${taskId}_step3`
  },
  body: JSON.stringify({
    completedSteps: ["fetch_data", "transform_schema"],
    currentStep: "load_destination",
    cursor: "rec_9938102"
  })
});

// 2. On worker restart or crash recovery:
const recoveryRes = await fetch(`https://memwry.servitor.workers.dev/mem/orchestrator/${checkpointKey}`);
if (recoveryRes.ok) {
  const state = await recoveryRes.json();
  console.log("Resuming task from cursor:", state.cursor);
}
Use Case 02 Tier: 6h ($0.01)

Session Memory (Cross-Request Ephemeral Context)

Use this when: Serverless or multi-instance conversational agents have no shared conversation state. Write an updated session state once, recall it every turn, and let TTL self-destruct state when the session ends without manual database cleanup.

const sessionId = "sess_user_alpha_77";

// Save updated conversation memory turn ($0.01 for 6h)
await payFetch(`https://memwry.servitor.workers.dev/mem/agent-chatbot/session:${sessionId}/6h`, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": crypto.randomUUID()
  },
  body: JSON.stringify({
    userIntent: "book_flight_paris",
    slots: { destination: "CDG", departDate: "2026-10-15", passengers: 2 },
    lastInteraction: new Date().toISOString()
  })
});

// Free recall on the next incoming chat webhook:
const sessionRes = await fetch(`https://memwry.servitor.workers.dev/mem/agent-chatbot/session:${sessionId}`);
const sessionData = sessionRes.ok ? await sessionRes.json() : null;
Use Case 03 Tier: 6h ($0.01)

Scratch Space (Offload Large Context Window Artifacts)

Use this when: Intermediate artifacts, tool output dumps, or scraped content are too large for the active LLM context window. Park the raw bytes under a scratch key, keep only a reference pointer in context, and retrieve parts on demand.

const runId = "run_audit_01";
const rawHtmlPayload = "... large 200KB web page dump ...";

// Park raw artifact in scratch space ($0.01 for 6h TTL)
await payFetch(`https://memwry.servitor.workers.dev/mem/researcher/scratch:${runId}:page/6h`, {
  method: "POST",
  headers: {
    "Content-Type": "text/html",
    "Idempotency-Key": `idem_scratch_${runId}`
  },
  body: rawHtmlPayload
});

// Subsequent tool execution retrieves specific stored artifact for free:
const docRes = await fetch(`https://memwry.servitor.workers.dev/mem/researcher/scratch:${runId}:page`);
const rawHtml = await docRes.text();
Use Case 04 Tier: 6h ($0.01)

LLM Response Cache (Stop Re-Paying for Reasoning)

Use this when: Multiple agents or invocations run identical heavy reasoning queries. Keying by SHA-256 hash of prompt + model enables a single $0.01 write to replace repeated $0.12 LLM completions, cutting token expenditures by over 90%.

import { createHash } from "node:crypto";

const prompt = "Summarize the technical spec of RFC 9457 Problem Details";
const promptHash = createHash("sha256").update(`gemini-2.5-flash|${prompt}`).digest("hex");
const cacheKey = `cache:${promptHash}`;

// 1. Check cache first (free read)
const cached = await fetch(`https://memwry.servitor.workers.dev/mem/synthesizer/${cacheKey}`);
if (cached.ok) {
  const result = await cached.text();
  console.log("Cache hit (free recall):", result);
} else {
  // 2. Compute via LLM and cache for 6 hours ($0.01 write)
  const answer = "RFC 9457 defines a 'problem detail' as a way to carry machine-readable error details...";
  await payFetch(`https://memwry.servitor.workers.dev/mem/synthesizer/${cacheKey}/6h`, {
    method: "POST",
    headers: { "Content-Type": "text/plain", "Idempotency-Key": `idem_${promptHash}` },
    body: answer
  });
}
Use Case 05 Tier: 12h ($0.02)

Multi-Agent Handoff (Decoupled State Relay)

Use this when: Agent A produces an execution plan and needs Agent B to execute it without orchestrating message queues or shared database credentials. The memory key string acts as the lightweight coordination handle.

// AGENT A (Planner) writes handoff plan:
const handoffChannel = "handoff:batch-3810";
await payFetch(`https://memwry.servitor.workers.dev/mem/shared-pipeline/${handoffChannel}/12h`, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": "idem_handoff_batch_3810"
  },
  body: JSON.stringify({
    assignedTo: "agent-coder-9",
    actionPlan: ["implement_types", "write_tests", "deploy_worker"],
    specVersion: "v2.1"
  })
});

// AGENT B (Executor) polls and recalls handoff artifact for free:
const handoffRes = await fetch(`https://memwry.servitor.workers.dev/mem/shared-pipeline/${handoffChannel}`);
if (handoffRes.ok) {
  const instructions = await handoffRes.json();
  console.log("Received handoff for:", instructions.assignedTo);
}
Use Case 06 Tier: 6h ($0.01)

Upstream API Cache (Rate-Limit & Cost Shield)

Use this when: Calling costly or tightly rate-limited external APIs (DEX prices, blockchain oracles, search indices). Memwry acts as an edge caching shield that absorbs concurrent requests while invalidating automatically after TTL.

const symbol = "ETH_USDC";
const apiCacheKey = `apicache:dex:${symbol}`;

// 1. Free read check against edge memory
const cacheRes = await fetch(`https://memwry.servitor.workers.dev/mem/dex-oracle/${apiCacheKey}`);
if (cacheRes.ok) {
  const quote = await cacheRes.json();
  console.log("Cached DEX quote:", quote.price);
} else {
  // 2. Query upstream provider and cache for 6 hours
  const upstreamQuote = { price: 3412.50, timestamp: Date.now() };
  await payFetch(`https://memwry.servitor.workers.dev/mem/dex-oracle/${apiCacheKey}/6h`, {
    method: "POST",
    headers: { "Content-Type": "application/json", "Idempotency-Key": `idem_dex_${symbol}_${Date.now()}` },
    body: JSON.stringify(upstreamQuote)
  });
}