Skip to content

feat(webui): display context usage#1871

Open
Premsenareddy wants to merge 2 commits into
agentscope-ai:mainfrom
Premsenareddy:codex/context-length-indicator
Open

feat(webui): display context usage#1871
Premsenareddy wants to merge 2 commits into
agentscope-ai:mainfrom
Premsenareddy:codex/context-length-indicator

Conversation

@Premsenareddy

Copy link
Copy Markdown
Contributor

Summary

  • persist per-session context usage in AgentState, including current tokens, compression threshold, model window, and trigger ratio
  • refresh context usage during compression/model reasoning and publish it through the existing state_updated SSE path
  • add a compact Web UI context usage indicator in the chat toolbar, initialized from SessionRecord.state and updated live from SSE/model usage events

How the frontend stays updated

  • Initial value comes from the existing sessions response: session.state.context_usage
  • Real-time authoritative updates arrive through the existing /sessions/{id}/stream SSE channel as CustomEvent(name="state_updated") with context_usage included
  • During an active reply, MODEL_CALL_END updates the displayed current token count immediately; the final state_updated event reconciles it with the persisted backend estimate

Tests

  • .venv/bin/python -m pytest -p no:cacheprovider tests/compress_context_test.py tests/agent_basic_test.py tests/service_wakeup_dispatcher_test.py tests/service_inbox_middleware_test.py tests/service_team_tools_test.py tests/storage_redis_test.py -q
  • corepack pnpm --dir examples/web_ui/frontend build
  • corepack pnpm --dir examples/web_ui/frontend lint
  • Browser smoke: opened http://127.0.0.1:5173/chat and checked for console errors

Addresses #1845

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.

1 participant