You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Headless: emit per-step token usage in the AG-UI stream (desktop status bar) #1253
infer headless --format ag-ui only carries token usage in the terminal RUN_FINISHED event's result object, so any client that renders live usage stats stays stale for the whole run and then jumps in one step at the end. The desktop status bar (in, out, cached, Context %, cost) needs this stream to carry usage as the run progresses.
Emit a per-step usage CUSTOM event from aguiEncoder (internal/platform/render/agui.go), mirroring the established extension points (agent_status, background_tasks, queued_message):
value: the same stats object the RUN_FINISHED result already carries - inputTokens, outputTokens, cacheReadTokens, totalToolCalls, lastInputTokens, contextWindow, cost - as cumulative session totals.
Cadence: after each LLM step/turn completes, before the tool loop continues, so the numbers climb while tool calls run.
Desktop contract (already implemented)
backend/src/agent.rs maps the CUSTOM token_usage value onto AgentEvent::TokenUsage with the same fields the RUN_FINISHED result uses; a missing/non-object value falls through harmlessly.
The transcript reducer overwrites its running usage with each TokenUsage event, so the authoritative totals win.
All done. Final verification passed: tree clean, branch in sync with origin, PR viewable and ready for review.
Summary
Implemented per-step token usage emission in the AG-UI headless stream (issue #1253). RenderAGUI now publishes a CUSTOM event named token_usage after every LLM step by reusing sessionResult(model, repo) - the same builder that feeds the terminal RUN_FINISHED result - so mid-run and terminal values can never drift. Verified via code trace that the agent records usage (AddTokenUsage) and assistant tool calls in the conversation repo before the completion event publishes, so each snapshot is current when tools start running. Emission is suppressed for zero-request runs. Desktop side stays inert until this ships, per desktop#306's prepared parser.
Changes: emitTokenUsage in agui.go (mirrors the agent_status/background_tasks/queued_message extension points), wiring + docs comments in render.go, TestRenderAGUI_TokenUsageStreamsPerStep render test (one event per step, all seven value fields including contextWindow, none for zero-request runs), event documented in docs/ag-ui-output.md
RenderAGUI crossed the cyclop cap with the new branch; nolint-ed per repo convention for cohesive event switches
Checks: task precommit:run and full task test green; commit pushed to fix/issue-1253
skipped: nothing - value builder reused verbatim from RUN_FINISHED; add a per-turn delta event only if the desktop asks for incremental (not cumulative) values.
Activity
edenreich commentedon Sep 20, 2026
@infer Can you fix this? use /ponytail:ponytail
inference-gateway-maintainer commentedon Sep 20, 2026
Model:
ollama_cloud/glm-5.3-flash· View JobTodos
Pull Request
#1254
✅ Infer Result: Success
All done. Final verification passed: tree clean, branch in sync with origin, PR viewable and ready for review.
Summary
Implemented per-step token usage emission in the AG-UI headless stream (issue #1253).
RenderAGUInow publishes aCUSTOMevent namedtoken_usageafter every LLM step by reusingsessionResult(model, repo)- the same builder that feeds the terminalRUN_FINISHEDresult - so mid-run and terminal values can never drift. Verified via code trace that the agent records usage (AddTokenUsage) and assistant tool calls in the conversation repo before the completion event publishes, so each snapshot is current when tools start running. Emission is suppressed for zero-request runs. Desktop side stays inert until this ships, per desktop#306's prepared parser.emitTokenUsageinagui.go(mirrors theagent_status/background_tasks/queued_messageextension points), wiring + docs comments inrender.go,TestRenderAGUI_TokenUsageStreamsPerSteprender test (one event per step, all seven value fields includingcontextWindow, none for zero-request runs), event documented indocs/ag-ui-output.mdRenderAGUIcrossed the cyclop cap with the new branch; nolint-ed per repo convention for cohesive event switchestask precommit:runand fulltask testgreen; commit pushed tofix/issue-1253skipped: nothing - value builder reused verbatim from
RUN_FINISHED; add a per-turn delta event only if the desktop asks for incremental (not cumulative) values.Model:
ollama_cloud/glm-5.3-flash· Exit Code:0· Duration: 10m 10sTokens: 3,481,142 in · 40,813 out · 3,521,955 total (43 requests)
Tool calls: 64 total · 100% success rate
Traces
Stats
Triggered by edenreich · Infer Action · OSS
inference-gateway-releaser commentedon Sep 20, 2026
🎉 This issue has been resolved in version 0.205.0 🎉
The release is available on:
Your semantic-release bot 📦🚀