From 3d55d6ea5bbc437fb70e592db8a1d10fd5a5613b Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sat, 18 Apr 2026 02:38:59 +0100 Subject: Report per-turn token usage to client. --- kaagum/tea.scm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/kaagum/tea.scm b/kaagum/tea.scm index f50a275..3421fe6 100644 --- a/kaagum/tea.scm +++ b/kaagum/tea.scm @@ -744,7 +744,24 @@ ending the turn of session with @var{session-id}." ("id" . ,(focus state-client-request-id state)) ("result" - ("stopReason" . "end_turn")))))))) + ("stopReason" . "end_turn") + ;; Report usage if it is non-zero. Usage can + ;; be zero if turn was for a slash command. + ,@(if (any (negate zero?) + (list input-tokens + output-tokens + thought-tokens + cache-read-tokens + cache-write-tokens)) + `(("usage" + ("totalTokens" . ,(+ input-tokens + output-tokens)) + ("inputTokens" . ,input-tokens) + ("outputTokens" . ,output-tokens) + ("thoughtTokens" . ,thought-tokens) + ("cachedReadTokens" . ,cache-read-tokens) + ("cachedWriteTokens" . ,cache-write-tokens))) + '())))))))) (define (next-state-llm-response state response tools) "Given current @var{state} and a new LLM @var{response}, return the next state -- cgit 1.4.1