DevTools Logo

AI Agent Memory & Buffer Simulator

AI Agent Memory & Buffer Simulator

Compare memory strategies and context cost locally in your browser

Message sequence

About

Compare last-N sliding windows, compact summary placeholders, and keyword-scored top-k vector memory retrieval. Costs use chars divided by four and all processing stays client-side.

Examples

Sliding window

Input
simulateAgentMemory(["one", "two", "three", "four"], { strategy: "window", limit: 2 })
Output
{ selectedMessages: ["three", "four"] }

Only the last N messages survive; older turns count as dropped with informationLoss true.

Keyword retrieval

Input
simulateAgentMemory(["cats dogs birds", "cats dogs", "unrelated"], { strategy: "vector", topK: 2, query: "cats dogs birds" })
Output
{ retrieved: [{ index: 0, score: 3 }, { index: 1, score: 2 }] }

Shared-word scores rank matches and topK cuts the list to the two best hits.

About this tool

AI Agent Memory Simulator models context budgets with simulateAgentMemory(messages, { strategy, limit, topK, query }) (alias simulateMemory): window keeps the last N messages, summary replaces older turns with a [Summary of K earlier messages] line plus the recent N, and vector retrieves the top-K keyword-overlap matches for the query. compareMemoryStrategies runs all three side by side for one limit and query.

Scoring is deterministic and client-safe: vector score counts shared words (Unicode letters/numbers), ties break by recency (higher index first), and token estimates use Math.ceil(chars/4). The context string numbers the selected messages and appends User: <query> when a query is present.

Costs tell the story: summary context is cheaper than a full window over the same history, droppedMessages and informationLoss flag what fell out of context, and empty history yields an empty selection with just the query line — no throws, byte-identical on repeat runs.

How to use this tool

  1. Build a history

    Pass plain strings or { role, content } messages; empty strings are filtered and empty history is valid.

  2. Pick a strategy and limit

    Use window/limit for recency, summary/limit for compressed recall, or vector/topK plus a query for retrieval.

  3. Compare the costs

    Run compareMemoryStrategies to contrast estimatedTokens, droppedMessages, and informationLoss across all three.

  4. Read retrieval order

    Check retrieved index/score pairs — higher score wins, recency breaks ties, and topK caps the selection.

Use cases

Sizing context windows

Prove how many recent turns fit a token budget before wiring max-history into the agent loop.

Justifying summarization

Show summary tokens beating a full-window replay while keeping recent turns verbatim.

Debugging retrieval tuning

Inspect scores and tie order to tune keywords, topK, and query phrasing for vector memory.

Common mistakes

Mistake:Expecting semantic embeddings.

Fix:Matching is keyword overlap only — paraphrases without shared words score zero and are not retrieved.

Mistake:Assuming ties keep original order.

Fix:Equal scores sort by descending index, so the newest tied message ranks first, not the oldest.

Mistake:Treating estimatedTokens as exact.

Fix:Costs are chars/4 approximations for comparison, not tokenizer-exact billing numbers.

Frequently asked questions

What does this tool do?

It simulates context memory with simulateAgentMemory (alias simulateMemory): window keeps the last N, summary compresses older turns into one line, vector retrieves top-K keyword matches — plus compareMemoryStrategies to contrast all three on cost and loss.

How are retrieval ties ordered, and is summary cheaper?

Equal keyword scores break by recency (newest first), so three report matches return indexes [2, 1, 0]. Summary context costs fewer tokens than a full window over the same history.

Is my conversation uploaded or stored?

No. History simulation, keyword scoring, and token math run fully client-side.

What happens with empty history?

Nothing breaks: selection is empty, context is just User: <query> (or empty without a query), and informationLoss is false across window, summary, and vector.

References & standards