diff options
| author | Arun Isaac | 2026-04-18 02:38:59 +0100 |
|---|---|---|
| committer | Arun Isaac | 2026-04-20 00:23:35 +0100 |
| commit | 3d55d6ea5bbc437fb70e592db8a1d10fd5a5613b (patch) | |
| tree | 83e0cd513a10455cb5b27193667e5525bcc792c3 | |
| parent | 7715ec5d75316530b304014272497711d370c9e0 (diff) | |
| download | kaagum-3d55d6ea5bbc437fb70e592db8a1d10fd5a5613b.tar.gz kaagum-3d55d6ea5bbc437fb70e592db8a1d10fd5a5613b.tar.lz kaagum-3d55d6ea5bbc437fb70e592db8a1d10fd5a5613b.zip | |
Report per-turn token usage to client.
| -rw-r--r-- | kaagum/tea.scm | 19 |
1 files changed, 18 insertions, 1 deletions
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 |
