agent-zero/plugins/_context_window/api/context_window.py
Alessandro f8c96860c2
Some checks are pending
Build And Publish Docker Images / plan (push) Waiting to run
Build And Publish Docker Images / build (push) Blocked by required conditions
Add context window usage indicator
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.
2026-08-23 06:08:41 +02:00

18 lines
821 B
Python

from helpers.api import ApiHandler, Input, Output, Request
from plugins._context_window.helpers.usage import usage_snapshot
from plugins._model_config.helpers.model_config import get_chat_model_config
class ContextWindow(ApiHandler):
async def process(self, input: Input, request: Request) -> Output:
context = self.use_context(str(input.get("context") or ""))
agent = context.streaming_agent or context.agent0
window = agent.get_data(agent.DATA_NAME_CTX_WINDOW)
window = window if isinstance(window, dict) else {}
config = get_chat_model_config(agent)
return {
"tokens": max(int(window.get("tokens") or 0), 0),
"context_window": max(int(config.get("ctx_length") or 0), 0),
"usage": usage_snapshot(window.get("usage")),
}