-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Summary
The RunResult
object currently does not include the .usage
property, making it difficult to track token usage directly from the result. This property is expected based on OpenAI API responses but is missing in the Agents SDK.
Steps to Reproduce
- Create a simple agent run with any supported model.
- Inspect the returned
RunResult
object. - Notice that
.usage
is not available, even though the API response contains usage data.
result = agent.run("Hello")
print(result.usage) # AttributeError: 'RunResult' object has no attribute 'usage'
###Expected Behavior
The RunResult object should include a .usage attribute that reflects the token usage data from the API response, similar to how the Python API client exposes it.
###Actual Behavior
The .usage attribute is missing, requiring developers to manually parse raw responses to get token usage.
### Possible Solution
- Update the RunResult class to store the usage field from the API response.
-
- Ensure .usage is directly accessible.
-
- Add unit tests verifying .usage is populated correctly.
-
### Environment
- openai-agents-python version: 0.2.0
-
- Python version: 3.11.9
-
- OS: Windows 11 Pro 23H2 (Build 22631)
- Additional Context
**This change would simplify token tracking and improve developer experience by matching behavior of other OpenAI SDKs.**
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working