Skip to content

[feat] Ambient context-usage meter sourced from the model catalog#5434

Open
ashrafchowdury wants to merge 4 commits into
fe-feat/session-context-infofrom
feat/extend-arda's-session-context-work
Open

[feat] Ambient context-usage meter sourced from the model catalog#5434
ashrafchowdury wants to merge 4 commits into
fe-feat/session-context-infofrom
feat/extend-arda's-session-context-work

Conversation

@ashrafchowdury

@ashrafchowdury ashrafchowdury commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Stacked PR. Base branch is fe-feat/session-context-info (Arda's original
indicator)

Context

This extends Arda's context-usage indicator. Two problems with that first version:

  1. The context-window denominator came from MODEL_CONTEXT_WINDOWS, a hardcoded ~25-entry
    map in the frontend, matched to the selected model by longest-substring guessing. Every
    new model needed a manual edit, and the substring match was fragile.
  2. The indicator showed two raw token measures side by side with developer labels
    (Ctx 407.0k / 1.0M (39%) · Σ 407.0k (39%)). That side-by-side was an internal A/B to
    pick one measure, and it shipped to end users who do not know what Ctx, Σ, or a
    "token" is.

Changes

Context window now comes from the model catalog, not a frontend map.
The SDK already ships each model's context_window on the harness-capabilities document
the frontend fetches (from model_catalog.py), so the denominator was already in the
browser. Deleted the hardcoded map and its substring resolver. A new selector resolves the
window by exact model id.

Before (hand-edited per model, substring-matched):

const MODEL_CONTEXT_WINDOWS = {
"gpt-4o": 128_000,
"claude-3-5-sonnet": 200_000,
// ~25 more...
}

After (exact-id lookup into the catalog that is already on the capabilities doc):

contextWindowForModel(capabilities, harness, modelId)
// → capabilities[harness].model_catalog.find(e => e.id === modelId)?.context_window

No new endpoint. Every model in the picker is covered automatically, and the match is
exact instead of a guess.

The indicator is now an ambient meter, not a dual token readout.
Dropped the Σ running-sum measure from both the data layer and the UI. It double-counted
resent history and never dropped, so it was the misleading one. Kept occupancy: the latest
turn's total tokens, which is how full the window is right now.

Before:
Ctx 407.0k / 1.0M (39%) · Σ 407.0k (39%)

After: a slim fill bar plus one plain line.
▓▓▓▓░░░░░░ Context 39% used

The line escalates with fill: neutral gray with room, amber at 75%, a faded red with a
warning icon and "Context almost full · 95%" at 90%. Exact counts move to the tooltip in
compact form (407k / 1M tokens), with a one-line explanation of what the context window
is and that older messages get summarized as it fills.

Prop and type changes for reviewers:

  • ContextBudgetIndicator takes maxTokens: number | null instead of model: string.
  • ContextBudget dropped runningSumTokens, runningSumPct, and perTurnTokens.
  • useAgentModelKeyStatus now also returns harness (read from agent.harness.kind).
  • New public export contextWindowForModel from @agenta/entities/workflow.

Tests / notes

  • @agenta/entities builds clean; OSS tsc --noEmit shows no new errors in the touched
    files; ESLint and prettier pass.
  • The indicator was the only reader of the dropped runningSum/perTurn fields, so no
    other consumer changed.
  • Follow-up, not in this PR: some catalog entries carry context_window: null (e.g. the
    Claude default alias). Those models show a raw token count with no bar or percent.
    Filling that in is a data change in model_catalog.py, not frontend.

What to QA

  • Open an agent session and send a few turns. The composer footer shows a gray bar and
    "Context N% used", where N tracks the latest turn.
  • Hover it. The tooltip shows compact tokens (407k / 1M tokens) and the plain explanation.
  • Switch the agent between a large-window model (a Pi 1M model) and a 200k model. The
    percent and bar rescale to the new denominator, confirming the catalog lookup rather than
    a hardcoded number.
  • Regression: pick a model the old map never listed. It still shows a percent (resolved
    from the catalog) instead of a bare token count.
  • Tiers: to see amber and red without a huge session, temporarily force occupancy near 80%
    and 95% in ContextBudgetIndicator (thresholds are >=0.75 amber, >=0.9 red).

Previews

image

When context fills up

image

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 21, 2026
@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview, Comment Jul 21, 2026 11:18am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ee9a0d2b-9bce-4ed1-b215-27cc9951dfaf

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/extend-arda's-session-context-work

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Frontend Improvement size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants