feat(status): add context window display and fix usage token tracking#9750
Open
WqyJh wants to merge 2 commits into
Open
feat(status): add context window display and fix usage token tracking#9750WqyJh wants to merge 2 commits into
WqyJh wants to merge 2 commits into
Conversation
added 2 commits
April 14, 2026 20:39
The GatewayStreamConsumer was not passing reply_to when sending the first streamed message, so platform adapters that support reply/quoting (e.g. Feishu) could not reference the user's original message. Changes: - Add reply_to parameter to GatewayStreamConsumer.__init__ - Pass reply_to on first message send in _send_or_edit() - Pass event_message_id as reply_to when creating the consumer in _run_agent()
- Fix reasoning_tokens extraction: move into per-API-format branches (Anthropic reads output_tokens_details, OpenAI reads completion_tokens_details) - Add compression_count to SessionEntry (persisted to sessions.json) - Pass input/output/total tokens and compression_count through update_session - Add context window line to /status: 📚 Context: 134k/1M (13%) · 🧹 Compactions: 0
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.
Changes
1. Fix
reasoning_tokensextraction (agent/usage_pricing.py)normalize_usage()was readingoutput_tokens_details(Anthropic format) for ALL API formatscompletion_tokens_detailsinstead, soreasoning_tokenswas always 02. Persist token stats to session (
gateway/session.py)SessionEntrynow trackscompression_count(persisted to sessions.json)update_session()acceptsinput_tokens,output_tokens,total_tokens,compression_countand accumulates them3. Show context window in
/status(gateway/run.py)DEFAULT_CONTEXT_LENGTHS(no network calls)last_prompt_tokensfrom the session for current usage4. Wire up compression count (
run_agent.py)compression_countfromContextCompressorupdate_session()Test