Skip to content

[GUI] The engine reports its reasoning tokens, and the row shows them exactly - #4502

Closed
xvcezrqpbxtpzblrt wants to merge 2 commits into
Niko1221:mainfrom
xvcezrqpbxtpzblrt:gui/reasoning-exact-027
Closed

xvcezrqpbxtpzblrt wants to merge 2 commits into
Niko1221:mainfrom
xvcezrqpbxtpzblrt:gui/reasoning-exact-027

Conversation

@xvcezrqpbxtpzblrt

Copy link
Copy Markdown
Contributor

Problem

The thinking row had to estimate its token count (marked ≈) because the chat usage the engine returns carries only prompt/completion/total. The engine already counts the thinking tokens internally for the Responses API (reasoning_tokens in its done event) but the OpenAI-compatible usage object had no completion_tokens_details.reasoning_tokens.

Result

  • The engine's chat usage now carries the standard field, for streamed and non-streamed replies: "completion_tokens_details": {"reasoning_tokens": N}.
  • The app reads it (host usage frame, message, thinking row) and shows the exact number without ≈ when it is present; the estimate remains the fallback when a provider does not send it.
  • The count is summed over the turn's requests, like the reasoning text itself.

Validation

  • Direct call to the running engine, non-streamed: "completion_tokens_details": {"reasoning_tokens": 16} next to prompt 54 / completion 16.
  • Same call streamed with stream_options.include_usage: the final usage carries "completion_tokens_details": {"reasoning_tokens": 19}.
  • node --test tests/agent-events.test.mjs → the count is summed over two usage frames (3 + 4 = 7) and the terminal frame has none when the provider sends none.
  • npm run typecheck clean.

Limits

  • On this computer the app still shows ≈: the pinned Harness (0.2.1-alpha.3) builds its usage frame in dsh-llm-pi-ai's mapUsage, which copies input/output/total/cache only and drops the provider's reasoning count before the app sees it. Its own TokenUsage type has the field, but this version never fills it. The engine and app sides are ready; the exact number appears once the Harness forwards it.
  • The estimate stays for API models whose providers do not send completion_tokens_details.
  • Based on [GUI] The thinking row shows live time and tokens, and counts only the thinking #4471 (the live thinking row); that one should merge first.

@xvcezrqpbxtpzblrt

Copy link
Copy Markdown
Contributor Author

Superseded by #4606, which carries this change with the rest of the 0.2.7 branch. Closing so the review has one place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant