WeKnora/internal/agent
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
..
approval refactor(terminology): rename user-facing tenant labels to workspace 2026-07-14 16:14:43 +08:00
memory feat(llm): add prompt-cache observability and wiki cache-friendly prompts 2026-07-23 19:17:30 +08:00
skills feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
token feat(agent): enhance message consolidation and context management 2026-03-25 22:08:29 +08:00
tools perf(agent): make knowledge_search MMR selection incremental 2026-08-20 15:44:32 +08:00
act.go feat(memory): introduce long-term memory feature with i18n updates 2026-08-13 18:00:02 +08:00
const.go feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
const_test.go feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
engine.go feat(agent): report and attribute per-turn LLM token usage 2026-08-24 10:36:19 +08:00
engine_image_test.go feat: auto-describe MCP tool result images via VLM 2026-03-25 21:38:15 +08:00
engine_memory_test.go feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
engine_test.go refactor(agent): introduce modelcontext registry and fix handle-codec bugs 2026-07-27 11:05:43 +08:00
finalize.go feat(agent): report and attribute per-turn LLM token usage 2026-08-24 10:36:19 +08:00
finalize_image_requirement_test.go fix(chat): enforce retrieved image output in answers 2026-07-15 18:10:31 +08:00
image_requirement.go fix(chat): enforce retrieved image output in answers 2026-07-15 18:10:31 +08:00
langfuse_test.go refactor(agent): introduce modelcontext registry and fix handle-codec bugs 2026-07-27 11:05:43 +08:00
observe.go feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
observe_test.go feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
prompts.go feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
prompts_shell_test.go feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
prompts_wiki.go Remove redundant Wiki operation log 2026-07-28 11:18:33 +08:00
prompts_wiki_test.go refactor(agent): introduce modelcontext registry and fix handle-codec bugs 2026-07-27 11:05:43 +08:00
think.go refactor(agent): introduce modelcontext registry and fix handle-codec bugs 2026-07-27 11:05:43 +08:00
turn_usage_test.go feat(agent): report and attribute per-turn LLM token usage 2026-08-24 10:36:19 +08:00