feat(widget): context-usage meter backed by the agent manager - #58
Open
AmitAvital1 wants to merge 1 commit into
Open
feat(widget): context-usage meter backed by the agent manager#58AmitAvital1 wants to merge 1 commit into
AmitAvital1 wants to merge 1 commit into
Conversation
Surface per-conversation token usage against the configured
context_max_tokens budget so users see how full the context is before
they hit the 429 wall.
Backend (source of truth):
- ContextUsage domain value object with a ContextSeverity StrEnum and a
from_totals factory that owns the warning/critical thresholds
- GET /conversations/{id}/usage returns used_tokens, max_tokens, percent
and severity; ConversationService.usage sums stored token counts
- schema reuses the domain ContextSeverity enum (no duplicated literals)
Widget (stateless renderer):
- AgentChatClient.getUsage + useConversation.loadUsage fetch usage on
open and after each turn; no client-side token math or thresholds
- ContextMeter ring (severity-coloured, hover popover) shown only when a
budget is set; hidden and non-breaking against backends without /usage
Also: neutral demo copy and a documented CONTEXT_MAX_TOKENS in the
starter example.
Tests: usage endpoint, severity thresholds, and two widget e2e cases.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
|
PR #58 The implementation is clean, but I think the current naming is misleading. The backend calculates usage by summing We should either:
I would prefer resolving this before merging, because the UI currently presents the value as Also, should the critical threshold use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack 2/4 · base:
feat/widget-fluent-ui(#57)Adds a context-usage meter (assistant-ui ContextDisplay) to the widget. All computation is on the backend — the agent manager exposes
GET /conversations/{id}/usagereturning used/max tokens, percent, and aContextSeverity(normal/warning/critical) as the single source of truth. The FE only renders; it does no token math. Severity is aStrEnumreused across domain + schema so thresholds live in one place.Verified:
make check(Python) + widget typecheck/e2e green.🤖 Generated with Claude Code