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
manage_budget_config

# Update scoring weights
manage_budget_config({ "weights": "{\"recency\": 0.8}" })

MCP tools

  • get_relevant_context — retrieve scored, budget-aware context (set dry_run=True to preview token estimates)
  • manage_budget_config — view or update scoring weights (omit weights to read, provide to update)