Skip to content

Commit 14c4a36

Browse files
tcdentdot-agi
andauthored
Fix token counts in OpenAI Agents redux (#890)
* Update attribute extraction to support dict as well as object. * Adjust tests to match serialization format of `list[str]`. Patch JSON encode in tests to handle MagicMock objects. * Collect base usage attributes, too. --------- Co-authored-by: Pratyush Shukla <[email protected]>
1 parent 754acb2 commit 14c4a36

File tree

1 file changed

+4
-0
lines changed
  • agentops/instrumentation/openai_agents/attributes

1 file changed

+4
-0
lines changed

agentops/instrumentation/openai_agents/attributes/response.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ def get_response_usage_attributes(usage: 'ResponseUsage') -> AttributeMap:
294294
# )
295295
attributes = {}
296296

297+
attributes.update(_extract_attributes_from_mapping(
298+
usage.__dict__,
299+
RESPONSE_USAGE_ATTRIBUTES))
300+
297301
# input_tokens_details is a dict if it exists
298302
if hasattr(usage, 'input_tokens_details'):
299303
input_details = usage.input_tokens_details

0 commit comments

Comments
 (0)