openai-agents 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of openai-agents might be problematic. Click here for more details.

agents/usage.py CHANGED
@@ -4,6 +4,26 @@ from openai.types.responses.response_usage import InputTokensDetails, OutputToke
4
4
  from pydantic.dataclasses import dataclass
5
5
 
6
6
 
7
+ @dataclass
8
+ class RequestUsage:
9
+ """Usage details for a single API request."""
10
+
11
+ input_tokens: int
12
+ """Input tokens for this individual request."""
13
+
14
+ output_tokens: int
15
+ """Output tokens for this individual request."""
16
+
17
+ total_tokens: int
18
+ """Total tokens (input + output) for this individual request."""
19
+
20
+ input_tokens_details: InputTokensDetails
21
+ """Details about the input tokens for this individual request."""
22
+
23
+ output_tokens_details: OutputTokensDetails
24
+ """Details about the output tokens for this individual request."""
25
+
26
+
7
27
  @dataclass
8
28
  class Usage:
9
29
  requests: int = 0
@@ -27,7 +47,37 @@ class Usage:
27
47
  total_tokens: int = 0
28
48
  """Total tokens sent and received, across all requests."""
29
49
 
50
+ request_usage_entries: list[RequestUsage] = field(default_factory=list)
51
+ """List of RequestUsage entries for accurate per-request cost calculation.
52
+
53
+ Each call to `add()` automatically creates an entry in this list if the added usage
54
+ represents a new request (i.e., has non-zero tokens).
55
+
56
+ Example:
57
+ For a run that makes 3 API calls with 100K, 150K, and 80K input tokens each,
58
+ the aggregated `input_tokens` would be 330K, but `request_usage_entries` would
59
+ preserve the [100K, 150K, 80K] breakdown, which could be helpful for detailed
60
+ cost calculation or context window management.
61
+ """
62
+
63
+ def __post_init__(self) -> None:
64
+ # Some providers don't populate optional token detail fields
65
+ # (cached_tokens, reasoning_tokens), and the OpenAI SDK's generated
66
+ # code can bypass Pydantic validation (e.g., via model_construct),
67
+ # allowing None values. We normalize these to 0 to prevent TypeErrors.
68
+ if self.input_tokens_details.cached_tokens is None:
69
+ self.input_tokens_details = InputTokensDetails(cached_tokens=0)
70
+ if self.output_tokens_details.reasoning_tokens is None:
71
+ self.output_tokens_details = OutputTokensDetails(reasoning_tokens=0)
72
+
30
73
  def add(self, other: "Usage") -> None:
74
+ """Add another Usage object to this one, aggregating all fields.
75
+
76
+ This method automatically preserves request_usage_entries.
77
+
78
+ Args:
79
+ other: The Usage object to add to this one.
80
+ """
31
81
  self.requests += other.requests if other.requests else 0
32
82
  self.input_tokens += other.input_tokens if other.input_tokens else 0
33
83
  self.output_tokens += other.output_tokens if other.output_tokens else 0
@@ -41,3 +91,18 @@ class Usage:
41
91
  reasoning_tokens=self.output_tokens_details.reasoning_tokens
42
92
  + other.output_tokens_details.reasoning_tokens
43
93
  )
94
+
95
+ # Automatically preserve request_usage_entries.
96
+ # If the other Usage represents a single request with tokens, record it.
97
+ if other.requests == 1 and other.total_tokens > 0:
98
+ request_usage = RequestUsage(
99
+ input_tokens=other.input_tokens,
100
+ output_tokens=other.output_tokens,
101
+ total_tokens=other.total_tokens,
102
+ input_tokens_details=other.input_tokens_details,
103
+ output_tokens_details=other.output_tokens_details,
104
+ )
105
+ self.request_usage_entries.append(request_usage)
106
+ elif other.request_usage_entries:
107
+ # If the other Usage already has individual request breakdowns, merge them.
108
+ self.request_usage_entries.extend(other.request_usage_entries)
@@ -122,7 +122,8 @@ class OpenAISTTTranscriptionSession(StreamedTranscriptionSession):
122
122
  return
123
123
 
124
124
  if self._tracing_span:
125
- if self._trace_include_sensitive_audio_data:
125
+ # Only encode audio if tracing is enabled AND buffer is not empty
126
+ if self._trace_include_sensitive_audio_data and self._turn_audio_buffer:
126
127
  self._tracing_span.span_data.input = _audio_to_base64(self._turn_audio_buffer)
127
128
 
128
129
  self._tracing_span.span_data.input_format = "pcm"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openai-agents
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: OpenAI Agents SDK
5
5
  Project-URL: Homepage, https://openai.github.io/openai-agents-python/
6
6
  Project-URL: Repository, https://github.com/openai/openai-agents-python
@@ -16,16 +16,20 @@ Classifier: Programming Language :: Python :: 3.10
16
16
  Classifier: Programming Language :: Python :: 3.11
17
17
  Classifier: Programming Language :: Python :: 3.12
18
18
  Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
19
20
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
21
  Classifier: Typing :: Typed
21
22
  Requires-Python: >=3.9
22
23
  Requires-Dist: griffe<2,>=1.5.6
23
24
  Requires-Dist: mcp<2,>=1.11.0; python_version >= '3.10'
24
- Requires-Dist: openai<3,>=2.2
25
- Requires-Dist: pydantic<3,>=2.10
25
+ Requires-Dist: openai<3,>=2.7.1
26
+ Requires-Dist: pydantic<3,>=2.12.3
26
27
  Requires-Dist: requests<3,>=2.0
27
28
  Requires-Dist: types-requests<3,>=2.0
28
29
  Requires-Dist: typing-extensions<5,>=4.12.2
30
+ Provides-Extra: dapr
31
+ Requires-Dist: dapr>=1.16.0; extra == 'dapr'
32
+ Requires-Dist: grpcio>=1.60.0; extra == 'dapr'
29
33
  Provides-Extra: encrypt
30
34
  Requires-Dist: cryptography<46,>=45.0; extra == 'encrypt'
31
35
  Provides-Extra: litellm
@@ -44,7 +48,7 @@ Requires-Dist: numpy<3,>=2.2.0; (python_version >= '3.10') and extra == 'voice'
44
48
  Requires-Dist: websockets<16,>=15.0; extra == 'voice'
45
49
  Description-Content-Type: text/markdown
46
50
 
47
- # OpenAI Agents SDK
51
+ # OpenAI Agents SDK [![PyPI](https://img.shields.io/pypi/v/openai-agents?label=pypi%20package)](https://pypi.org/project/openai-agents/)
48
52
 
49
53
  The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows. It is provider-agnostic, supporting the OpenAI Responses and Chat Completions APIs, as well as 100+ other LLMs.
50
54
 
@@ -352,6 +356,12 @@ make lint # run linter
352
356
  make format-check # run style checker
353
357
  ```
354
358
 
359
+ Format code if `make format-check` fails above by running:
360
+
361
+ ```
362
+ make format
363
+ ```
364
+
355
365
  ## Acknowledgements
356
366
 
357
367
  We'd like to acknowledge the excellent work of the open-source community, especially:
@@ -1,7 +1,7 @@
1
1
  agents/__init__.py,sha256=qdaXm0t_NP4B78ODns3J9FAy4AurgDcQGNkXf9y_pL8,9036
2
2
  agents/_config.py,sha256=ANrM7GP2VSQehDkMc9qocxkUlPwqU-i5sieMJyEwxpM,796
3
3
  agents/_debug.py,sha256=dRe2dUlA9bCLp6f8bAdiX7JfGyJuHyS_DRdW0kZshl0,856
4
- agents/_run_impl.py,sha256=WXxiCS_GMYhY8Z3SjxVOgcEk3YgtjdoM3pr6FxJXUi8,55174
4
+ agents/_run_impl.py,sha256=aGPdjlTYg2lcJaorxx8rCtVvlMzfpXyfBb7PqggF44Q,55318
5
5
  agents/agent.py,sha256=P5AzwKz3FiQJjzfautF0R9JzxkTXEeItcEkJgn8z5mM,19832
6
6
  agents/agent_output.py,sha256=teTFK8unUN3esXhmEBO0bQGYQm1Axd5rYleDt9TFDgw,7153
7
7
  agents/computer.py,sha256=XD44UgiUWSfniv-xKwwDP6wFKVwBiZkpaL1hO-0-7ZA,2516
@@ -9,34 +9,35 @@ agents/exceptions.py,sha256=roJsYttB5i7FQlzRQNg8QSVdALZFz5u7kUeVvJdaitE,4156
9
9
  agents/function_schema.py,sha256=njtbLt44DOkIU0a0U8TeDNEx-iQZU8oohwy3k7-k4A8,14855
10
10
  agents/guardrail.py,sha256=7P-kd9rKPhgB8rtI31MCV5ho4ZrEaNCQxHvE8IK3EOk,9582
11
11
  agents/handoffs.py,sha256=kDTM3nj3E_0khiJPMJAIN00gektMTRNbaYSbc5ZCnBM,11411
12
- agents/items.py,sha256=9-it0ZFCy_igRtpBIk7BTebdvK1G_Ygt16B24gFvN5w,14216
13
- agents/lifecycle.py,sha256=hGsqzumOSaal6oAjTqTfvBXl-ShAOkC42sthJigB5Fg,4308
12
+ agents/items.py,sha256=YoAhxwb2PSgClGGWrkTIWufAxg0F1cS1KohLYonwz6I,14370
13
+ agents/lifecycle.py,sha256=2dhFi8CBH-EHDiAnj-_h1UmZ2ayC8Tmv5K61P-Kem9w,4362
14
14
  agents/logger.py,sha256=p_ef7vWKpBev5FFybPJjhrCCQizK08Yy1A2EDO1SNNg,60
15
15
  agents/model_settings.py,sha256=7Ul-Xg-aNVXIbK6V4Rm2t5EEfNR0tsy_A9ac_wFqLLk,6828
16
16
  agents/prompts.py,sha256=Ss5y_7s2HFcRAOAKu4WTxQszs5ybI8TfbxgEYdnj9sg,2231
17
17
  agents/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
18
18
  agents/repl.py,sha256=NX0BE5YDnmGQ2rdQsmLm3CKkQZ5m4GC95xXmUsAXJVs,2539
19
19
  agents/result.py,sha256=FW3-fsYOIJrn7pjiDjWPHN58pPpYfNoFNTympFV_96k,13963
20
- agents/run.py,sha256=z0SKQx2jk4nHeWkBII2ZDpEY4dxm6Ce6Ud8I9GN7N9A,74508
20
+ agents/run.py,sha256=g4Z8I28pKaefbMxB0rNVqT4JBbLqHNYSH8_W1WHHmmM,77816
21
21
  agents/run_context.py,sha256=vuSUQM8O4CLensQY27-22fOqECnw7yvwL9U3WO8b_bk,851
22
- agents/stream_events.py,sha256=VFyTu-DT3ZMnHLtMbg-X_lxec0doQxNfx-hVxLB0BpI,1700
22
+ agents/stream_events.py,sha256=vW7O5T6iwFuRFvds1Bq3zMB60fRCz7lWryMkHSL-bAo,1733
23
23
  agents/strict_schema.py,sha256=HFm4j753-UKDfJ0zSiQYf5V1qGuHY6TRm2zzwI0f0E0,6382
24
- agents/tool.py,sha256=H-IytTUTna7qTQbfraRystrgKeYU5Cc1zFKAeXqwO5A,19537
24
+ agents/tool.py,sha256=yNCqv4gu1g0Gxrt9YPYdSkZaWlO3d84vlEwxOegVRng,20304
25
25
  agents/tool_context.py,sha256=g53mgaeX7kCwPaIReiwuUejD8qC7QejMS-F3Wnkuhhg,1866
26
26
  agents/tool_guardrails.py,sha256=2uXEr_R5AWy9NHtBjd7G7upc3uZSuoP86Hfsc-qTadM,8344
27
- agents/usage.py,sha256=Tb5udGd3DPgD0JBdRD8fDctTE4M-zKML5uRn8ZG1yBc,1675
27
+ agents/usage.py,sha256=azQmy1Oyx0vk6dpq-gSAFPvP5L54zIM2CwbJbozTOR0,4517
28
28
  agents/version.py,sha256=_1knUwzSK-HUeZTpRUkk6Z-CIcurqXuEplbV5TLJ08E,230
29
29
  agents/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
30
  agents/extensions/handoff_filters.py,sha256=CS-k7TGCtT8TW3GeXb04OoFBXKdjg8-85QXswWAYBmI,2095
31
31
  agents/extensions/handoff_prompt.py,sha256=oGWN0uNh3Z1L7E-Ev2up8W084fFrDNOsLDy7P6bcmic,1006
32
32
  agents/extensions/visualization.py,sha256=sf9D_C-HMwkbWdZccTZvvMPRy_NSiwbm48tRJlESQBI,5144
33
- agents/extensions/memory/__init__.py,sha256=jhx0pa1TVRFooiI0ERRhklkaeiZ-NDGA_b9tJXp3VfM,2201
33
+ agents/extensions/memory/__init__.py,sha256=ckEgIcbSh7ptmJzoHtVI7YeC6TjI3IkxrYKG-NQApBA,3498
34
34
  agents/extensions/memory/advanced_sqlite_session.py,sha256=rCrXM878foAuBN-rN2fibP2GHs-1hTtRx-TQcDKIfGI,52883
35
+ agents/extensions/memory/dapr_session.py,sha256=AZ2fOsHLqDIcS8Ash9jRYRsqB7lpcV1zJLeIMNVe41I,16663
35
36
  agents/extensions/memory/encrypt_session.py,sha256=PVnZIEj50bjUq16OLnMKrbZiinLkrVpamPPEw8RnUCA,6485
36
37
  agents/extensions/memory/redis_session.py,sha256=JwXY6zUTMgq9bRezlyFZ4Tze7DO7T0hioTc23qjSHjU,9838
37
- agents/extensions/memory/sqlalchemy_session.py,sha256=LlZ5Gx1zR9cRGwM__LkQCHzK7ItT9hfACo16hCQWlQU,11879
38
+ agents/extensions/memory/sqlalchemy_session.py,sha256=fnlZkNF_XZekP44uhiR4rjlCkwG7JJEiFm35TJfiCtc,12325
38
39
  agents/extensions/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
- agents/extensions/models/litellm_model.py,sha256=D4dbbOHHgdBPADAEYHlFhma9645r3gN9U7gg4713mhw,23653
40
+ agents/extensions/models/litellm_model.py,sha256=hbQFhAeEF5eHdyu5Q-7HNYFEhmn0KFK2KAcfYA10vqc,25621
40
41
  agents/extensions/models/litellm_provider.py,sha256=ZHgh1nMoEvA7NpawkzLh3JDuDFtwXUV94Rs7UrwWqAk,1083
41
42
  agents/mcp/__init__.py,sha256=yHmmYlrmEHzUas1inRLKL2iPqbb_-107G3gKe_tyg4I,750
42
43
  agents/mcp/server.py,sha256=cby0KKKKRhuWCydr4llERPL72Z94uV-SV3LLAcgcWTk,28435
@@ -48,9 +49,9 @@ agents/memory/sqlite_session.py,sha256=6HGzSL70mQgutITIPZUC2x2Qtj6U4hXiZTceu3Da7
48
49
  agents/memory/util.py,sha256=ZAHOrNVA36xICFzuNgHgEA1_s_oEMO6Wsu6-EecY8JU,586
49
50
  agents/models/__init__.py,sha256=E0XVqWayVAsFqxucDLBW30siaqfNQsVrAnfidG_C3ok,287
50
51
  agents/models/_openai_shared.py,sha256=4Ngwo2Fv2RXY61Pqck1cYPkSln2tDnb8Ai-ao4QG-iE,836
51
- agents/models/chatcmpl_converter.py,sha256=qEobLnIJjrK6WRi_tsVkrDrGq78EGro3MZXlVMpMK2c,26011
52
+ agents/models/chatcmpl_converter.py,sha256=cwc2JSQpsYzzc_Pk-j_wcQWArWnHWOHglE5N_vdPv5Y,26185
52
53
  agents/models/chatcmpl_helpers.py,sha256=YC2krp_-uBgRCrCEImLjNvONTWRWfwLlPKHI4kBmNXE,1483
53
- agents/models/chatcmpl_stream_handler.py,sha256=r8nc-4hJg1plw87y24MD48O23xnfC_2gHKowtOYgO3M,28896
54
+ agents/models/chatcmpl_stream_handler.py,sha256=_ZlFgwoiBOHMHbN-WN3hN5lTIEy04M3uoWctDb4H4VM,29209
54
55
  agents/models/default_models.py,sha256=mlvBePn8H4UkHo7lN-wh7A3k2ciLgBUFKpROQxzdTfs,2098
55
56
  agents/models/fake_id.py,sha256=lbXjUUSMeAQ8eFx4V5QLUnBClHE6adJlYYav55RlG5w,268
56
57
  agents/models/interface.py,sha256=-AFUHC8iRuGZmtQwguDw4s-M4OPL2y2mct4TAmWvVrU,4057
@@ -64,16 +65,16 @@ agents/realtime/_default_tracker.py,sha256=4OMxBvD1MnZmMn6JZYKL42uWhVzvK6NdDLDfP
64
65
  agents/realtime/_util.py,sha256=ehBzUN1RTD2m2TXq73Jm4WohQzJ6y_MfnF5MaK8uu14,341
65
66
  agents/realtime/agent.py,sha256=bkegBJ_lc3z3NtnlIyEkVZFxZWBJwVjsQVzpQZAu7PM,4283
66
67
  agents/realtime/audio_formats.py,sha256=DBUWVVff4XY5BT6Mol86tF4PFMp5OIS3LmAbqUmQn_k,1019
67
- agents/realtime/config.py,sha256=ud0GK8ZbcnKRC4oGZNwpsiZI8TZ1OdTSMADfFtM8Z6I,6948
68
- agents/realtime/events.py,sha256=eANiNNyYlp_1Ybdl-MOwXRVTDtrK9hfgn6iw0xNxnaY,5889
68
+ agents/realtime/config.py,sha256=vnjgkeZXcOSLFopoAiGj4Vki_75pEJIKTagJtQpCWmg,7072
69
+ agents/realtime/events.py,sha256=BkktfS4cCpz53Fn6Di-8kgRXlxzE9NvzqJFevDVE3uc,6084
69
70
  agents/realtime/handoffs.py,sha256=iJ4lr5RVdDkw5W3_AOGB_Az-hlRt1CoFFFNFDfd3ues,6698
70
71
  agents/realtime/items.py,sha256=5EG768FkKpbk-dhe4b_7BfFpdUEFWtxoiVUtNI9KXsc,5517
71
- agents/realtime/model.py,sha256=Lnb9pEcvnlIdXJUcldVyioaX5lpmrBou5FZoNJe4XfA,6457
72
+ agents/realtime/model.py,sha256=jVZBhPRc2yDQfAFn2pqnnVNtkgsguKS8qO-KbQCtuEs,6774
72
73
  agents/realtime/model_events.py,sha256=2NKofzLszKHwtlcsogsNnH6hdeFfO7S96yWDB4AlxB8,4340
73
- agents/realtime/model_inputs.py,sha256=gRas0-ohirmGbCMWc8tHTo-e3ZPcPn7TK9BauCK9ynA,2657
74
- agents/realtime/openai_realtime.py,sha256=x3dLSax3DF-hbQDSPXUtvHalN3nlwwcXYBIa36_ZqNo,44307
74
+ agents/realtime/model_inputs.py,sha256=-pl8Oj0WVrA5Gt-dqP5Va3ZHqXyIXpsjMsf9UL-suEY,2789
75
+ agents/realtime/openai_realtime.py,sha256=5tLF_gglC1GAKcJNjleSPdVZbM7656SxtqnLzVynrpk,45806
75
76
  agents/realtime/runner.py,sha256=KfU7utmc9QFH2htIKN2IN9H-5EnB0qN9ezmvlRTnOm4,2511
76
- agents/realtime/session.py,sha256=e4fJ3E5lS_y5IfczPAnX81vHr5rvEzJbT1LsmVdW7lc,35199
77
+ agents/realtime/session.py,sha256=TmMZdw-1qpQh22Oa_XDy1T6NrnPnGXXRAZ-yKKKFj_w,37077
77
78
  agents/tracing/__init__.py,sha256=5HO_6na5S6EwICgwl50OMtxiIIosUrqalhvldlYvSVc,2991
78
79
  agents/tracing/create.py,sha256=xpJ4ZRnGyUDPKoVVkA_8hmdhtwOKGhSkwRco2AQIhAo,18003
79
80
  agents/tracing/logger.py,sha256=J4KUDRSGa7x5UVfUwWe-gbKwoaq8AeETRqkPt3QvtGg,68
@@ -106,9 +107,9 @@ agents/voice/utils.py,sha256=MrRomVqBLXeMAOue-Itwh0Fc5HjB0QCMKXclqFPhrbI,1309
106
107
  agents/voice/workflow.py,sha256=m_-_4qU1gEE5gcGahiE2IrIimmRW2X1rR20zZEGivSc,3795
107
108
  agents/voice/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
108
109
  agents/voice/models/openai_model_provider.py,sha256=Khn0uT-VhsEbe7_OhBMGFQzXNwL80gcWZyTHl3CaBII,3587
109
- agents/voice/models/openai_stt.py,sha256=eZ0dmX_uDywpR1H3Q2N5jrV7NK3bR9l2a1InWM3yegk,17151
110
+ agents/voice/models/openai_stt.py,sha256=Lb_F9160VNKDHXZ9zylSzeig7sB8lBjiYhQLDZsp6NQ,17257
110
111
  agents/voice/models/openai_tts.py,sha256=4KoLQuFDHKu5a1VTJlu9Nj3MHwMlrn9wfT_liJDJ2dw,1477
111
- openai_agents-0.4.0.dist-info/METADATA,sha256=oz5c_NXJgwN1WWVSpsQDb9MYB9tz7TZA1v2lqySphmM,12929
112
- openai_agents-0.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
113
- openai_agents-0.4.0.dist-info/licenses/LICENSE,sha256=E994EspT7Krhy0qGiES7WYNzBHrh1YDk3r--8d1baRU,1063
114
- openai_agents-0.4.0.dist-info/RECORD,,
112
+ openai_agents-0.5.0.dist-info/METADATA,sha256=GcCRv8byD4gVjMUNanTpvOaCeAbNxQLN1gPncRMHbBI,13295
113
+ openai_agents-0.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
114
+ openai_agents-0.5.0.dist-info/licenses/LICENSE,sha256=E994EspT7Krhy0qGiES7WYNzBHrh1YDk3r--8d1baRU,1063
115
+ openai_agents-0.5.0.dist-info/RECORD,,