Skip to content

Commit d298754

Browse files
committed
docstring cleanup
1 parent 7e43c4b commit d298754

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

src/agents/usage.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66

77
@dataclass
88
class RequestUsage:
9-
"""Usage details for a single API request.
10-
11-
This is useful for cost calculation when different pricing rates apply based on
12-
per-request token counts (e.g., Anthropic's 200K token threshold pricing).
13-
"""
9+
"""Usage details for a single API request."""
1410

1511
input_tokens: int
1612
"""Input tokens for this individual request."""
@@ -52,29 +48,22 @@ class Usage:
5248
"""Total tokens sent and received, across all requests."""
5349

5450
request_usage_entries: list[RequestUsage] = field(default_factory=list)
55-
"""List of individual request usage details for accurate per-request cost calculation.
56-
57-
This field preserves the token counts for each individual API request made during a run.
58-
This is particularly useful for providers like Anthropic that have different pricing
59-
tiers based on per-request token counts (e.g., different rates for requests with more
60-
or fewer than 200K tokens).
51+
"""List of RequestUsage entries for accurate per-request cost calculation.
6152
6253
Each call to `add()` automatically creates an entry in this list if the added usage
6354
represents a new request (i.e., has non-zero tokens).
6455
6556
Example:
6657
For a run that makes 3 API calls with 100K, 150K, and 80K input tokens each,
6758
the aggregated `input_tokens` would be 330K, but `request_usage_entries` would
68-
preserve the [100K, 150K, 80K] breakdown needed for accurate cost calculation.
59+
preserve the [100K, 150K, 80K] breakdown, which could be helpful for detailed
60+
cost calculation or context window management.
6961
"""
7062

7163
def add(self, other: "Usage") -> None:
7264
"""Add another Usage object to this one, aggregating all fields.
7365
74-
This method automatically preserves individual request details for accurate
75-
cost calculation. When adding a Usage object that represents a single request
76-
(requests=1), it creates an RequestUsage entry to preserve the
77-
per-request token breakdown.
66+
This method automatically preserves request_usage_entries.
7867
7968
Args:
8069
other: The Usage object to add to this one.
@@ -93,7 +82,7 @@ def add(self, other: "Usage") -> None:
9382
+ other.output_tokens_details.reasoning_tokens
9483
)
9584

96-
# Automatically preserve individual request details for accurate cost calculation.
85+
# Automatically preserve request_usage_entries.
9786
# If the other Usage represents a single request with tokens, record it.
9887
if other.requests == 1 and other.total_tokens > 0:
9988
individual_usage = RequestUsage(

tests/test_usage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def test_usage_request_usage_entries_default_empty():
212212

213213

214214
def test_anthropic_cost_calculation_scenario():
215-
"""Test a realistic scenario for Anthropic cost calculation with 200K token thresholds."""
215+
"""Test a realistic scenario for Sonnet 4.5 cost calculation with 200K token thresholds."""
216216
# Simulate 3 API calls: 100K, 150K, and 80K input tokens each
217217
# None exceed 200K, so they should all use the lower pricing tier
218218

0 commit comments

Comments
 (0)