sdk-python
sdk-python copied to clipboard
[FEATURE] Include compaction calls in token usage
Human Overview
Need to add the token usage for compaction to the token usage tracked by the Strands SDK.
SDK Language
Both / Not language-specific
Problem Statement
Model.compact() calls the model outside the agent loop, for both the client-side default and native compaction. Anthropic reports native compaction usage in usage.iterations. Neither shows up in agent metrics or traces, so users can't see what summarization costs. The 0022 evals had to add it up by hand.
Proposed Solution
- Add each
compact()call's usage to the agent's accumulated usage, includingusage.iterationsfor native compaction. - Emit a span for each compaction call. Follow the convention in #4618.
- Design 0022 doesn't cover usage accounting yet. Add a short section to it.
Use Case
A user compares the cost of compacting often against compacting rarely.
Additional Context
- Depends on: #5464, #5401
- Design:
team/designs/0022-server-side-compaction-support.md(#5242)