Skip to main content
Glama

BPE Token Budget, Attention Trough & Multi-Model Cost Planner

plan_context_token_budget
Read-onlyIdempotent

Counts BPE tokens across prompt segments, flags high-priority instructions in the 35–72% attention trough, and calculates USD/satoshi costs to audit budgets, reorder sections, and compare models.

Instructions

Counts subword BPE tokens across prompt segments, detects high-priority instructions trapped in the 35%\u201372% Lost-in-the-Middle attention trough, and calculates USD/satoshi costs across frontier LLMs. Use when auditing prompt token budgets, reordering prompt sections for primacy/recency attention, or comparing model API costs; for actively compressing and stripping low-salience lines from a single large file, use prune_context_skeleton instead. Read-only edge call (32 KB, 60 RPM): accepts 'segments_json' (with enum defaults), uses '?demo=true' or L402 (10 sats); HTTP 400 if invalid.

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": {
      "segments_json": "<segments_json>"
    },
    "name": "plan_context_token_budget"
  }
}

Input Schema

NameRequiredDescriptionDefault
segments_jsonYesJSON string or array of prompt segments '[{"name":"sys","text":"...","priority":10}]' to analyze.
max_context_tokensNoTarget model context window limit in tokens; defaults to 128000 when omitted.
target_model_familyNoPrimary model family for token-Window calibration; defaults to 'gemini_3_1' when omitted.

Output Schema

NameRequiredDescriptionDefault
within_budgetYesTrue when total_input_tokens_est fits inside available_input_budget.
total_input_tokens_estYesTotal BPE tokens summed across all prompt segments.
lost_in_the_middle_warningsYesWarnings for high-priority segments positioned in the 35%–72% attention trough.
multi_model_cost_comparisonYesEstimated USD and satoshi inference cost across 5 frontier models.
optimal_primacy_recency_orderYesRecommended segment ordering placing critical instructions at prompt boundaries.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv1.3.3

TDQS

A4.6/5.0
Behavior5/5

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

Goes well beyond the readOnlyHint/idempotentHint annotations by disclosing operational constraints: a 32 KB payload ceiling, 60 RPM rate limit, authentication via '?demo=true' or L402 payment of 10 sats, and HTTP 400 on invalid input. These are exactly the traits an agent needs before invoking an edge endpoint.

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?

Front-loaded with the core capability, then usage, then the sibling exclusion, then operations — a good information order with near-zero waste. The parenthetical '(with enum defaults)' is confusing filler that costs a little clarity.

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

Completeness5/5

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

An output schema exists, so return values need not be described; parameters are fully schema-covered; and the description supplies the routing, auth, and failure-mode context that the structured fields do not. Nothing an agent needs to call this correctly is missing.

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 description coverage is 100%, so the schema already documents segments_json, max_context_tokens, and target_model_family. The description's 'segments_json (with enum defaults)' is slightly muddled — the enum actually belongs to target_model_family — and adds no new syntax or format guidance, so baseline 3 applies.

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?

States concrete verbs and resources: counts BPE tokens across prompt segments, detects instructions in the 35%–72% attention trough, and computes USD/satoshi model costs. This is specific enough that an agent can distinguish it from compression-oriented siblings without opening any schema.

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

Usage Guidelines5/5

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

Explicitly names three triggering scenarios (auditing token budgets, reordering for primacy/recency, comparing API costs) and names the alternative for the adjacent case: prune_context_skeleton for actively compressing/stripping a single large file. When-to-use, when-not, and the sibling route are all present.

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

Deploy Server

Other Tools