mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-08-23 23:37:05 +00:00
Add a bundled context-window plugin with a composer usage ring, responsive breakdown popover, token counts, percentages, and free-space reporting. Keep accounting plugin-owned, reuse existing history token counts, cache bounded prompt fragments by content, and expose independent mobile and desktop visibility controls.
2 KiB
2 KiB
Context Window Plugin DOX
Purpose
- Own context-window token accounting, the usage API, the composer indicator, its popover, and its Interface visibility row.
Ownership
helpers/usage.pyowns per-prompt bucket measurement and reconciliation.extensions/python/records prompt parts at their source extension points.api/context_window.pyexposes the active chat's token usage and effective model limit without returning prompt content.webui/andextensions/webui/own the Alpine store, indicator, popover, model-override refresh, and Interface visibility row.
Local Contracts
- The six used-token buckets are
messages,system_tools,skills,mcp_tools,system_prompt, andextras. - Tools, MCP tools, and the available-skills catalog are measured from their extensible prompt builders, never inferred from rendered headings.
- Loaded skill instructions are removed from Messages and added to Skills.
- Protocol and prompt extras are reported together as Extras.
- Messages reuse the history record token ledger; independently rendered fragments use a bounded, content-addressed, runtime-only cache.
- Bucket totals reconcile to the already-stored prompt token total; the unclaimed remainder belongs to System prompt.
- Older chats without a stored breakdown show the explanatory empty state.
_model_configsupplies the effective model limit and themodel-context-strip-endWebUI slot; it does not own this feature's state.- The
contextWindowUsageInterface setting defaults to visible on mobile and desktop.
Work Guidance
- Keep prompt accounting out of rendered-text heuristics.
- Keep the API response limited to counts needed by the UI.
- Preserve the upward, right-aligned popover geometry used beside the model and profile selectors.
Verification
- Run
conda run -n a0 pytest plugins/_context_window/tests. - Smoke-test the indicator, popover, chat switching, post-run refresh, and mobile/desktop visibility against the live WebUI.
Child DOX Index
No child DOX files.