fix(insights): persist token usage for non-CLI sessions

This commit is contained in:
kshitijk4poor
2026-04-02 11:15:16 +05:30
committed by Teknium
parent 585855d2ca
commit 20441cf2c8
6 changed files with 73 additions and 112 deletions

View File

@@ -2804,20 +2804,12 @@ class GatewayRunner:
skip_db=agent_persisted,
)
# Update session with actual prompt token count and model from the agent
# Token counts and model are now persisted by the agent directly.
# Keep only last_prompt_tokens here for context-window tracking and
# compression decisions.
self.session_store.update_session(
session_entry.session_key,
input_tokens=agent_result.get("input_tokens", 0),
output_tokens=agent_result.get("output_tokens", 0),
cache_read_tokens=agent_result.get("cache_read_tokens", 0),
cache_write_tokens=agent_result.get("cache_write_tokens", 0),
last_prompt_tokens=agent_result.get("last_prompt_tokens", 0),
model=agent_result.get("model"),
estimated_cost_usd=agent_result.get("estimated_cost_usd"),
cost_status=agent_result.get("cost_status"),
cost_source=agent_result.get("cost_source"),
provider=agent_result.get("provider"),
base_url=agent_result.get("base_url"),
)
# Auto voice reply: send TTS audio before the text response