Skip to content

fix(render): carry session stats in the AG-UI RUN_FINISHED result - #1187

Merged
edenreich merged 1 commit into
mainfrom
fix/issue-1186
Sep 12, 2026
Merged

edenreich merged 1 commit into
mainfrom
fix/issue-1186

Conversation

@inference-gateway-maintainer

Copy link
Copy Markdown
Contributor

Resolves #1186

Summary

RUN_FINISHED now carries the per-session token, cost, and tool-call totals in its result, as docs/ag-ui-output.md already promised. RenderAGUI receives the conversation repository and reads the same stats RenderJSON reports in its session_stats line, so AG-UI consumers (the desktop sidecar, inference-gateway/desktop#216) see real usage instead of zeros.

Changes

  • RenderAGUI now takes the conversation repository; after a successful run it attaches sessionResult to the terminal RUN_FINISHED through the AG-UI SDK's WithResult option.
  • result keys: inputTokens, outputTokens, cacheReadTokens, totalToolCalls (counted from the session's assistant messages), cost, lastInputTokens, contextWindow (omitted when the model's window is unknown).
  • Gated exactly like RenderJSON: a run with no model requests (e.g. a shortcut answer) emits RUN_FINISHED without result.
  • Both call sites updated: headless renderStream and the browser extension bridge (which now passes its repo, so the desktop panel's AG-UI path benefits too).
  • render_test.go: TestRenderAGUI_RunFinishedCarriesSessionStats asserts every field is present and non-zero for a run with at least one request, plus the zero-request case; docs/ag-ui-output.md documents the exact key names.

Affected repos

  • inference-gateway/desktop: parser can now consume result (desktop#216, desktop#217, desktop#218); follow-up tracking issue filed there.

RenderAGUI now receives the conversation repository and attaches the per-session totals (inputTokens, outputTokens, cacheReadTokens, totalToolCalls, cost, lastInputTokens, contextWindow) to RUN_FINISHED.result, mirroring RenderJSON's session_stats line. A run with no model requests emits no result, matching RenderJSON's gating.
@inference-gateway-maintainer
inference-gateway-maintainer Bot marked this pull request as ready for review September 12, 2026 16:45
@inference-gateway-maintainer
inference-gateway-maintainer Bot requested a review from a team as a code owner September 12, 2026 16:45
edenreich added a commit to inference-gateway/desktop that referenced this pull request Sep 12, 2026
The CLI (inference-gateway/cli#1187) puts the stats under result, not
stats, and the totals are cumulative for the whole session, so the
reducer now replaces the conversation's usage instead of adding to it.
@edenreich
edenreich merged commit baaf16a into main Sep 12, 2026
1 check passed
@edenreich
edenreich deleted the fix/issue-1186 branch September 12, 2026 16:55
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.190.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Sep 12, 2026
edenreich added a commit to inference-gateway/desktop that referenced this pull request Sep 12, 2026
…and tools count (#216)

* feat(status-bar): mirror CLI status bar with per-conversation tokens and tools count

Fold TokenReadout into StatusBar as one dim, dot-separated row (Tools, in,
out, cached, tool calls). Token usage now lives in the per-conversation
chat reducer so it switches with the active chat and drops on delete. The
tools list is fetched once the CLI is ready (and after Restart CLI) instead
of lazily on the !! picker. Settings gets a Show status bar checkbox backed
by chat.status_bar.enabled in the CLI config, so one toggle drives both.

Closes #213

* Apply suggestion from @edenreich

* fix(status-bar): read session totals from RUN_FINISHED result

The CLI (inference-gateway/cli#1187) puts the stats under result, not
stats, and the totals are cumulative for the whole session, so the
reducer now replaces the conversation's usage instead of adding to it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Include session token stats in the AG-UI RUN_FINISHED event

1 participant