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
[REFACTOR] Unify chat and headless token accumulation #835
Two independent token accumulators read the same response.Usage:
Chat funnels through AgentServiceImpl.storeIterationMetrics (internal/agent/agent.go:724), storing domain.ChatMetrics per request with a tokenizer polyfill when providers omit usage.
Headless re-implements inline counters (cmd/agent.go:108-109, accumulation at :679-682, plus its own AddTokenUsage at :708).
Cost math can drift between modes, and any metrics recorder must tap two places.
Design
Extract one shared usage accumulator (likely alongside domain.ChatMetrics) that both AgentServiceImpl and the headless executor feed; the headless executor drops its ad-hoc fields. Keep the tokenizer polyfill in the shared path so both modes estimate identically when usage is missing from the stream.
Acceptance criteria
Single accumulation code path; for identical mock scenarios, headless totals equal chat totals (assertable via the existing usage-report scenario, 142 tokens)
/cost and the headless final stats read from the same source
Dependencies
None. Prerequisite for the metrics recorder issue.
Activity
refactor(agent): unify chat and headless token accumulation (#860)
inference-gateway-releaser commentedon Jul 11, 2026
🎉 This issue has been resolved in version 0.142.2 🎉
The release is available on:
Your semantic-release bot 📦🚀
feat(telemetry): OpenTelemetry recorder, `infer stats`, and OTLP expo…