11from openai .types .responses .response_usage import InputTokensDetails , OutputTokensDetails
22
3- from agents .usage import IndividualRequestUsage , Usage
3+ from agents .usage import RequestUsage , Usage
44
55
66def test_usage_add_aggregates_all_fields ():
@@ -52,25 +52,25 @@ def test_usage_add_aggregates_with_none_values():
5252 assert u1 .output_tokens_details .reasoning_tokens == 6
5353
5454
55- def test_individual_request_usage_creation ():
56- """Test that IndividualRequestUsage is created correctly."""
57- individual = IndividualRequestUsage (
55+ def test_request_usage_creation ():
56+ """Test that RequestUsage is created correctly."""
57+ request_usage = RequestUsage (
5858 input_tokens = 100 ,
5959 output_tokens = 200 ,
6060 total_tokens = 300 ,
6161 input_tokens_details = InputTokensDetails (cached_tokens = 10 ),
6262 output_tokens_details = OutputTokensDetails (reasoning_tokens = 20 ),
6363 )
6464
65- assert individual .input_tokens == 100
66- assert individual .output_tokens == 200
67- assert individual .total_tokens == 300
68- assert individual .input_tokens_details .cached_tokens == 10
69- assert individual .output_tokens_details .reasoning_tokens == 20
65+ assert request_usage .input_tokens == 100
66+ assert request_usage .output_tokens == 200
67+ assert request_usage .total_tokens == 300
68+ assert request_usage .input_tokens_details .cached_tokens == 10
69+ assert request_usage .output_tokens_details .reasoning_tokens == 20
7070
7171
7272def test_usage_add_preserves_single_request ():
73- """Test that adding a single request Usage creates an IndividualRequestUsage entry."""
73+ """Test that adding a single request Usage creates an RequestUsage entry."""
7474 u1 = Usage ()
7575 u2 = Usage (
7676 requests = 1 ,
@@ -83,18 +83,18 @@ def test_usage_add_preserves_single_request():
8383
8484 u1 .add (u2 )
8585
86- # Should preserve the individual request details
87- assert len (u1 .individual_requests ) == 1
88- individual = u1 .individual_requests [0 ]
89- assert individual .input_tokens == 100
90- assert individual .output_tokens == 200
91- assert individual .total_tokens == 300
92- assert individual .input_tokens_details .cached_tokens == 10
93- assert individual .output_tokens_details .reasoning_tokens == 20
86+ # Should preserve the request usage details
87+ assert len (u1 .request_usage_entries ) == 1
88+ request_usage = u1 .request_usage_entries [0 ]
89+ assert request_usage .input_tokens == 100
90+ assert request_usage .output_tokens == 200
91+ assert request_usage .total_tokens == 300
92+ assert request_usage .input_tokens_details .cached_tokens == 10
93+ assert request_usage .output_tokens_details .reasoning_tokens == 20
9494
9595
9696def test_usage_add_ignores_zero_token_requests ():
97- """Test that zero-token requests don't create IndividualRequestUsage entries ."""
97+ """Test that zero-token requests don't create request_usage_entries ."""
9898 u1 = Usage ()
9999 u2 = Usage (
100100 requests = 1 ,
@@ -107,12 +107,12 @@ def test_usage_add_ignores_zero_token_requests():
107107
108108 u1 .add (u2 )
109109
110- # Should not create an individual request entry for zero tokens
111- assert len (u1 .individual_requests ) == 0
110+ # Should not create a request_usage_entry for zero tokens
111+ assert len (u1 .request_usage_entries ) == 0
112112
113113
114114def test_usage_add_ignores_multi_request_usage ():
115- """Test that multi-request Usage objects don't create IndividualRequestUsage entries ."""
115+ """Test that multi-request Usage objects don't create request_usage_entries ."""
116116 u1 = Usage ()
117117 u2 = Usage (
118118 requests = 3 , # Multiple requests
@@ -125,13 +125,13 @@ def test_usage_add_ignores_multi_request_usage():
125125
126126 u1 .add (u2 )
127127
128- # Should not create an individual request entry for multi-request usage
129- assert len (u1 .individual_requests ) == 0
128+ # Should not create a request usage entry for multi-request usage
129+ assert len (u1 .request_usage_entries ) == 0
130130
131131
132- def test_usage_add_merges_existing_individual_requests ():
133- """Test that existing individual_requests are merged when adding Usage objects."""
134- # Create first usage with individual requests
132+ def test_usage_add_merges_existing_request_usage_entries ():
133+ """Test that existing request_usage_entries are merged when adding Usage objects."""
134+ # Create first usage with request_usage_entries
135135 u1 = Usage ()
136136 u2 = Usage (
137137 requests = 1 ,
@@ -143,7 +143,7 @@ def test_usage_add_merges_existing_individual_requests():
143143 )
144144 u1 .add (u2 )
145145
146- # Create second usage with individual requests
146+ # Create second usage with request_usage_entries
147147 u3 = Usage (
148148 requests = 1 ,
149149 input_tokens = 50 ,
@@ -155,27 +155,27 @@ def test_usage_add_merges_existing_individual_requests():
155155
156156 u1 .add (u3 )
157157
158- # Should have both individual requests
159- assert len (u1 .individual_requests ) == 2
158+ # Should have both request_usage_entries
159+ assert len (u1 .request_usage_entries ) == 2
160160
161161 # First request
162- first = u1 .individual_requests [0 ]
162+ first = u1 .request_usage_entries [0 ]
163163 assert first .input_tokens == 100
164164 assert first .output_tokens == 200
165165 assert first .total_tokens == 300
166166
167167 # Second request
168- second = u1 .individual_requests [1 ]
168+ second = u1 .request_usage_entries [1 ]
169169 assert second .input_tokens == 50
170170 assert second .output_tokens == 75
171171 assert second .total_tokens == 125
172172
173173
174- def test_usage_add_with_pre_existing_individual_requests ():
175- """Test adding Usage objects that already have individual_requests ."""
174+ def test_usage_add_with_pre_existing_request_usage_entries ():
175+ """Test adding Usage objects that already have request_usage_entries ."""
176176 u1 = Usage ()
177177
178- # Create a usage with individual requests
178+ # Create a usage with request_usage_entries
179179 u2 = Usage (
180180 requests = 1 ,
181181 input_tokens = 100 ,
@@ -186,7 +186,7 @@ def test_usage_add_with_pre_existing_individual_requests():
186186 )
187187 u1 .add (u2 )
188188
189- # Create another usage with individual requests
189+ # Create another usage with request_usage_entries
190190 u3 = Usage (
191191 requests = 1 ,
192192 input_tokens = 50 ,
@@ -199,16 +199,16 @@ def test_usage_add_with_pre_existing_individual_requests():
199199 # Add u3 to u1
200200 u1 .add (u3 )
201201
202- # Should have both individual requests
203- assert len (u1 .individual_requests ) == 2
204- assert u1 .individual_requests [0 ].input_tokens == 100
205- assert u1 .individual_requests [1 ].input_tokens == 50
202+ # Should have both request_usage_entries
203+ assert len (u1 .request_usage_entries ) == 2
204+ assert u1 .request_usage_entries [0 ].input_tokens == 100
205+ assert u1 .request_usage_entries [1 ].input_tokens == 50
206206
207207
208- def test_usage_individual_requests_default_empty ():
209- """Test that individual_requests defaults to an empty list."""
208+ def test_usage_request_usage_entries_default_empty ():
209+ """Test that request_usage_entries defaults to an empty list."""
210210 u = Usage ()
211- assert u .individual_requests == []
211+ assert u .request_usage_entries == []
212212
213213
214214def test_anthropic_cost_calculation_scenario ():
@@ -257,13 +257,13 @@ def test_anthropic_cost_calculation_scenario():
257257 assert usage .output_tokens == 165_000 # 50K + 75K + 40K
258258 assert usage .total_tokens == 495_000 # 150K + 225K + 120K
259259
260- # Verify individual request preservation
261- assert len (usage .individual_requests ) == 3
262- assert usage .individual_requests [0 ].input_tokens == 100_000
263- assert usage .individual_requests [1 ].input_tokens == 150_000
264- assert usage .individual_requests [2 ].input_tokens == 80_000
260+ # Verify request_usage_entries preservation
261+ assert len (usage .request_usage_entries ) == 3
262+ assert usage .request_usage_entries [0 ].input_tokens == 100_000
263+ assert usage .request_usage_entries [1 ].input_tokens == 150_000
264+ assert usage .request_usage_entries [2 ].input_tokens == 80_000
265265
266- # All individual requests are under 200K threshold
267- for req in usage .individual_requests :
266+ # All request_usage_entries are under 200K threshold
267+ for req in usage .request_usage_entries :
268268 assert req .input_tokens < 200_000
269269 assert req .output_tokens < 200_000
0 commit comments