openai-agents 0.0.8__py3-none-any.whl → 0.0.10__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/agent.py +1 -1
- agents/function_schema.py +1 -1
- agents/items.py +3 -1
- agents/mcp/util.py +5 -0
- agents/model_settings.py +13 -0
- agents/models/interface.py +8 -0
- agents/models/openai_chatcompletions.py +40 -8
- agents/models/openai_responses.py +13 -2
- agents/result.py +8 -0
- agents/run.py +22 -2
- agents/tracing/scope.py +4 -0
- agents/tracing/setup.py +3 -0
- agents/tracing/span_data.py +60 -0
- {openai_agents-0.0.8.dist-info → openai_agents-0.0.10.dist-info}/METADATA +1 -1
- {openai_agents-0.0.8.dist-info → openai_agents-0.0.10.dist-info}/RECORD +17 -17
- {openai_agents-0.0.8.dist-info → openai_agents-0.0.10.dist-info}/WHEEL +0 -0
- {openai_agents-0.0.8.dist-info → openai_agents-0.0.10.dist-info}/licenses/LICENSE +0 -0
agents/agent.py
CHANGED
|
@@ -108,7 +108,7 @@ class Agent(Generic[TContext]):
|
|
|
108
108
|
"""The model implementation to use when invoking the LLM.
|
|
109
109
|
|
|
110
110
|
By default, if not set, the agent will use the default model configured in
|
|
111
|
-
`
|
|
111
|
+
`openai_provider.DEFAULT_MODEL` (currently "gpt-4o").
|
|
112
112
|
"""
|
|
113
113
|
|
|
114
114
|
model_settings: ModelSettings = field(default_factory=ModelSettings)
|
agents/function_schema.py
CHANGED
|
@@ -131,7 +131,7 @@ def _detect_docstring_style(doc: str) -> DocstringStyle:
|
|
|
131
131
|
|
|
132
132
|
@contextlib.contextmanager
|
|
133
133
|
def _suppress_griffe_logging():
|
|
134
|
-
#
|
|
134
|
+
# Suppresses warnings about missing annotations for params
|
|
135
135
|
logger = logging.getLogger("griffe")
|
|
136
136
|
previous_level = logger.getEffectiveLevel()
|
|
137
137
|
logger.setLevel(logging.ERROR)
|
agents/items.py
CHANGED
|
@@ -166,9 +166,11 @@ class ModelResponse:
|
|
|
166
166
|
usage: Usage
|
|
167
167
|
"""The usage information for the response."""
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
response_id: str | None
|
|
170
170
|
"""An ID for the response which can be used to refer to the response in subsequent calls to the
|
|
171
171
|
model. Not supported by all model providers.
|
|
172
|
+
If using OpenAI models via the Responses API, this is the `response_id` parameter, and it can
|
|
173
|
+
be passed to `Runner.run`.
|
|
172
174
|
"""
|
|
173
175
|
|
|
174
176
|
def to_input_items(self) -> list[TResponseInputItem]:
|
agents/mcp/util.py
CHANGED
|
@@ -59,6 +59,11 @@ class MCPUtil:
|
|
|
59
59
|
"""Convert an MCP tool to an Agents SDK function tool."""
|
|
60
60
|
invoke_func = functools.partial(cls.invoke_mcp_tool, server, tool)
|
|
61
61
|
schema, is_strict = tool.inputSchema, False
|
|
62
|
+
|
|
63
|
+
# MCP spec doesn't require the inputSchema to have `properties`, but OpenAI spec does.
|
|
64
|
+
if "properties" not in schema:
|
|
65
|
+
schema["properties"] = {}
|
|
66
|
+
|
|
62
67
|
if convert_schemas_to_strict:
|
|
63
68
|
try:
|
|
64
69
|
schema = ensure_strict_json_schema(schema)
|
agents/model_settings.py
CHANGED
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from dataclasses import dataclass, fields, replace
|
|
4
4
|
from typing import Literal
|
|
5
5
|
|
|
6
|
+
from openai._types import Body, Query
|
|
6
7
|
from openai.types.shared import Reasoning
|
|
7
8
|
|
|
8
9
|
|
|
@@ -54,6 +55,18 @@ class ModelSettings:
|
|
|
54
55
|
"""Whether to store the generated model response for later retrieval.
|
|
55
56
|
Defaults to True if not provided."""
|
|
56
57
|
|
|
58
|
+
include_usage: bool | None = None
|
|
59
|
+
"""Whether to include usage chunk.
|
|
60
|
+
Defaults to True if not provided."""
|
|
61
|
+
|
|
62
|
+
extra_query: Query | None = None
|
|
63
|
+
"""Additional query fields to provide with the request.
|
|
64
|
+
Defaults to None if not provided."""
|
|
65
|
+
|
|
66
|
+
extra_body: Body | None = None
|
|
67
|
+
"""Additional body fields to provide with the request.
|
|
68
|
+
Defaults to None if not provided."""
|
|
69
|
+
|
|
57
70
|
def resolve(self, override: ModelSettings | None) -> ModelSettings:
|
|
58
71
|
"""Produce a new ModelSettings by overlaying any non-None values from the
|
|
59
72
|
override on top of this instance."""
|
agents/models/interface.py
CHANGED
|
@@ -44,6 +44,8 @@ class Model(abc.ABC):
|
|
|
44
44
|
output_schema: AgentOutputSchema | None,
|
|
45
45
|
handoffs: list[Handoff],
|
|
46
46
|
tracing: ModelTracing,
|
|
47
|
+
*,
|
|
48
|
+
previous_response_id: str | None,
|
|
47
49
|
) -> ModelResponse:
|
|
48
50
|
"""Get a response from the model.
|
|
49
51
|
|
|
@@ -55,6 +57,8 @@ class Model(abc.ABC):
|
|
|
55
57
|
output_schema: The output schema to use.
|
|
56
58
|
handoffs: The handoffs available to the model.
|
|
57
59
|
tracing: Tracing configuration.
|
|
60
|
+
previous_response_id: the ID of the previous response. Generally not used by the model,
|
|
61
|
+
except for the OpenAI Responses API.
|
|
58
62
|
|
|
59
63
|
Returns:
|
|
60
64
|
The full model response.
|
|
@@ -71,6 +75,8 @@ class Model(abc.ABC):
|
|
|
71
75
|
output_schema: AgentOutputSchema | None,
|
|
72
76
|
handoffs: list[Handoff],
|
|
73
77
|
tracing: ModelTracing,
|
|
78
|
+
*,
|
|
79
|
+
previous_response_id: str | None,
|
|
74
80
|
) -> AsyncIterator[TResponseStreamEvent]:
|
|
75
81
|
"""Stream a response from the model.
|
|
76
82
|
|
|
@@ -82,6 +88,8 @@ class Model(abc.ABC):
|
|
|
82
88
|
output_schema: The output schema to use.
|
|
83
89
|
handoffs: The handoffs available to the model.
|
|
84
90
|
tracing: Tracing configuration.
|
|
91
|
+
previous_response_id: the ID of the previous response. Generally not used by the model,
|
|
92
|
+
except for the OpenAI Responses API.
|
|
85
93
|
|
|
86
94
|
Returns:
|
|
87
95
|
An iterator of response stream events, in OpenAI Responses format.
|
|
@@ -108,6 +108,7 @@ class OpenAIChatCompletionsModel(Model):
|
|
|
108
108
|
output_schema: AgentOutputSchema | None,
|
|
109
109
|
handoffs: list[Handoff],
|
|
110
110
|
tracing: ModelTracing,
|
|
111
|
+
previous_response_id: str | None,
|
|
111
112
|
) -> ModelResponse:
|
|
112
113
|
with generation_span(
|
|
113
114
|
model=str(self.model),
|
|
@@ -156,7 +157,7 @@ class OpenAIChatCompletionsModel(Model):
|
|
|
156
157
|
return ModelResponse(
|
|
157
158
|
output=items,
|
|
158
159
|
usage=usage,
|
|
159
|
-
|
|
160
|
+
response_id=None,
|
|
160
161
|
)
|
|
161
162
|
|
|
162
163
|
async def stream_response(
|
|
@@ -168,6 +169,8 @@ class OpenAIChatCompletionsModel(Model):
|
|
|
168
169
|
output_schema: AgentOutputSchema | None,
|
|
169
170
|
handoffs: list[Handoff],
|
|
170
171
|
tracing: ModelTracing,
|
|
172
|
+
*,
|
|
173
|
+
previous_response_id: str | None,
|
|
171
174
|
) -> AsyncIterator[TResponseStreamEvent]:
|
|
172
175
|
"""
|
|
173
176
|
Yields a partial message as it is generated, as well as the usage information.
|
|
@@ -497,7 +500,11 @@ class OpenAIChatCompletionsModel(Model):
|
|
|
497
500
|
span.span_data.input = converted_messages
|
|
498
501
|
|
|
499
502
|
parallel_tool_calls = (
|
|
500
|
-
True
|
|
503
|
+
True
|
|
504
|
+
if model_settings.parallel_tool_calls and tools and len(tools) > 0
|
|
505
|
+
else False
|
|
506
|
+
if model_settings.parallel_tool_calls is False
|
|
507
|
+
else NOT_GIVEN
|
|
501
508
|
)
|
|
502
509
|
tool_choice = _Converter.convert_tool_choice(model_settings.tool_choice)
|
|
503
510
|
response_format = _Converter.convert_response_format(output_schema)
|
|
@@ -518,10 +525,10 @@ class OpenAIChatCompletionsModel(Model):
|
|
|
518
525
|
f"Response format: {response_format}\n"
|
|
519
526
|
)
|
|
520
527
|
|
|
521
|
-
# Match the behavior of Responses where store is True when not given
|
|
522
|
-
store = model_settings.store if model_settings.store is not None else True
|
|
523
|
-
|
|
524
528
|
reasoning_effort = model_settings.reasoning.effort if model_settings.reasoning else None
|
|
529
|
+
store = _Converter.get_store_param(self._get_client(), model_settings)
|
|
530
|
+
|
|
531
|
+
stream_options = _Converter.get_stream_options_param(self._get_client(), model_settings)
|
|
525
532
|
|
|
526
533
|
ret = await self._get_client().chat.completions.create(
|
|
527
534
|
model=self.model,
|
|
@@ -536,11 +543,13 @@ class OpenAIChatCompletionsModel(Model):
|
|
|
536
543
|
response_format=response_format,
|
|
537
544
|
parallel_tool_calls=parallel_tool_calls,
|
|
538
545
|
stream=stream,
|
|
539
|
-
stream_options=
|
|
540
|
-
store=store,
|
|
546
|
+
stream_options=self._non_null_or_not_given(stream_options),
|
|
547
|
+
store=self._non_null_or_not_given(store),
|
|
541
548
|
reasoning_effort=self._non_null_or_not_given(reasoning_effort),
|
|
542
549
|
extra_headers=_HEADERS,
|
|
543
|
-
|
|
550
|
+
extra_query=model_settings.extra_query,
|
|
551
|
+
extra_body=model_settings.extra_body,
|
|
552
|
+
metadata=self._non_null_or_not_given(model_settings.metadata),
|
|
544
553
|
)
|
|
545
554
|
|
|
546
555
|
if isinstance(ret, ChatCompletion):
|
|
@@ -570,6 +579,29 @@ class OpenAIChatCompletionsModel(Model):
|
|
|
570
579
|
|
|
571
580
|
|
|
572
581
|
class _Converter:
|
|
582
|
+
@classmethod
|
|
583
|
+
def is_openai(cls, client: AsyncOpenAI):
|
|
584
|
+
return str(client.base_url).startswith("https://api.openai.com")
|
|
585
|
+
|
|
586
|
+
@classmethod
|
|
587
|
+
def get_store_param(cls, client: AsyncOpenAI, model_settings: ModelSettings) -> bool | None:
|
|
588
|
+
# Match the behavior of Responses where store is True when not given
|
|
589
|
+
default_store = True if cls.is_openai(client) else None
|
|
590
|
+
return model_settings.store if model_settings.store is not None else default_store
|
|
591
|
+
|
|
592
|
+
@classmethod
|
|
593
|
+
def get_stream_options_param(
|
|
594
|
+
cls, client: AsyncOpenAI, model_settings: ModelSettings
|
|
595
|
+
) -> dict[str, bool] | None:
|
|
596
|
+
default_include_usage = True if cls.is_openai(client) else None
|
|
597
|
+
include_usage = (
|
|
598
|
+
model_settings.include_usage
|
|
599
|
+
if model_settings.include_usage is not None
|
|
600
|
+
else default_include_usage
|
|
601
|
+
)
|
|
602
|
+
stream_options = {"include_usage": include_usage} if include_usage is not None else None
|
|
603
|
+
return stream_options
|
|
604
|
+
|
|
573
605
|
@classmethod
|
|
574
606
|
def convert_tool_choice(
|
|
575
607
|
cls, tool_choice: Literal["auto", "required", "none"] | str | None
|
|
@@ -69,6 +69,7 @@ class OpenAIResponsesModel(Model):
|
|
|
69
69
|
output_schema: AgentOutputSchema | None,
|
|
70
70
|
handoffs: list[Handoff],
|
|
71
71
|
tracing: ModelTracing,
|
|
72
|
+
previous_response_id: str | None,
|
|
72
73
|
) -> ModelResponse:
|
|
73
74
|
with response_span(disabled=tracing.is_disabled()) as span_response:
|
|
74
75
|
try:
|
|
@@ -79,6 +80,7 @@ class OpenAIResponsesModel(Model):
|
|
|
79
80
|
tools,
|
|
80
81
|
output_schema,
|
|
81
82
|
handoffs,
|
|
83
|
+
previous_response_id,
|
|
82
84
|
stream=False,
|
|
83
85
|
)
|
|
84
86
|
|
|
@@ -120,7 +122,7 @@ class OpenAIResponsesModel(Model):
|
|
|
120
122
|
return ModelResponse(
|
|
121
123
|
output=response.output,
|
|
122
124
|
usage=usage,
|
|
123
|
-
|
|
125
|
+
response_id=response.id,
|
|
124
126
|
)
|
|
125
127
|
|
|
126
128
|
async def stream_response(
|
|
@@ -132,6 +134,7 @@ class OpenAIResponsesModel(Model):
|
|
|
132
134
|
output_schema: AgentOutputSchema | None,
|
|
133
135
|
handoffs: list[Handoff],
|
|
134
136
|
tracing: ModelTracing,
|
|
137
|
+
previous_response_id: str | None,
|
|
135
138
|
) -> AsyncIterator[ResponseStreamEvent]:
|
|
136
139
|
"""
|
|
137
140
|
Yields a partial message as it is generated, as well as the usage information.
|
|
@@ -145,6 +148,7 @@ class OpenAIResponsesModel(Model):
|
|
|
145
148
|
tools,
|
|
146
149
|
output_schema,
|
|
147
150
|
handoffs,
|
|
151
|
+
previous_response_id,
|
|
148
152
|
stream=True,
|
|
149
153
|
)
|
|
150
154
|
|
|
@@ -180,6 +184,7 @@ class OpenAIResponsesModel(Model):
|
|
|
180
184
|
tools: list[Tool],
|
|
181
185
|
output_schema: AgentOutputSchema | None,
|
|
182
186
|
handoffs: list[Handoff],
|
|
187
|
+
previous_response_id: str | None,
|
|
183
188
|
stream: Literal[True],
|
|
184
189
|
) -> AsyncStream[ResponseStreamEvent]: ...
|
|
185
190
|
|
|
@@ -192,6 +197,7 @@ class OpenAIResponsesModel(Model):
|
|
|
192
197
|
tools: list[Tool],
|
|
193
198
|
output_schema: AgentOutputSchema | None,
|
|
194
199
|
handoffs: list[Handoff],
|
|
200
|
+
previous_response_id: str | None,
|
|
195
201
|
stream: Literal[False],
|
|
196
202
|
) -> Response: ...
|
|
197
203
|
|
|
@@ -203,6 +209,7 @@ class OpenAIResponsesModel(Model):
|
|
|
203
209
|
tools: list[Tool],
|
|
204
210
|
output_schema: AgentOutputSchema | None,
|
|
205
211
|
handoffs: list[Handoff],
|
|
212
|
+
previous_response_id: str | None,
|
|
206
213
|
stream: Literal[True] | Literal[False] = False,
|
|
207
214
|
) -> Response | AsyncStream[ResponseStreamEvent]:
|
|
208
215
|
list_input = ItemHelpers.input_to_new_input_list(input)
|
|
@@ -229,9 +236,11 @@ class OpenAIResponsesModel(Model):
|
|
|
229
236
|
f"Stream: {stream}\n"
|
|
230
237
|
f"Tool choice: {tool_choice}\n"
|
|
231
238
|
f"Response format: {response_format}\n"
|
|
239
|
+
f"Previous response id: {previous_response_id}\n"
|
|
232
240
|
)
|
|
233
241
|
|
|
234
242
|
return await self._client.responses.create(
|
|
243
|
+
previous_response_id=self._non_null_or_not_given(previous_response_id),
|
|
235
244
|
instructions=self._non_null_or_not_given(system_instructions),
|
|
236
245
|
model=self.model,
|
|
237
246
|
input=list_input,
|
|
@@ -245,10 +254,12 @@ class OpenAIResponsesModel(Model):
|
|
|
245
254
|
parallel_tool_calls=parallel_tool_calls,
|
|
246
255
|
stream=stream,
|
|
247
256
|
extra_headers=_HEADERS,
|
|
257
|
+
extra_query=model_settings.extra_query,
|
|
258
|
+
extra_body=model_settings.extra_body,
|
|
248
259
|
text=response_format,
|
|
249
260
|
store=self._non_null_or_not_given(model_settings.store),
|
|
250
261
|
reasoning=self._non_null_or_not_given(model_settings.reasoning),
|
|
251
|
-
metadata=model_settings.metadata,
|
|
262
|
+
metadata=self._non_null_or_not_given(model_settings.metadata),
|
|
252
263
|
)
|
|
253
264
|
|
|
254
265
|
def _get_client(self) -> AsyncOpenAI:
|
agents/result.py
CHANGED
|
@@ -80,6 +80,14 @@ class RunResultBase(abc.ABC):
|
|
|
80
80
|
|
|
81
81
|
return original_items + new_items
|
|
82
82
|
|
|
83
|
+
@property
|
|
84
|
+
def last_response_id(self) -> str | None:
|
|
85
|
+
"""Convenience method to get the response ID of the last model response."""
|
|
86
|
+
if not self.raw_responses:
|
|
87
|
+
return None
|
|
88
|
+
|
|
89
|
+
return self.raw_responses[-1].response_id
|
|
90
|
+
|
|
83
91
|
|
|
84
92
|
@dataclass
|
|
85
93
|
class RunResult(RunResultBase):
|
agents/run.py
CHANGED
|
@@ -117,6 +117,7 @@ class Runner:
|
|
|
117
117
|
max_turns: int = DEFAULT_MAX_TURNS,
|
|
118
118
|
hooks: RunHooks[TContext] | None = None,
|
|
119
119
|
run_config: RunConfig | None = None,
|
|
120
|
+
previous_response_id: str | None = None,
|
|
120
121
|
) -> RunResult:
|
|
121
122
|
"""Run a workflow starting at the given agent. The agent will run in a loop until a final
|
|
122
123
|
output is generated. The loop runs like so:
|
|
@@ -141,6 +142,8 @@ class Runner:
|
|
|
141
142
|
AI invocation (including any tool calls that might occur).
|
|
142
143
|
hooks: An object that receives callbacks on various lifecycle events.
|
|
143
144
|
run_config: Global settings for the entire agent run.
|
|
145
|
+
previous_response_id: The ID of the previous response, if using OpenAI models via the
|
|
146
|
+
Responses API, this allows you to skip passing in input from the previous turn.
|
|
144
147
|
|
|
145
148
|
Returns:
|
|
146
149
|
A run result containing all the inputs, guardrail results and the output of the last
|
|
@@ -230,6 +233,7 @@ class Runner:
|
|
|
230
233
|
run_config=run_config,
|
|
231
234
|
should_run_agent_start_hooks=should_run_agent_start_hooks,
|
|
232
235
|
tool_use_tracker=tool_use_tracker,
|
|
236
|
+
previous_response_id=previous_response_id,
|
|
233
237
|
),
|
|
234
238
|
)
|
|
235
239
|
else:
|
|
@@ -243,6 +247,7 @@ class Runner:
|
|
|
243
247
|
run_config=run_config,
|
|
244
248
|
should_run_agent_start_hooks=should_run_agent_start_hooks,
|
|
245
249
|
tool_use_tracker=tool_use_tracker,
|
|
250
|
+
previous_response_id=previous_response_id,
|
|
246
251
|
)
|
|
247
252
|
should_run_agent_start_hooks = False
|
|
248
253
|
|
|
@@ -291,6 +296,7 @@ class Runner:
|
|
|
291
296
|
max_turns: int = DEFAULT_MAX_TURNS,
|
|
292
297
|
hooks: RunHooks[TContext] | None = None,
|
|
293
298
|
run_config: RunConfig | None = None,
|
|
299
|
+
previous_response_id: str | None = None,
|
|
294
300
|
) -> RunResult:
|
|
295
301
|
"""Run a workflow synchronously, starting at the given agent. Note that this just wraps the
|
|
296
302
|
`run` method, so it will not work if there's already an event loop (e.g. inside an async
|
|
@@ -319,6 +325,8 @@ class Runner:
|
|
|
319
325
|
AI invocation (including any tool calls that might occur).
|
|
320
326
|
hooks: An object that receives callbacks on various lifecycle events.
|
|
321
327
|
run_config: Global settings for the entire agent run.
|
|
328
|
+
previous_response_id: The ID of the previous response, if using OpenAI models via the
|
|
329
|
+
Responses API, this allows you to skip passing in input from the previous turn.
|
|
322
330
|
|
|
323
331
|
Returns:
|
|
324
332
|
A run result containing all the inputs, guardrail results and the output of the last
|
|
@@ -332,6 +340,7 @@ class Runner:
|
|
|
332
340
|
max_turns=max_turns,
|
|
333
341
|
hooks=hooks,
|
|
334
342
|
run_config=run_config,
|
|
343
|
+
previous_response_id=previous_response_id,
|
|
335
344
|
)
|
|
336
345
|
)
|
|
337
346
|
|
|
@@ -344,6 +353,7 @@ class Runner:
|
|
|
344
353
|
max_turns: int = DEFAULT_MAX_TURNS,
|
|
345
354
|
hooks: RunHooks[TContext] | None = None,
|
|
346
355
|
run_config: RunConfig | None = None,
|
|
356
|
+
previous_response_id: str | None = None,
|
|
347
357
|
) -> RunResultStreaming:
|
|
348
358
|
"""Run a workflow starting at the given agent in streaming mode. The returned result object
|
|
349
359
|
contains a method you can use to stream semantic events as they are generated.
|
|
@@ -370,7 +380,8 @@ class Runner:
|
|
|
370
380
|
AI invocation (including any tool calls that might occur).
|
|
371
381
|
hooks: An object that receives callbacks on various lifecycle events.
|
|
372
382
|
run_config: Global settings for the entire agent run.
|
|
373
|
-
|
|
383
|
+
previous_response_id: The ID of the previous response, if using OpenAI models via the
|
|
384
|
+
Responses API, this allows you to skip passing in input from the previous turn.
|
|
374
385
|
Returns:
|
|
375
386
|
A result object that contains data about the run, as well as a method to stream events.
|
|
376
387
|
"""
|
|
@@ -428,6 +439,7 @@ class Runner:
|
|
|
428
439
|
hooks=hooks,
|
|
429
440
|
context_wrapper=context_wrapper,
|
|
430
441
|
run_config=run_config,
|
|
442
|
+
previous_response_id=previous_response_id,
|
|
431
443
|
)
|
|
432
444
|
)
|
|
433
445
|
return streamed_result
|
|
@@ -485,6 +497,7 @@ class Runner:
|
|
|
485
497
|
hooks: RunHooks[TContext],
|
|
486
498
|
context_wrapper: RunContextWrapper[TContext],
|
|
487
499
|
run_config: RunConfig,
|
|
500
|
+
previous_response_id: str | None,
|
|
488
501
|
):
|
|
489
502
|
current_span: Span[AgentSpanData] | None = None
|
|
490
503
|
current_agent = starting_agent
|
|
@@ -554,6 +567,7 @@ class Runner:
|
|
|
554
567
|
should_run_agent_start_hooks,
|
|
555
568
|
tool_use_tracker,
|
|
556
569
|
all_tools,
|
|
570
|
+
previous_response_id,
|
|
557
571
|
)
|
|
558
572
|
should_run_agent_start_hooks = False
|
|
559
573
|
|
|
@@ -623,6 +637,7 @@ class Runner:
|
|
|
623
637
|
should_run_agent_start_hooks: bool,
|
|
624
638
|
tool_use_tracker: AgentToolUseTracker,
|
|
625
639
|
all_tools: list[Tool],
|
|
640
|
+
previous_response_id: str | None,
|
|
626
641
|
) -> SingleStepResult:
|
|
627
642
|
if should_run_agent_start_hooks:
|
|
628
643
|
await asyncio.gather(
|
|
@@ -662,6 +677,7 @@ class Runner:
|
|
|
662
677
|
get_model_tracing_impl(
|
|
663
678
|
run_config.tracing_disabled, run_config.trace_include_sensitive_data
|
|
664
679
|
),
|
|
680
|
+
previous_response_id=previous_response_id,
|
|
665
681
|
):
|
|
666
682
|
if isinstance(event, ResponseCompletedEvent):
|
|
667
683
|
usage = (
|
|
@@ -677,7 +693,7 @@ class Runner:
|
|
|
677
693
|
final_response = ModelResponse(
|
|
678
694
|
output=event.response.output,
|
|
679
695
|
usage=usage,
|
|
680
|
-
|
|
696
|
+
response_id=event.response.id,
|
|
681
697
|
)
|
|
682
698
|
|
|
683
699
|
streamed_result._event_queue.put_nowait(RawResponsesStreamEvent(data=event))
|
|
@@ -717,6 +733,7 @@ class Runner:
|
|
|
717
733
|
run_config: RunConfig,
|
|
718
734
|
should_run_agent_start_hooks: bool,
|
|
719
735
|
tool_use_tracker: AgentToolUseTracker,
|
|
736
|
+
previous_response_id: str | None,
|
|
720
737
|
) -> SingleStepResult:
|
|
721
738
|
# Ensure we run the hooks before anything else
|
|
722
739
|
if should_run_agent_start_hooks:
|
|
@@ -746,6 +763,7 @@ class Runner:
|
|
|
746
763
|
context_wrapper,
|
|
747
764
|
run_config,
|
|
748
765
|
tool_use_tracker,
|
|
766
|
+
previous_response_id,
|
|
749
767
|
)
|
|
750
768
|
|
|
751
769
|
return await cls._get_single_step_result_from_response(
|
|
@@ -888,6 +906,7 @@ class Runner:
|
|
|
888
906
|
context_wrapper: RunContextWrapper[TContext],
|
|
889
907
|
run_config: RunConfig,
|
|
890
908
|
tool_use_tracker: AgentToolUseTracker,
|
|
909
|
+
previous_response_id: str | None,
|
|
891
910
|
) -> ModelResponse:
|
|
892
911
|
model = cls._get_model(agent, run_config)
|
|
893
912
|
model_settings = agent.model_settings.resolve(run_config.model_settings)
|
|
@@ -903,6 +922,7 @@ class Runner:
|
|
|
903
922
|
tracing=get_model_tracing_impl(
|
|
904
923
|
run_config.tracing_disabled, run_config.trace_include_sensitive_data
|
|
905
924
|
),
|
|
925
|
+
previous_response_id=previous_response_id,
|
|
906
926
|
)
|
|
907
927
|
|
|
908
928
|
context_wrapper.usage.add(new_response.usage)
|
agents/tracing/scope.py
CHANGED
|
@@ -18,6 +18,10 @@ _current_trace: contextvars.ContextVar["Trace | None"] = contextvars.ContextVar(
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
class Scope:
|
|
21
|
+
"""
|
|
22
|
+
Manages the current span and trace in the context.
|
|
23
|
+
"""
|
|
24
|
+
|
|
21
25
|
@classmethod
|
|
22
26
|
def get_current_span(cls) -> "Span[Any] | None":
|
|
23
27
|
return _current_span.get()
|
agents/tracing/setup.py
CHANGED
agents/tracing/span_data.py
CHANGED
|
@@ -9,17 +9,28 @@ if TYPE_CHECKING:
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class SpanData(abc.ABC):
|
|
12
|
+
"""
|
|
13
|
+
Represents span data in the trace.
|
|
14
|
+
"""
|
|
15
|
+
|
|
12
16
|
@abc.abstractmethod
|
|
13
17
|
def export(self) -> dict[str, Any]:
|
|
18
|
+
"""Export the span data as a dictionary."""
|
|
14
19
|
pass
|
|
15
20
|
|
|
16
21
|
@property
|
|
17
22
|
@abc.abstractmethod
|
|
18
23
|
def type(self) -> str:
|
|
24
|
+
"""Return the type of the span."""
|
|
19
25
|
pass
|
|
20
26
|
|
|
21
27
|
|
|
22
28
|
class AgentSpanData(SpanData):
|
|
29
|
+
"""
|
|
30
|
+
Represents an Agent Span in the trace.
|
|
31
|
+
Includes name, handoffs, tools, and output type.
|
|
32
|
+
"""
|
|
33
|
+
|
|
23
34
|
__slots__ = ("name", "handoffs", "tools", "output_type")
|
|
24
35
|
|
|
25
36
|
def __init__(
|
|
@@ -49,6 +60,11 @@ class AgentSpanData(SpanData):
|
|
|
49
60
|
|
|
50
61
|
|
|
51
62
|
class FunctionSpanData(SpanData):
|
|
63
|
+
"""
|
|
64
|
+
Represents a Function Span in the trace.
|
|
65
|
+
Includes input, output and MCP data (if applicable).
|
|
66
|
+
"""
|
|
67
|
+
|
|
52
68
|
__slots__ = ("name", "input", "output", "mcp_data")
|
|
53
69
|
|
|
54
70
|
def __init__(
|
|
@@ -78,6 +94,11 @@ class FunctionSpanData(SpanData):
|
|
|
78
94
|
|
|
79
95
|
|
|
80
96
|
class GenerationSpanData(SpanData):
|
|
97
|
+
"""
|
|
98
|
+
Represents a Generation Span in the trace.
|
|
99
|
+
Includes input, output, model, model configuration, and usage.
|
|
100
|
+
"""
|
|
101
|
+
|
|
81
102
|
__slots__ = (
|
|
82
103
|
"input",
|
|
83
104
|
"output",
|
|
@@ -116,6 +137,11 @@ class GenerationSpanData(SpanData):
|
|
|
116
137
|
|
|
117
138
|
|
|
118
139
|
class ResponseSpanData(SpanData):
|
|
140
|
+
"""
|
|
141
|
+
Represents a Response Span in the trace.
|
|
142
|
+
Includes response and input.
|
|
143
|
+
"""
|
|
144
|
+
|
|
119
145
|
__slots__ = ("response", "input")
|
|
120
146
|
|
|
121
147
|
def __init__(
|
|
@@ -140,6 +166,11 @@ class ResponseSpanData(SpanData):
|
|
|
140
166
|
|
|
141
167
|
|
|
142
168
|
class HandoffSpanData(SpanData):
|
|
169
|
+
"""
|
|
170
|
+
Represents a Handoff Span in the trace.
|
|
171
|
+
Includes source and destination agents.
|
|
172
|
+
"""
|
|
173
|
+
|
|
143
174
|
__slots__ = ("from_agent", "to_agent")
|
|
144
175
|
|
|
145
176
|
def __init__(self, from_agent: str | None, to_agent: str | None):
|
|
@@ -159,6 +190,11 @@ class HandoffSpanData(SpanData):
|
|
|
159
190
|
|
|
160
191
|
|
|
161
192
|
class CustomSpanData(SpanData):
|
|
193
|
+
"""
|
|
194
|
+
Represents a Custom Span in the trace.
|
|
195
|
+
Includes name and data property bag.
|
|
196
|
+
"""
|
|
197
|
+
|
|
162
198
|
__slots__ = ("name", "data")
|
|
163
199
|
|
|
164
200
|
def __init__(self, name: str, data: dict[str, Any]):
|
|
@@ -178,6 +214,11 @@ class CustomSpanData(SpanData):
|
|
|
178
214
|
|
|
179
215
|
|
|
180
216
|
class GuardrailSpanData(SpanData):
|
|
217
|
+
"""
|
|
218
|
+
Represents a Guardrail Span in the trace.
|
|
219
|
+
Includes name and triggered status.
|
|
220
|
+
"""
|
|
221
|
+
|
|
181
222
|
__slots__ = ("name", "triggered")
|
|
182
223
|
|
|
183
224
|
def __init__(self, name: str, triggered: bool = False):
|
|
@@ -197,6 +238,11 @@ class GuardrailSpanData(SpanData):
|
|
|
197
238
|
|
|
198
239
|
|
|
199
240
|
class TranscriptionSpanData(SpanData):
|
|
241
|
+
"""
|
|
242
|
+
Represents a Transcription Span in the trace.
|
|
243
|
+
Includes input, output, model, and model configuration.
|
|
244
|
+
"""
|
|
245
|
+
|
|
200
246
|
__slots__ = (
|
|
201
247
|
"input",
|
|
202
248
|
"output",
|
|
@@ -236,6 +282,11 @@ class TranscriptionSpanData(SpanData):
|
|
|
236
282
|
|
|
237
283
|
|
|
238
284
|
class SpeechSpanData(SpanData):
|
|
285
|
+
"""
|
|
286
|
+
Represents a Speech Span in the trace.
|
|
287
|
+
Includes input, output, model, model configuration, and first content timestamp.
|
|
288
|
+
"""
|
|
289
|
+
|
|
239
290
|
__slots__ = ("input", "output", "model", "model_config", "first_content_at")
|
|
240
291
|
|
|
241
292
|
def __init__(
|
|
@@ -273,6 +324,10 @@ class SpeechSpanData(SpanData):
|
|
|
273
324
|
|
|
274
325
|
|
|
275
326
|
class SpeechGroupSpanData(SpanData):
|
|
327
|
+
"""
|
|
328
|
+
Represents a Speech Group Span in the trace.
|
|
329
|
+
"""
|
|
330
|
+
|
|
276
331
|
__slots__ = "input"
|
|
277
332
|
|
|
278
333
|
def __init__(
|
|
@@ -293,6 +348,11 @@ class SpeechGroupSpanData(SpanData):
|
|
|
293
348
|
|
|
294
349
|
|
|
295
350
|
class MCPListToolsSpanData(SpanData):
|
|
351
|
+
"""
|
|
352
|
+
Represents an MCP List Tools Span in the trace.
|
|
353
|
+
Includes server and result.
|
|
354
|
+
"""
|
|
355
|
+
|
|
296
356
|
__slots__ = (
|
|
297
357
|
"server",
|
|
298
358
|
"result",
|
|
@@ -2,20 +2,20 @@ agents/__init__.py,sha256=gA9s_CXBfe0jaEa1iWPmDG3weoHwin_KQ1XAgaVmHzw,6854
|
|
|
2
2
|
agents/_config.py,sha256=ANrM7GP2VSQehDkMc9qocxkUlPwqU-i5sieMJyEwxpM,796
|
|
3
3
|
agents/_debug.py,sha256=7OKys2lDjeCtGggTkM53m_8vw0WIr3yt-_JPBDAnsw0,608
|
|
4
4
|
agents/_run_impl.py,sha256=QVTLbSydSaXWmaUuXLsZXD0Iktu2fDqBeh965cA416g,34155
|
|
5
|
-
agents/agent.py,sha256=
|
|
5
|
+
agents/agent.py,sha256=jI7AoyptMEtvIca-ZOScEro7ZwXu_TOcg4NJPT88Yf4,10078
|
|
6
6
|
agents/agent_output.py,sha256=sUlsur0_C2pPokyvspo5gxIkM0PtcNxdbZmeu_6Z4TE,5379
|
|
7
7
|
agents/computer.py,sha256=XD44UgiUWSfniv-xKwwDP6wFKVwBiZkpaL1hO-0-7ZA,2516
|
|
8
8
|
agents/exceptions.py,sha256=F3AltRt27PGdhbFqKBhRJL9eHqoN4SQx7oxBn0GWmhs,1856
|
|
9
|
-
agents/function_schema.py,sha256=
|
|
9
|
+
agents/function_schema.py,sha256=k4GTdxf5bvcisVr9b4xSdTGzkB5oP3XZnJMdouABCsw,12909
|
|
10
10
|
agents/guardrail.py,sha256=vWWcApo9s_6aHapQ5AMko08MqC8Jrlk-J5iqIRctCDQ,9291
|
|
11
11
|
agents/handoffs.py,sha256=wRg-HBGKBZev88mOg_mfv6CR8T2kewZM8eX3tb71l1g,9043
|
|
12
|
-
agents/items.py,sha256=
|
|
12
|
+
agents/items.py,sha256=6Xnf6a2tIgM8Pz3T2Xr6J8wgok8fI-KhyKW1XdfHBJU,8306
|
|
13
13
|
agents/lifecycle.py,sha256=wYFG6PLSKQ7bICKVbB8oGtdoJNINGq9obh2RSKlAkDE,2938
|
|
14
14
|
agents/logger.py,sha256=p_ef7vWKpBev5FFybPJjhrCCQizK08Yy1A2EDO1SNNg,60
|
|
15
|
-
agents/model_settings.py,sha256=
|
|
15
|
+
agents/model_settings.py,sha256=9_YyNOI2MDHxk5MnhTOZhbaE4bm4aJSowqxlP_awDZk,2724
|
|
16
16
|
agents/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
17
|
-
agents/result.py,sha256=
|
|
18
|
-
agents/run.py,sha256=
|
|
17
|
+
agents/result.py,sha256=lCzl7heEpY8b74Z9N8Yu_Xxy6fsD6Y6sb2baqQKPV7g,8676
|
|
18
|
+
agents/run.py,sha256=1Vw1UXpW9eCAEp0K5Rai7HZ5zUgce3GJPICKI1rOurE,40009
|
|
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
|
|
@@ -28,22 +28,22 @@ agents/extensions/handoff_prompt.py,sha256=oGWN0uNh3Z1L7E-Ev2up8W084fFrDNOsLDy7P
|
|
|
28
28
|
agents/extensions/visualization.py,sha256=bHtrkqwapHsp9z3hYfidAJXdhsKnW2KioisQcHRxgzM,4242
|
|
29
29
|
agents/mcp/__init__.py,sha256=x-4ZFiXNyJPn9Nbwcai6neKgonyRJ7by67HxnOLPgrw,359
|
|
30
30
|
agents/mcp/server.py,sha256=qbeFEPg2xiUvNKfUlA8qyfDeFsv2yXAJabLG2GhfExQ,11269
|
|
31
|
-
agents/mcp/util.py,sha256=
|
|
31
|
+
agents/mcp/util.py,sha256=dIEdYDMc7Sjp-DFQnvoc4VWU-B7Heyx0I41bcW7RlEg,5232
|
|
32
32
|
agents/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
33
33
|
agents/models/_openai_shared.py,sha256=4Ngwo2Fv2RXY61Pqck1cYPkSln2tDnb8Ai-ao4QG-iE,836
|
|
34
34
|
agents/models/fake_id.py,sha256=lbXjUUSMeAQ8eFx4V5QLUnBClHE6adJlYYav55RlG5w,268
|
|
35
|
-
agents/models/interface.py,sha256=
|
|
36
|
-
agents/models/openai_chatcompletions.py,sha256=
|
|
35
|
+
agents/models/interface.py,sha256=QnJ1TOlK_7fmX9hP7wGKjCyt8Ko6VvjRSIDHm_ahT44,3541
|
|
36
|
+
agents/models/openai_chatcompletions.py,sha256=_sTHk9x4ZNLhLhiyW_5ywPU9FQtKG9pSqa7R4JYigKE,41272
|
|
37
37
|
agents/models/openai_provider.py,sha256=NMxTNaoTa329GrA7jj51LC02pb_e2eFh-PCvWADJrkY,3478
|
|
38
|
-
agents/models/openai_responses.py,sha256=
|
|
38
|
+
agents/models/openai_responses.py,sha256=zI9xcpIwyOGMQfjz5CHNd-1Y_O79T-ejpezogGB7BQE,14254
|
|
39
39
|
agents/tracing/__init__.py,sha256=-hJeEiNvgyQdEXpFTrr_qu_XYREvIrF5KyePDtovSak,2804
|
|
40
40
|
agents/tracing/create.py,sha256=kkMf2pp5Te20YkiSvf3Xj3J9qMibQCjEAxZs1Lr_kTE,18124
|
|
41
41
|
agents/tracing/logger.py,sha256=J4KUDRSGa7x5UVfUwWe-gbKwoaq8AeETRqkPt3QvtGg,68
|
|
42
42
|
agents/tracing/processor_interface.py,sha256=wNyZCwNJko5CrUIWD_lMou5ppQ67CFYwvWRsJRM3up8,1659
|
|
43
43
|
agents/tracing/processors.py,sha256=7FDXVhWj_hk2jv88cFUalF2lqv4KXnruJ74MjS03Euw,10086
|
|
44
|
-
agents/tracing/scope.py,sha256=
|
|
45
|
-
agents/tracing/setup.py,sha256=
|
|
46
|
-
agents/tracing/span_data.py,sha256=
|
|
44
|
+
agents/tracing/scope.py,sha256=u17_m8RPpGvbHrTkaO_kDi5ROBWhfOAIgBe7suiaRD4,1445
|
|
45
|
+
agents/tracing/setup.py,sha256=YnEDTaRG_b510vtsXbOaCUZ0nf7MOr1ULvOpQOHtdBs,6776
|
|
46
|
+
agents/tracing/span_data.py,sha256=rVsp6JDmpsgrjSclcojKqYjMVsdn8mXNh73YevOtcHM,9017
|
|
47
47
|
agents/tracing/spans.py,sha256=6vVzocGMsdgIma1ksqkBZmhar91xj4RpgcpUC3iibqg,6606
|
|
48
48
|
agents/tracing/traces.py,sha256=G5LlECSK-DBRFP-bjT8maZjBQulz6SaHILYauUVlfq8,4775
|
|
49
49
|
agents/tracing/util.py,sha256=x5tAw2YBKggwQ8rH5NG8GiJrFOnPErlJPk7oicBO1dA,501
|
|
@@ -69,7 +69,7 @@ agents/voice/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
|
|
|
69
69
|
agents/voice/models/openai_model_provider.py,sha256=Khn0uT-VhsEbe7_OhBMGFQzXNwL80gcWZyTHl3CaBII,3587
|
|
70
70
|
agents/voice/models/openai_stt.py,sha256=rRsldkvkPhH4T0waX1dhccEqIwmPYh-teK_LRvBgiNI,16882
|
|
71
71
|
agents/voice/models/openai_tts.py,sha256=4KoLQuFDHKu5a1VTJlu9Nj3MHwMlrn9wfT_liJDJ2dw,1477
|
|
72
|
-
openai_agents-0.0.
|
|
73
|
-
openai_agents-0.0.
|
|
74
|
-
openai_agents-0.0.
|
|
75
|
-
openai_agents-0.0.
|
|
72
|
+
openai_agents-0.0.10.dist-info/METADATA,sha256=o1G4eXnWYmV9mgS5v7sKXhVq6e2fEvP34fP9QAcU6WY,8134
|
|
73
|
+
openai_agents-0.0.10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
74
|
+
openai_agents-0.0.10.dist-info/licenses/LICENSE,sha256=E994EspT7Krhy0qGiES7WYNzBHrh1YDk3r--8d1baRU,1063
|
|
75
|
+
openai_agents-0.0.10.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|