Skip to main content
Glama

Search Memories Within a Token Budget

memory-budget

Retrieve memories that fit a specified token budget, ranked by relevance and importance, so AI agents can fill limited context slots without exceeding limits.

Instructions

Like memory-search, but returns memories that fit within a TOKEN BUDGET instead of a count limit. Greedy fill from highest-relevance memories: candidates ranked by score × importance, included until the next entry would exceed the budget. Used by przm's Context Budget Engine: the persona/memories slot allocates N tokens, and przm Memory returns "the most useful subset that fits." Returns the same memory shape as memory-search plus { budgetTokens, usedTokens, includedCount, candidateCount } so callers can see how the budget got spent.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "query": "<query>",
      "budgetTokens": "<budgetTokens>"
    },
    "name": "memory-budget"
  }
}

Input Schema

NameRequiredDescriptionDefault
tagNoFilter by exact tag match.
queryYesNatural language search query.
topicNoFilter by topic.
domainNoFilter by domain/project.
formatNoIf true, returns formatted text grouped by cognitive layer instead of JSON.
budgetTokensYesToken budget for the returned set. Greedy fill stops before exceeding this. Recommended range: 200 (tight slot) to 5000 (generous).
candidateLimitNoMax candidates to consider before budget filtering (default: 50). Larger candidate pool = better quality picks but slower search.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.6.0

TDQS

A4.1/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full load and does well: it discloses the greedy-fill algorithm, the score × importance ranking key, the stop rule (stop before the next entry would exceed the budget), and the extra response fields (budgetTokens, usedTokens, includedCount, candidateCount). It omits permissions/auth and behavior on zero matches, but the core mechanics are unusually well exposed.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The key differentiator is front-loaded in the first sentence and the algorithm follows logically. The 'Used by przm's Context Budget Engine... "the most useful subset that fits"' passage is partly redundant framing that could be trimmed, but it does anchor the intended use case.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 7-parameter read tool with no output schema, the description covers the algorithm, the budget semantics, and the returned shape including the four budget-reporting fields. Only edge cases (empty results, auth requirements, performance caveats of large candidateLimit) are left unaddressed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so every parameter is already documented in the schema, which sets the baseline at 3. The description reinforces budgetTokens and the candidate/ranking tradeoff but adds no format details (e.g., how query is matched, how format=true groups by cognitive layer) beyond what the schema states.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific operation (return memories that fit a token budget) and contrasts it directly with the sibling memory-search along the axis that distinguishes them (budget vs. count limit). An agent can tell exactly which of the two to call without opening either schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives a concrete use case (the persona/memories slot of a context-budget engine allocating N tokens) and implicitly routes count-limited searches to memory-search via 'instead of a count limit.' It does not spell out an explicit when-not or failure condition, but the context is clear enough to select correctly.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.