WeKnora/internal
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
..
agent feat(agent): report and attribute per-turn LLM token usage 2026-08-24 10:36:19 +08:00
application fix(datasource): restore sync_deletions on the in-memory object after create 2026-08-21 16:37:05 +08:00
assets feat(assets): add ASR test audio file and embed it in the application 2026-04-02 21:27:27 +08:00
common feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
config fix(config): 补齐 WEKNORA_TENANT_ENABLE_CROSS_TENANT_ACCESS 的 env 读取 2026-08-10 19:40:09 +08:00
container feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
database feat(agent): report and attribute per-turn LLM token usage 2026-08-24 10:36:19 +08:00
datasource feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
errors refactor(terminology): rename user-facing tenant labels to workspace 2026-07-14 16:14:43 +08:00
event feat(agent): report and attribute per-turn LLM token usage 2026-08-24 10:36:19 +08:00
handler feat(agent): report and attribute per-turn LLM token usage 2026-08-24 10:36:19 +08:00
im feat(agent): report and attribute per-turn LLM token usage 2026-08-24 10:36:19 +08:00
infrastructure feat(docreader): add XMind outline parsing (#2713) 2026-08-20 19:49:48 +08:00
logger refactor(context): replace middleware.EmbedChannelContextKey with types.EmbedChannelContextKey 2026-08-13 18:00:02 +08:00
mcp fix(security): harden outbound URL SSRF protection (#2626) 2026-08-10 13:24:14 +08:00
middleware refactor(context): replace middleware.EmbedChannelContextKey with types.EmbedChannelContextKey 2026-08-13 18:00:02 +08:00
modelcontext feat(memory): introduce long-term memory feature with i18n updates 2026-08-13 18:00:02 +08:00
models feat(agent): report and attribute per-turn LLM token usage 2026-08-24 10:36:19 +08:00
ratelimit feat(embed): add backend embed channels with auth and rate limiting (#1657) 2026-06-12 23:10:39 +08:00
router feat(system-admin): add endpoint for creating users (#2722) 2026-08-20 19:51:10 +08:00
runtime fix(redis): harden TLS tests and surface TLS config at startup 2026-07-06 23:04:52 +08:00
sandbox feat(sandbox): enhance logging for sandbox operations and error diagnostics 2026-08-12 10:53:46 +08:00
searchutil fix(retrieval): 分段中删除的图片不再被检索到 2026-08-20 12:01:28 +08:00
storageallowlist fix(storage): align default provider fallback with STORAGE_ALLOW_LIST 2026-07-15 11:05:00 +08:00
storageurl fix(api): address resource_urls review follow-ups 2026-08-05 14:42:51 +08:00
stream feat(redis): support TLS for Redis connections (#1930) 2026-07-06 23:02:02 +08:00
tracing/langfuse feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
types feat(agent): report and attribute per-turn LLM token usage 2026-08-24 10:36:19 +08:00
utils feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00