basic-memory icon indicating copy to clipboard operation
basic-memory copied to clipboard

Prompt memory budget indicators — show agents how full their context injection is

Open bm-clawd opened this issue 8 months ago • 3 comments

Idea

Hermes renders memory with a usage indicator: MEMORY (your personal notes) [67% — 1,474/2,200 chars]. This gives the agent a clear signal about how much budget remains, encouraging curation over accumulation.

Problem

Agents using BM notes in their prompts have no visibility into how much context they're consuming. This leads to:

  • Memory files growing unbounded until they cause problems
  • No pressure to curate — agents append but rarely prune
  • Surprise context window issues when notes get too large

Proposal

When BM notes are loaded into agent context (via MCP tools or context file injection), include a budget indicator:

══════════════════════════════════════════════
KNOWLEDGE CONTEXT [3,200/8,000 tokens — 40%]
══════════════════════════════════════════════

This could be:

  1. A config option — agents or users set a token budget for BM context
  2. Returned in tool responses — search/read results include a running total
  3. A standalone tool — context_budget returns current usage stats

The key insight: making the budget visible creates natural pressure to curate. The agent sees it's at 90% and starts pruning instead of appending.

References

  • Hermes Agent char-based memory limits with rendered usage indicators
  • Progressive loading (issue #686) complements this — load less by default, budget stays low

bm-clawd avatar Mar 21 '26 14:03 bm-clawd

Claude finished @bm-clawd's task in 1m 18s —— View job


Issue Triage

  • [x] Gather context and analyze issue
  • [x] Explore codebase for relevant components
  • [x] Check for duplicate issues
  • [x] Apply labels
  • [x] Post triage analysis

Analysis

Type: Feature Request — Enhancement to existing MCP tools
Priority: Medium
Component: MCP tools (build_context, search_notes, read_note, recent_activity)
Complexity: Medium

No duplicates found. The related issue #686 (Progressive loading) is complementary as mentioned in the issue body.


Triage Notes

This is a well-scoped idea that addresses a real problem: agents have no visibility into how much context budget their BM notes are consuming, which leads to unbounded growth and surprise context window issues.

Codebase observations:

  • build_context already returns a footer with metadata: *N primary, M related | depth=D | project: P*
  • _format_context_markdown() in build_context.py is the natural place to add a char/token indicator for output_format="text"
  • The JSON response path (graph.model_dump()) could include a char_count or token_estimate field in the metadata
  • search_notes and read_note have similar response shaping points

Recommended approach (Option 2 from the issue — returned in tool responses):
Adding budget indicators directly to tool responses is the lowest-friction path. No new config required, no new tool required — just augment the existing footer/metadata in build_context, search_notes, read_note, and recent_activity text output with a char count and optional token estimate.

Example for build_context text output:

*3 primary, 7 related | depth=1 | project: research*
*Context size: 3,200 chars (~800 tokens)*

A configurable context_budget (Option 1) could be a follow-on: if set in config, the indicator becomes 3,200/8,000 chars (40%) — creating the explicit pressure to curate described in the issue.

Labels applied: enhancement

claude[bot] avatar Mar 21 '26 14:03 claude[bot]

For agent workflows, a context budget indicator would be most useful if it also identified:

  • what was loaded;
  • from which project;
  • at which detail level;
  • whether content was truncated;
  • whether the result came from search or exact read;
  • whether the budget applies to one tool response or the whole injected context.

A raw percentage alone may be misleading if several tools or memory surfaces contribute to the same prompt.

This feedback was prepared collaboratively by Semyon Poklad and the AI agent Lad. It is based on a small multi-agent family-research MVP and is offered as a user-side observation, not a claim about Basic Memory's internal architecture. The final text was reviewed and manually approved by Semyon before posting.

TeaShaman-cyber avatar Aug 02 '26 20:08 TeaShaman-cyber

this is a job for the harness. declining

phernandez avatar Aug 11 '26 01:08 phernandez