WeKnora/internal/models
ochan.kwon 894cbec48a feat(agent): report and attribute per-turn LLM token usage
Accumulate token usage across every LLM round of an agent turn and
expose the aggregate everywhere a turn is observable:

- AgentState.TurnUsage accumulates each round's reported usage,
  including the final-answer synthesis call; TokenUsage.Accumulate
  keeps the cache counters as prompt subsets and recomputes the
  combined cache status (unsupported survives only while every call
  was itself unsupported).
- The agent completion event carries the aggregate, and the complete
  stream event exposes it both as data.usage and as a typed
  StreamEvent.Usage that buildStreamResponse promotes into the
  previously-unused StreamResponse.Usage wire field.
- The assistant message persists it as a nullable usage column on
  both migration targets (postgres 000085 jsonb, sqlite 000012 text),
  for web and IM channels alike, so history reads still carry the
  turn's cost after the live stream is gone.
- "[LLM Usage]" log lines gain ", session_id=..., principal=type:id"
  when the context carries them; calls outside sessions stay
  byte-identical.

Usage from failed retry attempts is not accumulated: the per-call
usage log remains the ground truth, while the turn aggregate serves
as the operational signal.
2026-08-24 10:36:19 +08:00
..
asr fix(security): harden model client redirects 2026-07-02 19:15:46 +08:00
chat feat(agent): report and attribute per-turn LLM token usage 2026-08-24 10:36:19 +08:00
embedding fix(embedding): validate WeKnoraCloud response indexes 2026-08-11 16:59:48 +08:00
limiter feat(system): expose model concurrency stats on runtime queues dashboard 2026-07-11 07:17:28 +08:00
provider feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
rerank feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
utils feat: integrate ChatBot provider and docreader 2026-04-13 17:47:24 +08:00
vlm feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00