feat: add $usage field to adapter protocol #80

Merged
xiaomo merged 1 commits from feat/74-usage-in-protocol into main 2026-06-04 22:14:13 +00:00
Owner

What

Add Usage type and $usage field throughout the adapter protocol for token usage reporting.

Why

Eval framework (#34) needs per-step token consumption data. This is the foundation — adapters currently return null, real implementations in #76/#77.

Changes

  • protocol/types.tsUsage type, added to StepRecord + StepEntry
  • protocol/schemas.tsusage in STEP_NODE_SCHEMA (not required, backward compatible)
  • util-agent/types.tsusage in AgentRunResult + AdapterOutput
  • util-agent/run.ts — threaded through writeStepNodepersistStepcreateAgent
  • agent-mock / agent-hermes / agent-claude-code / agent-builtin — return usage: null
  • Tests updated: step-timing, step-show-json, protocol types

Ref

Fixes #74
Refs #68

## What Add `Usage` type and `$usage` field throughout the adapter protocol for token usage reporting. ## Why Eval framework (#34) needs per-step token consumption data. This is the foundation — adapters currently return `null`, real implementations in #76/#77. ## Changes - `protocol/types.ts` — `Usage` type, added to `StepRecord` + `StepEntry` - `protocol/schemas.ts` — `usage` in `STEP_NODE_SCHEMA` (not required, backward compatible) - `util-agent/types.ts` — `usage` in `AgentRunResult` + `AdapterOutput` - `util-agent/run.ts` — threaded through `writeStepNode` → `persistStep` → `createAgent` - `agent-mock` / `agent-hermes` / `agent-claude-code` / `agent-builtin` — return `usage: null` - Tests updated: `step-timing`, `step-show-json`, `protocol types` ## Ref Fixes #74 Refs #68
xiaoju added 1 commit 2026-06-04 15:46:39 +00:00
feat: add $usage field to adapter protocol
CI / check (pull_request) Successful in 2m28s
99f40c2488
- Add Usage type to protocol (turns, inputTokens, outputTokens, duration)
- Add usage to StepRecord, StepNodePayload, StepEntry, STEP_NODE_SCHEMA
- Thread usage through util-agent extract pipeline (writeStepNode → persistStep → createAgent)
- All adapters return usage: null as placeholder (mock, hermes, claude-code, builtin)
- 746 tests pass, no breaking changes (usage not in schema required array)

Fixes #74
Refs #68
xiaomo approved these changes 2026-06-04 22:14:12 +00:00
xiaomo left a comment
Owner

LGTM Usage 类型设计合理,schema anyOf null 向后兼容,全链路 threaded through。eval 基础到位。

LGTM ✅ Usage 类型设计合理,schema anyOf null 向后兼容,全链路 threaded through。eval 基础到位。
xiaomo merged commit 172c232e61 into main 2026-06-04 22:14:13 +00:00
xiaomo deleted branch feat/74-usage-in-protocol 2026-06-04 22:14:13 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shazhou/united-workforce#80