Skip to content

Comments

feat: expose context window utilization to agent via MOIM#7418

Merged
tlongwell-block merged 2 commits intomainfrom
tyler/context-token-awareness
Feb 22, 2026
Merged

feat: expose context window utilization to agent via MOIM#7418
tlongwell-block merged 2 commits intomainfrom
tyler/context-token-awareness

Conversation

@tlongwell-block
Copy link
Collaborator

@tlongwell-block tlongwell-block commented Feb 22, 2026

Summary

Add token/context usage info to the per-turn <info-msg> (MOIM — Minus One Info Message) injection so the agent can see how much of its context window is consumed and make informed decisions (e.g., summarize early, hand off, or keep going).

The agent now sees a line like:

Context: ~85k/128k tokens used (66%)

Implementation

~22 lines in collect_moim() in extension_manager.rs, which already has access to both the provider (context_limit) and session_manager (total_tokens). No new files, no new dependencies, no new abstractions.

Fail-open guarantees (4 layers)

  1. if let Ok(session) — session lookup fails → skip silently
  2. if let (Some(total), Some(config)) — missing token data or model config → skip silently
  3. total > 0 — negative or zero tokens (first turn, corrupt state) → skip silently
  4. limit > 0 — zero context limit → skip silently (also prevents division by zero)

Why this matters

The agent currently has zero visibility into its own context usage. It can't tell if it's at 20% or 95% of its context window. This leads to:

  • Agents running into compaction unexpectedly
  • No ability to proactively summarize or hand off when running low
  • Context management decisions happening around the agent instead of with it

Related issues: #1703, #7415, #7413, #6930, #5255, #3485

Add token/context usage info to the per-turn <info-msg> injection so the
agent can see how much of its context window is consumed and make informed
decisions (e.g., summarize early, hand off, or keep going).

The agent now sees a line like:
  Context: ~85k/128k tokens used (66%)

Implementation: ~15 lines in collect_moim() which already has access to
both the provider (context_limit) and session_manager (total_tokens).

