Context Budgeting

Intelligent token-aware context selection that works behind the scenes. As your Engrams database grows, budgeting ensures the AI loads only what matters for the current task — keeping prompts fast and costs low.

The problem it solves

Your Engrams database grows over time — 50 decisions, 20 patterns, dozens of glossary terms. Loading all of them into every prompt would be expensive and noisy. Context budgeting scores each item by relevance and fits only the highest-value items into the token window.

Example

You: "Add WebSocket support for real-time notifications"

AI:  Retrieving project context...

     Loaded 6 of 43 Engrams items (budget: 4,000 tokens):
     ✓ Decision #31: Use WebSockets for real-time features
     ✓ Pattern #8:   Event-driven pub/sub architecture
     ✓ Decision #7:  JWT auth (tokens must validate on WS connect)
     ✓ Decision #19: Redis for pub/sub message brokering
     ✓ Pattern #12:  Connection lifecycle management
     ✓ Glossary:     "notification_channel" schema definition

     Skipped 37 lower-relevance items (database indexing,
     REST endpoint conventions, deployment configs, etc.)

     Implementing WebSocket endpoint using pub/sub with Redis,
     authenticating via JWT on connect...

Scoring factors

  • Semantic similarity — how closely the item relates to the current query
  • Recency — recently updated items score higher
  • Code bindings — items bound to files being edited score higher
  • Item type — configurable per-type base weights

Configuration

View and update the budget configuration using the MCP tools:

# View current config
get_context_budget_config

# Update the token budget (example: increase to 8000 tokens)
update_context_budget_config({ "max_tokens": 8000 })

MCP tools

  • get_relevant_context — retrieve scored, budget-aware context
  • estimate_context_size — estimate token usage before loading
  • get_context_budget_config — view current budget settings
  • update_context_budget_config — adjust budget and scoring weights