[feat] Ambient context-usage meter sourced from the model catalog#5434
[feat] Ambient context-usage meter sourced from the model catalog#5434ashrafchowdury wants to merge 4 commits into
Conversation
…ntext window for token budgeting
…y and performance
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Context
This extends Arda's context-usage indicator. Two problems with that first version:
MODEL_CONTEXT_WINDOWS, a hardcoded ~25-entrymap 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.
(
Ctx 407.0k / 1.0M (39%) · Σ 407.0k (39%)). That side-by-side was an internal A/B topick 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_windowon the harness-capabilities documentthe frontend fetches (from
model_catalog.py), so the denominator was already in thebrowser. 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):
After (exact-id lookup into the catalog that is already on the capabilities doc):
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-countedresent 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 windowis and that older messages get summarized as it fills.
Prop and type changes for reviewers:
ContextBudgetIndicatortakesmaxTokens: number | nullinstead ofmodel: string.ContextBudgetdroppedrunningSumTokens,runningSumPct, andperTurnTokens.useAgentModelKeyStatusnow also returnsharness(read fromagent.harness.kind).contextWindowForModelfrom@agenta/entities/workflow.Tests / notes
@agenta/entitiesbuilds clean; OSStsc --noEmitshows no new errors in the touchedfiles; ESLint and prettier pass.
runningSum/perTurnfields, so noother consumer changed.
context_window: null(e.g. theClaude
defaultalias). 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
"Context N% used", where N tracks the latest turn.
407k / 1M tokens) and the plain explanation.percent and bar rescale to the new denominator, confirming the catalog lookup rather than
a hardcoded number.
from the catalog) instead of a bare token count.
and 95% in
ContextBudgetIndicator(thresholds are>=0.75amber,>=0.9red).Previews
When context fills up