Fails open at four layers: session lookup failure, missing token data,
missing model config, and zero/negative values all silently skip the line.
@tlongwell-block tlongwell-block marked this pull request as ready for review February 22, 2026 17:10
@tlongwell-block tlongwell-block added this pull request to the merge queue Feb 22, 2026
Merged via the queue into main with commit c8d4057 Feb 22, 2026
17 of 21 checks passed
@tlongwell-block tlongwell-block deleted the tyler/context-token-awareness branch February 22, 2026 18:18
tlongwell-block added a commit that referenced this pull request Feb 22, 2026
* origin/main:
  feat: expose context window utilization to agent via MOIM (#7418)
  Small model naming (#7394)
  chore(deps): bump ajv in /documentation (#7416)
michaelneale added a commit that referenced this pull request Feb 23, 2026
* main: (27 commits)
  dev: add cmake to hermitized env (#7399)
  refactor: remove allows_unlisted_models flag, always allow custom model entry (#7255)
  feat: expose context window utilization to agent via MOIM (#7418)
  Small model naming (#7394)
  chore(deps): bump ajv in /documentation (#7416)
  doc: groq models (#7404)
  Client settings (#7381)
  Fix settings tabs getting cut off in narrow windows (#7379)
  docs: voice dictation updates (#7396)
  [docs] Add Excalidraw MCP App Tutorial (#7401)
  Post release checklist as a comment on release PRs (#7307)
  unique api key (#7391)
  fix: use correct colors for download progress bar (#7390)
  Add local model settings access from bottom bar model menu (#7378)
  Change Recipe Security Scanner API key (#7387)
  switch Ask AI Discord bot from openrouter to anthropic (#7386)
  feat(ui): show token counts directly for "free" providers (#7383)
  Update creator note (#7384)
  Remove display_name from local model API and use model ID everywhere (#7382)
  fix(summon): stop MOIM from telling models to sleep while waiting for tasks (#7377)
  ...
lifeizhou-ap added a commit that referenced this pull request Feb 23, 2026
* main: (73 commits)
  dev: add cmake to hermitized env (#7399)
  refactor: remove allows_unlisted_models flag, always allow custom model entry (#7255)
  feat: expose context window utilization to agent via MOIM (#7418)
  Small model naming (#7394)
  chore(deps): bump ajv in /documentation (#7416)
  doc: groq models (#7404)
  Client settings (#7381)
  Fix settings tabs getting cut off in narrow windows (#7379)
  docs: voice dictation updates (#7396)
  [docs] Add Excalidraw MCP App Tutorial (#7401)
  Post release checklist as a comment on release PRs (#7307)
  unique api key (#7391)
  fix: use correct colors for download progress bar (#7390)
  Add local model settings access from bottom bar model menu (#7378)
  Change Recipe Security Scanner API key (#7387)
  switch Ask AI Discord bot from openrouter to anthropic (#7386)
  feat(ui): show token counts directly for "free" providers (#7383)
  Update creator note (#7384)
  Remove display_name from local model API and use model ID everywhere (#7382)
  fix(summon): stop MOIM from telling models to sleep while waiting for tasks (#7377)
  ...
zanesq added a commit that referenced this pull request Feb 23, 2026
…oviders

* 'main' of github.com:block/goose:
  New navigation settings layout options and styling (#6645)
  refactor: MCP-compliant theme tokens and CSS class rename (#7275)
  Redirect llama.cpp logs through tracing to avoid polluting CLI stdout/stderr (#7434)
  refactor: change open recipe in new window to pass recipe id (#7392)
  fix: handle truncated tool calls that break conversation alternation (#7424)
  streamline some github actions (#7430)
  Enable bedrock prompt cache (#6710)
  fix: use BEGIN IMMEDIATE to prevent SQLite deadlocks (#7429)
  Display working dir (#7419)
  dev: add cmake to hermitized env (#7399)
  refactor: remove allows_unlisted_models flag, always allow custom model entry (#7255)
  feat: expose context window utilization to agent via MOIM (#7418)
  Small model naming (#7394)
  chore(deps): bump ajv in /documentation (#7416)
  doc: groq models (#7404)
  Client settings (#7381)
  Fix settings tabs getting cut off in narrow windows (#7379)

# Conflicts:
#	ui/desktop/src/components/settings/dictation/DictationSettings.tsx
michaelneale added a commit that referenced this pull request Feb 23, 2026
…xt-edit

* origin/main: (35 commits)
  docs: generate manpages (#7443)
  Blog/goose v1 25 0 release (#7433)
  fix: detect truncated LLM responses in apps extension (#7354)
  fix: removed unnecessary version for goose acp macro dependency (#7428)
  add flag to hide select voice providers (#7406)
  New navigation settings layout options and styling (#6645)
  refactor: MCP-compliant theme tokens and CSS class rename (#7275)
  Redirect llama.cpp logs through tracing to avoid polluting CLI stdout/stderr (#7434)
  refactor: change open recipe in new window to pass recipe id (#7392)
  fix: handle truncated tool calls that break conversation alternation (#7424)
  streamline some github actions (#7430)
  Enable bedrock prompt cache (#6710)
  fix: use BEGIN IMMEDIATE to prevent SQLite deadlocks (#7429)
  Display working dir (#7419)
  dev: add cmake to hermitized env (#7399)
  refactor: remove allows_unlisted_models flag, always allow custom model entry (#7255)
  feat: expose context window utilization to agent via MOIM (#7418)
  Small model naming (#7394)
  chore(deps): bump ajv in /documentation (#7416)
  doc: groq models (#7404)
  ...
aharvard added a commit that referenced this pull request Feb 24, 2026
* origin/main: (49 commits)
  add flag to hide select voice providers (#7406)
  New navigation settings layout options and styling (#6645)
  refactor: MCP-compliant theme tokens and CSS class rename (#7275)
  Redirect llama.cpp logs through tracing to avoid polluting CLI stdout/stderr (#7434)
  refactor: change open recipe in new window to pass recipe id (#7392)
  fix: handle truncated tool calls that break conversation alternation (#7424)
  streamline some github actions (#7430)
  Enable bedrock prompt cache (#6710)
  fix: use BEGIN IMMEDIATE to prevent SQLite deadlocks (#7429)
  Display working dir (#7419)
  dev: add cmake to hermitized env (#7399)
  refactor: remove allows_unlisted_models flag, always allow custom model entry (#7255)
  feat: expose context window utilization to agent via MOIM (#7418)
  Small model naming (#7394)
  chore(deps): bump ajv in /documentation (#7416)
  doc: groq models (#7404)
  Client settings (#7381)
  Fix settings tabs getting cut off in narrow windows (#7379)
  docs: voice dictation updates (#7396)
  [docs] Add Excalidraw MCP App Tutorial (#7401)
  ...

# Conflicts:
#	ui/desktop/src/components/McpApps/McpAppRenderer.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants