Skip to content

feat(weave): add cache token fields to LLM usage and cost schemas#6483

Closed
andrewtruong wants to merge 2 commits intomasterfrom
andrew/l2-cache-token-schema
Closed

feat(weave): add cache token fields to LLM usage and cost schemas#6483
andrewtruong wants to merge 2 commits intomasterfrom
andrew/l2-cache-token-schema

Conversation

@andrewtruong
Copy link
Copy Markdown
Collaborator

Summary

  • Add cache_read_input_tokens and cache_write_input_tokens to LLMUsageSchema TypedDict
  • Add cache_read_input_tokens_total_cost, cache_write_input_tokens_total_cost, cache_read_input_token_cost, cache_write_input_token_cost to LLMCostSchema
  • Add all cache fields to LLMAggregatedUsage BaseModel
  • Update usage_utils.py to extract, normalize (cache_creation_input_tokenscache_write_input_tokens), merge, and aggregate cache tokens through the call hierarchy

Context

This is Layer 2 of the cached token tracking feature. It extends the data model so the system can represent cached token counts flowing from provider SDKs (L1) and enables downstream cost calculation (L5) and query support (L6/L7).

Test plan

  • Existing usage aggregation tests pass unchanged
  • LLMAggregatedUsage serializes/deserializes with new fields defaulting to 0/None
  • Cache tokens from summary dicts are extracted and merged correctly in _extract_call_usage and _merge_usage

🤖 Generated with Claude Code

Add cache_read_input_tokens and cache_write_input_tokens to
LLMUsageSchema, LLMCostSchema, and LLMAggregatedUsage so the data model
can represent cached token counts and their costs.

Update usage_utils.py to extract, normalize (cache_creation_input_tokens
→ cache_write_input_tokens), merge, and aggregate the new fields through
the call hierarchy.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@w-b-hivemind
Copy link
Copy Markdown

w-b-hivemind Bot commented Mar 28, 2026

HiveMind Sessions

1 session · 2m · $0.77

Session Agent Duration Tokens Cost Lines
Conductor App Work Setup
fba61a57-d7c5-4e08-945d-7bea2a646e21
claude 2m 4.2K $0.77 +0 -0
Total 2m 4.2K $0.77 +0 -0

View all sessions in HiveMind →

Run claude --resume fba61a57-d7c5-4e08-945d-7bea2a646e21 to pickup where you left off.

@github-actions
Copy link
Copy Markdown
Contributor

This PR has been inactive for 14 days. It will be closed in 7 days unless there is new activity.

@github-actions github-actions Bot added the Stale label Apr 12, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant