openai-agents 0.0.13__py3-none-any.whl → 0.0.15__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.

@@ -269,6 +269,8 @@ class LitellmModel(Model):
269
269
  extra_kwargs["extra_query"] = model_settings.extra_query
270
270
  if model_settings.metadata:
271
271
  extra_kwargs["metadata"] = model_settings.metadata
272
+ if model_settings.extra_body and isinstance(model_settings.extra_body, dict):
273
+ extra_kwargs.update(model_settings.extra_body)
272
274
 
273
275
  ret = await litellm.acompletion(
274
276
  model=self.model,
agents/mcp/__init__.py CHANGED
@@ -5,6 +5,8 @@ try:
5
5
  MCPServerSseParams,
6
6
  MCPServerStdio,
7
7
  MCPServerStdioParams,
8
+ MCPServerStreamableHttp,
9
+ MCPServerStreamableHttpParams,
8
10
  )
9
11
  except ImportError:
10
12
  pass
@@ -17,5 +19,7 @@ __all__ = [
17
19
  "MCPServerSseParams",
18
20
  "MCPServerStdio",
19
21
  "MCPServerStdioParams",
22
+ "MCPServerStreamableHttp",
23
+ "MCPServerStreamableHttpParams",
20
24
  "MCPUtil",
21
25
  ]
agents/mcp/server.py CHANGED
@@ -10,7 +10,9 @@ from typing import Any, Literal
10
10
  from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
11
11
  from mcp import ClientSession, StdioServerParameters, Tool as MCPTool, stdio_client
12
12
  from mcp.client.sse import sse_client
13
- from mcp.types import CallToolResult, JSONRPCMessage
13
+ from mcp.client.streamable_http import GetSessionIdCallback, streamablehttp_client
14
+ from mcp.shared.message import SessionMessage
15
+ from mcp.types import CallToolResult
14
16
  from typing_extensions import NotRequired, TypedDict
15
17
 
16
18
  from ..exceptions import UserError
@@ -83,8 +85,9 @@ class _MCPServerWithClientSession(MCPServer, abc.ABC):
83
85
  self,
84
86
  ) -> AbstractAsyncContextManager[
85
87
  tuple[
86
- MemoryObjectReceiveStream[JSONRPCMessage | Exception],
87
- MemoryObjectSendStream[JSONRPCMessage],
88
+ MemoryObjectReceiveStream[SessionMessage | Exception],
89
+ MemoryObjectSendStream[SessionMessage],
90
+ GetSessionIdCallback | None
88
91
  ]
89
92
  ]:
90
93
  """Create the streams for the server."""
@@ -105,7 +108,11 @@ class _MCPServerWithClientSession(MCPServer, abc.ABC):
105
108
  """Connect to the server."""
106
109
  try:
107
110
  transport = await self.exit_stack.enter_async_context(self.create_streams())
108
- read, write = transport
111
+ # streamablehttp_client returns (read, write, get_session_id)
112
+ # sse_client returns (read, write)
113
+
114
+ read, write, *_ = transport
115
+
109
116
  session = await self.exit_stack.enter_async_context(
110
117
  ClientSession(
111
118
  read,
@@ -232,8 +239,9 @@ class MCPServerStdio(_MCPServerWithClientSession):
232
239
  self,
233
240
  ) -> AbstractAsyncContextManager[
234
241
  tuple[
235
- MemoryObjectReceiveStream[JSONRPCMessage | Exception],
236
- MemoryObjectSendStream[JSONRPCMessage],
242
+ MemoryObjectReceiveStream[SessionMessage | Exception],
243
+ MemoryObjectSendStream[SessionMessage],
244
+ GetSessionIdCallback | None
237
245
  ]
238
246
  ]:
239
247
  """Create the streams for the server."""
@@ -302,8 +310,9 @@ class MCPServerSse(_MCPServerWithClientSession):
302
310
  self,
303
311
  ) -> AbstractAsyncContextManager[
304
312
  tuple[
305
- MemoryObjectReceiveStream[JSONRPCMessage | Exception],
306
- MemoryObjectSendStream[JSONRPCMessage],
313
+ MemoryObjectReceiveStream[SessionMessage | Exception],
314
+ MemoryObjectSendStream[SessionMessage],
315
+ GetSessionIdCallback | None
307
316
  ]
308
317
  ]:
309
318
  """Create the streams for the server."""
@@ -318,3 +327,84 @@ class MCPServerSse(_MCPServerWithClientSession):
318
327
  def name(self) -> str:
319
328
  """A readable name for the server."""
320
329
  return self._name
330
+
331
+
332
+ class MCPServerStreamableHttpParams(TypedDict):
333
+ """Mirrors the params in`mcp.client.streamable_http.streamablehttp_client`."""
334
+
335
+ url: str
336
+ """The URL of the server."""
337
+
338
+ headers: NotRequired[dict[str, str]]
339
+ """The headers to send to the server."""
340
+
341
+ timeout: NotRequired[timedelta]
342
+ """The timeout for the HTTP request. Defaults to 5 seconds."""
343
+
344
+ sse_read_timeout: NotRequired[timedelta]
345
+ """The timeout for the SSE connection, in seconds. Defaults to 5 minutes."""
346
+
347
+ terminate_on_close: NotRequired[bool]
348
+ """Terminate on close"""
349
+
350
+
351
+ class MCPServerStreamableHttp(_MCPServerWithClientSession):
352
+ """MCP server implementation that uses the Streamable HTTP transport. See the [spec]
353
+ (https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http)
354
+ for details.
355
+ """
356
+
357
+ def __init__(
358
+ self,
359
+ params: MCPServerStreamableHttpParams,
360
+ cache_tools_list: bool = False,
361
+ name: str | None = None,
362
+ client_session_timeout_seconds: float | None = 5,
363
+ ):
364
+ """Create a new MCP server based on the Streamable HTTP transport.
365
+
366
+ Args:
367
+ params: The params that configure the server. This includes the URL of the server,
368
+ the headers to send to the server, the timeout for the HTTP request, and the
369
+ timeout for the Streamable HTTP connection and whether we need to
370
+ terminate on close.
371
+
372
+ cache_tools_list: Whether to cache the tools list. If `True`, the tools list will be
373
+ cached and only fetched from the server once. If `False`, the tools list will be
374
+ fetched from the server on each call to `list_tools()`. The cache can be
375
+ invalidated by calling `invalidate_tools_cache()`. You should set this to `True`
376
+ if you know the server will not change its tools list, because it can drastically
377
+ improve latency (by avoiding a round-trip to the server every time).
378
+
379
+ name: A readable name for the server. If not provided, we'll create one from the
380
+ URL.
381
+
382
+ client_session_timeout_seconds: the read timeout passed to the MCP ClientSession.
383
+ """
384
+ super().__init__(cache_tools_list, client_session_timeout_seconds)
385
+
386
+ self.params = params
387
+ self._name = name or f"streamable_http: {self.params['url']}"
388
+
389
+ def create_streams(
390
+ self,
391
+ ) -> AbstractAsyncContextManager[
392
+ tuple[
393
+ MemoryObjectReceiveStream[SessionMessage | Exception],
394
+ MemoryObjectSendStream[SessionMessage],
395
+ GetSessionIdCallback | None
396
+ ]
397
+ ]:
398
+ """Create the streams for the server."""
399
+ return streamablehttp_client(
400
+ url=self.params["url"],
401
+ headers=self.params.get("headers", None),
402
+ timeout=self.params.get("timeout", timedelta(seconds=30)),
403
+ sse_read_timeout=self.params.get("sse_read_timeout", timedelta(seconds=60 * 5)),
404
+ terminate_on_close=self.params.get("terminate_on_close", True)
405
+ )
406
+
407
+ @property
408
+ def name(self) -> str:
409
+ """A readable name for the server."""
410
+ return self._name
@@ -234,7 +234,7 @@ class Converter:
234
234
  type="image_url",
235
235
  image_url={
236
236
  "url": casted_image_param["image_url"],
237
- "detail": casted_image_param["detail"],
237
+ "detail": casted_image_param.get("detail", "auto"),
238
238
  },
239
239
  )
240
240
  )
agents/result.py CHANGED
@@ -15,6 +15,7 @@ from .exceptions import InputGuardrailTripwireTriggered, MaxTurnsExceeded
15
15
  from .guardrail import InputGuardrailResult, OutputGuardrailResult
16
16
  from .items import ItemHelpers, ModelResponse, RunItem, TResponseInputItem
17
17
  from .logger import logger
18
+ from .run_context import RunContextWrapper
18
19
  from .stream_events import StreamEvent
19
20
  from .tracing import Trace
20
21
  from .util._pretty_print import pretty_print_result, pretty_print_run_result_streaming
@@ -50,6 +51,9 @@ class RunResultBase(abc.ABC):
50
51
  output_guardrail_results: list[OutputGuardrailResult]
51
52
  """Guardrail results for the final output of the agent."""
52
53
 
54
+ context_wrapper: RunContextWrapper[Any]
55
+ """The context wrapper for the agent run."""
56
+
53
57
  @property
54
58
  @abc.abstractmethod
55
59
  def last_agent(self) -> Agent[Any]:
@@ -75,9 +79,7 @@ class RunResultBase(abc.ABC):
75
79
 
76
80
  def to_input_list(self) -> list[TResponseInputItem]:
77
81
  """Creates a new input list, merging the original input with all the new items generated."""
78
- original_items: list[TResponseInputItem] = ItemHelpers.input_to_new_input_list(
79
- self.input
80
- )
82
+ original_items: list[TResponseInputItem] = ItemHelpers.input_to_new_input_list(self.input)
81
83
  new_items = [item.to_input_item() for item in self.new_items]
82
84
 
83
85
  return original_items + new_items
@@ -206,17 +208,13 @@ class RunResultStreaming(RunResultBase):
206
208
 
207
209
  def _check_errors(self):
208
210
  if self.current_turn > self.max_turns:
209
- self._stored_exception = MaxTurnsExceeded(
210
- f"Max turns ({self.max_turns}) exceeded"
211
- )
211
+ self._stored_exception = MaxTurnsExceeded(f"Max turns ({self.max_turns}) exceeded")
212
212
 
213
213
  # Fetch all the completed guardrail results from the queue and raise if needed
214
214
  while not self._input_guardrail_queue.empty():
215
215
  guardrail_result = self._input_guardrail_queue.get_nowait()
216
216
  if guardrail_result.output.tripwire_triggered:
217
- self._stored_exception = InputGuardrailTripwireTriggered(
218
- guardrail_result
219
- )
217
+ self._stored_exception = InputGuardrailTripwireTriggered(guardrail_result)
220
218
 
221
219
  # Check the tasks for any exceptions
222
220
  if self._run_impl_task and self._run_impl_task.done():
agents/run.py CHANGED
@@ -270,6 +270,7 @@ class Runner:
270
270
  _last_agent=current_agent,
271
271
  input_guardrail_results=input_guardrail_results,
272
272
  output_guardrail_results=output_guardrail_results,
273
+ context_wrapper=context_wrapper,
273
274
  )
274
275
  elif isinstance(turn_result.next_step, NextStepHandoff):
275
276
  current_agent = cast(Agent[TContext], turn_result.next_step.new_agent)
@@ -423,6 +424,7 @@ class Runner:
423
424
  output_guardrail_results=[],
424
425
  _current_agent_output_schema=output_schema,
425
426
  trace=new_trace,
427
+ context_wrapper=context_wrapper,
426
428
  )
427
429
 
428
430
  # Kick off the actual agent loop in the background and return the streamed result object.
@@ -696,6 +698,7 @@ class Runner:
696
698
  usage=usage,
697
699
  response_id=event.response.id,
698
700
  )
701
+ context_wrapper.usage.add(usage)
699
702
 
700
703
  streamed_result._event_queue.put_nowait(RawResponsesStreamEvent(data=event))
701
704
 
agents/voice/__init__.py CHANGED
@@ -7,6 +7,7 @@ from .model import (
7
7
  STTModelSettings,
8
8
  TTSModel,
9
9
  TTSModelSettings,
10
+ TTSVoice,
10
11
  VoiceModelProvider,
11
12
  )
12
13
  from .models.openai_model_provider import OpenAIVoiceModelProvider
@@ -30,6 +31,7 @@ __all__ = [
30
31
  "STTModelSettings",
31
32
  "TTSModel",
32
33
  "TTSModelSettings",
34
+ "TTSVoice",
33
35
  "VoiceModelProvider",
34
36
  "StreamedAudioResult",
35
37
  "SingleAgentVoiceWorkflow",
agents/voice/model.py CHANGED
@@ -14,14 +14,13 @@ DEFAULT_TTS_INSTRUCTIONS = (
14
14
  )
15
15
  DEFAULT_TTS_BUFFER_SIZE = 120
16
16
 
17
+ TTSVoice = Literal["alloy", "ash", "coral", "echo", "fable", "onyx", "nova", "sage", "shimmer"]
18
+ """Exportable type for the TTSModelSettings voice enum"""
17
19
 
18
20
  @dataclass
19
21
  class TTSModelSettings:
20
22
  """Settings for a TTS model."""
21
-
22
- voice: (
23
- Literal["alloy", "ash", "coral", "echo", "fable", "onyx", "nova", "sage", "shimmer"] | None
24
- ) = None
23
+ voice: TTSVoice | None = None
25
24
  """
26
25
  The voice to use for the TTS model. If not provided, the default voice for the respective model
27
26
  will be used.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openai-agents
3
- Version: 0.0.13
3
+ Version: 0.0.15
4
4
  Summary: OpenAI Agents SDK
5
5
  Project-URL: Homepage, https://github.com/openai/openai-agents-python
6
6
  Project-URL: Repository, https://github.com/openai/openai-agents-python
@@ -19,14 +19,14 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
19
  Classifier: Typing :: Typed
20
20
  Requires-Python: >=3.9
21
21
  Requires-Dist: griffe<2,>=1.5.6
22
- Requires-Dist: mcp<2,>=1.6.0; python_version >= '3.10'
22
+ Requires-Dist: mcp<2,>=1.8.0; python_version >= '3.10'
23
23
  Requires-Dist: openai>=1.76.0
24
24
  Requires-Dist: pydantic<3,>=2.10
25
25
  Requires-Dist: requests<3,>=2.0
26
26
  Requires-Dist: types-requests<3,>=2.0
27
27
  Requires-Dist: typing-extensions<5,>=4.12.2
28
28
  Provides-Extra: litellm
29
- Requires-Dist: litellm<2,>=1.65.0; extra == 'litellm'
29
+ Requires-Dist: litellm<2,>=1.67.4.post1; extra == 'litellm'
30
30
  Provides-Extra: viz
31
31
  Requires-Dist: graphviz>=0.17; extra == 'viz'
32
32
  Provides-Extra: voice
@@ -14,8 +14,8 @@ agents/lifecycle.py,sha256=wYFG6PLSKQ7bICKVbB8oGtdoJNINGq9obh2RSKlAkDE,2938
14
14
  agents/logger.py,sha256=p_ef7vWKpBev5FFybPJjhrCCQizK08Yy1A2EDO1SNNg,60
15
15
  agents/model_settings.py,sha256=7s9YjfHBVz1f1a-V3dd-8eMe-IAgfDXhQgChI27Kz00,3326
16
16
  agents/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
17
- agents/result.py,sha256=WjRTfmM9UOEqcliUX_oUfpHjfzp9b7GuS34SgCngr9U,9258
18
- agents/run.py,sha256=Fm1dHG9cuUuv17B7AXEEeskal5uxrkRy0CJrPbYE2k4,40121
17
+ agents/result.py,sha256=dhtOaLIoOp5PYC4qcsgoU5qg2yvdI_VKdCy6i2qth7k,9305
18
+ agents/run.py,sha256=kPxqU6KjFzkuVdH-UbKPUhJrvl70ChMnQbfI4UDD3fw,40276
19
19
  agents/run_context.py,sha256=vuSUQM8O4CLensQY27-22fOqECnw7yvwL9U3WO8b_bk,851
20
20
  agents/stream_events.py,sha256=ULgBEcL_H4vklZoxhpY2yomeoxVF0UiXvswsFsjFv4s,1547
21
21
  agents/strict_schema.py,sha256=_KuEJkglmq-Fj3HSeYP4WqTvqrxbSKu6gezfz5Brhh0,5775
@@ -27,14 +27,14 @@ agents/extensions/handoff_filters.py,sha256=2cXxu1JROez96CpTiGuT9PIuaIrIE8ksP01f
27
27
  agents/extensions/handoff_prompt.py,sha256=oGWN0uNh3Z1L7E-Ev2up8W084fFrDNOsLDy7P6bcmic,1006
28
28
  agents/extensions/visualization.py,sha256=AQFC7kQlZqTI6QVkyDHrF_DodCytrrhcLg35nfRd_JA,4256
29
29
  agents/extensions/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
- agents/extensions/models/litellm_model.py,sha256=sqlUA4uS6jJExf05oY-ZdhlX_97ZX47Eg5zHmR0UkyI,13631
30
+ agents/extensions/models/litellm_model.py,sha256=JV9DfS6gj9QR0NMFyX4o3Dq5QqJNQ3BksBh7ijrgWoA,13776
31
31
  agents/extensions/models/litellm_provider.py,sha256=wTm00Anq8YoNb9AnyT0JOunDG-HCDm_98ORNy7aNJdw,928
32
- agents/mcp/__init__.py,sha256=x-4ZFiXNyJPn9Nbwcai6neKgonyRJ7by67HxnOLPgrw,359
33
- agents/mcp/server.py,sha256=vB3K2GREyrQv2ikRz2m4EtEY0nynQ5X-7sLbOH3s29E,12163
32
+ agents/mcp/__init__.py,sha256=_aDpMTvYCe1IezOEasZ0vmombBM8r7BD8lpXiKi-UlM,499
33
+ agents/mcp/server.py,sha256=f4F5DSH3TfMJ1SvruRqJT_wYbWhKQbRzVhdYdAjnOnk,15748
34
34
  agents/mcp/util.py,sha256=dIEdYDMc7Sjp-DFQnvoc4VWU-B7Heyx0I41bcW7RlEg,5232
35
35
  agents/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
36
36
  agents/models/_openai_shared.py,sha256=4Ngwo2Fv2RXY61Pqck1cYPkSln2tDnb8Ai-ao4QG-iE,836
37
- agents/models/chatcmpl_converter.py,sha256=C4EOZQDffCRDDRGT8XEobOHJoX7ONaiETDz2MeTviHg,18114
37
+ agents/models/chatcmpl_converter.py,sha256=Sae-ITlhQz8_SiFiSat7Z-lavqIuczduOXR_PF_f6cs,18126
38
38
  agents/models/chatcmpl_helpers.py,sha256=eIWySobaH7I0AQijAz5i-_rtsXrSvmEHD567s_8Zw1o,1318
39
39
  agents/models/chatcmpl_stream_handler.py,sha256=VjskdeGnepn0iJbxsqNZrexcuAYAV1zd5hwt0lU8E7I,12452
40
40
  agents/models/fake_id.py,sha256=lbXjUUSMeAQ8eFx4V5QLUnBClHE6adJlYYav55RlG5w,268
@@ -61,12 +61,12 @@ agents/util/_json.py,sha256=eKeQeMlQkBXRFeL3ilNZFmszGyfhtzZdW_GW_As6dcg,972
61
61
  agents/util/_pretty_print.py,sha256=rRVp24UmTgzCm-W4ritWBOxxnPRinzFdrZlOhTi1KVQ,2227
62
62
  agents/util/_transforms.py,sha256=CZe74NOHkHneyo4fHYfFWksCSTn-kXtEyejL9P0_xlA,270
63
63
  agents/util/_types.py,sha256=8KxYfCw0gYSMWcQmacJoc3Q7Lc46LmT-AWvhF10KJ-E,160
64
- agents/voice/__init__.py,sha256=aEw6GdORLNIXHqIvKFc-5PFZr3XMala3jv4AoeLKt4Q,1507
64
+ agents/voice/__init__.py,sha256=4VWBUjyoXC6dGFuk-oZQGg8T32bFxVwy371c-zDK-EU,1537
65
65
  agents/voice/events.py,sha256=4aPAZC0__ocgmg_mcX4c1zv9Go-YdKIVItQ2kYgtye0,1216
66
66
  agents/voice/exceptions.py,sha256=QcyfvaUTBe4gxbFP82oDSa_puzZ4Z4O4k01B8pAHnK0,233
67
67
  agents/voice/imports.py,sha256=VaE5I8aJTP9Zl_0-y9dx1UcAP7KPRDMaikFK2jFnn8s,348
68
68
  agents/voice/input.py,sha256=FSbdHMIdLVKX4vYcmf3WBJ5dAlh5zMDjCAuGfXOZTQs,2910
69
- agents/voice/model.py,sha256=4ptWkKPfUGbVsg8u10KUIl64iNhQX9rx7Y0D_ZcFlv0,5893
69
+ agents/voice/model.py,sha256=haVPgL3xlzkUyMeVaDphB74TlcZpruagMsx6CQxpx5g,5954
70
70
  agents/voice/pipeline.py,sha256=5LKTTDytQt4QlZzVKgbB9x3X2zA-TeR94FTi15vIUc0,6259
71
71
  agents/voice/pipeline_config.py,sha256=_cynbnzxvQijxkGrMYHJzIV54F9bRvDsPV24qexVO8c,1759
72
72
  agents/voice/result.py,sha256=Yx9JCMGCE9OfXacaBFfFLQJRwkNo5-h4Nqm9OPnemU4,11107
@@ -76,7 +76,7 @@ agents/voice/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
76
76
  agents/voice/models/openai_model_provider.py,sha256=Khn0uT-VhsEbe7_OhBMGFQzXNwL80gcWZyTHl3CaBII,3587
77
77
  agents/voice/models/openai_stt.py,sha256=rRsldkvkPhH4T0waX1dhccEqIwmPYh-teK_LRvBgiNI,16882
78
78
  agents/voice/models/openai_tts.py,sha256=4KoLQuFDHKu5a1VTJlu9Nj3MHwMlrn9wfT_liJDJ2dw,1477
79
- openai_agents-0.0.13.dist-info/METADATA,sha256=0b4sOGaK4JbQC-SId-Xn4WB_AmCRFCUHxymAJEdhYMU,8157
80
- openai_agents-0.0.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
81
- openai_agents-0.0.13.dist-info/licenses/LICENSE,sha256=E994EspT7Krhy0qGiES7WYNzBHrh1YDk3r--8d1baRU,1063
82
- openai_agents-0.0.13.dist-info/RECORD,,
79
+ openai_agents-0.0.15.dist-info/METADATA,sha256=aWuj1znysjWdTLEA_Qtou1aOsPBNRRVFXiPcIoJ4o9c,8163
80
+ openai_agents-0.0.15.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
81
+ openai_agents-0.0.15.dist-info/licenses/LICENSE,sha256=E994EspT7Krhy0qGiES7WYNzBHrh1YDk3r--8d1baRU,1063
82
+ openai_agents-0.0.15.dist-info/RECORD,,