openai-agents 0.2.8__py3-none-any.whl → 0.6.8__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.
Files changed (96) hide show
  1. agents/__init__.py +105 -4
  2. agents/_debug.py +15 -4
  3. agents/_run_impl.py +1203 -96
  4. agents/agent.py +164 -19
  5. agents/apply_diff.py +329 -0
  6. agents/editor.py +47 -0
  7. agents/exceptions.py +35 -0
  8. agents/extensions/experimental/__init__.py +6 -0
  9. agents/extensions/experimental/codex/__init__.py +92 -0
  10. agents/extensions/experimental/codex/codex.py +89 -0
  11. agents/extensions/experimental/codex/codex_options.py +35 -0
  12. agents/extensions/experimental/codex/codex_tool.py +1142 -0
  13. agents/extensions/experimental/codex/events.py +162 -0
  14. agents/extensions/experimental/codex/exec.py +263 -0
  15. agents/extensions/experimental/codex/items.py +245 -0
  16. agents/extensions/experimental/codex/output_schema_file.py +50 -0
  17. agents/extensions/experimental/codex/payloads.py +31 -0
  18. agents/extensions/experimental/codex/thread.py +214 -0
  19. agents/extensions/experimental/codex/thread_options.py +54 -0
  20. agents/extensions/experimental/codex/turn_options.py +36 -0
  21. agents/extensions/handoff_filters.py +13 -1
  22. agents/extensions/memory/__init__.py +120 -0
  23. agents/extensions/memory/advanced_sqlite_session.py +1285 -0
  24. agents/extensions/memory/async_sqlite_session.py +239 -0
  25. agents/extensions/memory/dapr_session.py +423 -0
  26. agents/extensions/memory/encrypt_session.py +185 -0
  27. agents/extensions/memory/redis_session.py +261 -0
  28. agents/extensions/memory/sqlalchemy_session.py +334 -0
  29. agents/extensions/models/litellm_model.py +449 -36
  30. agents/extensions/models/litellm_provider.py +3 -1
  31. agents/function_schema.py +47 -5
  32. agents/guardrail.py +16 -2
  33. agents/{handoffs.py → handoffs/__init__.py} +89 -47
  34. agents/handoffs/history.py +268 -0
  35. agents/items.py +237 -11
  36. agents/lifecycle.py +75 -14
  37. agents/mcp/server.py +280 -37
  38. agents/mcp/util.py +24 -3
  39. agents/memory/__init__.py +22 -2
  40. agents/memory/openai_conversations_session.py +91 -0
  41. agents/memory/openai_responses_compaction_session.py +249 -0
  42. agents/memory/session.py +19 -261
  43. agents/memory/sqlite_session.py +275 -0
  44. agents/memory/util.py +20 -0
  45. agents/model_settings.py +14 -3
  46. agents/models/__init__.py +13 -0
  47. agents/models/chatcmpl_converter.py +303 -50
  48. agents/models/chatcmpl_helpers.py +63 -0
  49. agents/models/chatcmpl_stream_handler.py +290 -68
  50. agents/models/default_models.py +58 -0
  51. agents/models/interface.py +4 -0
  52. agents/models/openai_chatcompletions.py +103 -49
  53. agents/models/openai_provider.py +10 -4
  54. agents/models/openai_responses.py +162 -46
  55. agents/realtime/__init__.py +4 -0
  56. agents/realtime/_util.py +14 -3
  57. agents/realtime/agent.py +7 -0
  58. agents/realtime/audio_formats.py +53 -0
  59. agents/realtime/config.py +78 -10
  60. agents/realtime/events.py +18 -0
  61. agents/realtime/handoffs.py +2 -2
  62. agents/realtime/items.py +17 -1
  63. agents/realtime/model.py +13 -0
  64. agents/realtime/model_events.py +12 -0
  65. agents/realtime/model_inputs.py +18 -1
  66. agents/realtime/openai_realtime.py +696 -150
  67. agents/realtime/session.py +243 -23
  68. agents/repl.py +7 -3
  69. agents/result.py +197 -38
  70. agents/run.py +949 -168
  71. agents/run_context.py +13 -2
  72. agents/stream_events.py +1 -0
  73. agents/strict_schema.py +14 -0
  74. agents/tool.py +413 -15
  75. agents/tool_context.py +22 -1
  76. agents/tool_guardrails.py +279 -0
  77. agents/tracing/__init__.py +2 -0
  78. agents/tracing/config.py +9 -0
  79. agents/tracing/create.py +4 -0
  80. agents/tracing/processor_interface.py +84 -11
  81. agents/tracing/processors.py +65 -54
  82. agents/tracing/provider.py +64 -7
  83. agents/tracing/spans.py +105 -0
  84. agents/tracing/traces.py +116 -16
  85. agents/usage.py +134 -12
  86. agents/util/_json.py +19 -1
  87. agents/util/_transforms.py +12 -2
  88. agents/voice/input.py +5 -4
  89. agents/voice/models/openai_stt.py +17 -9
  90. agents/voice/pipeline.py +2 -0
  91. agents/voice/pipeline_config.py +4 -0
  92. {openai_agents-0.2.8.dist-info → openai_agents-0.6.8.dist-info}/METADATA +44 -19
  93. openai_agents-0.6.8.dist-info/RECORD +134 -0
  94. {openai_agents-0.2.8.dist-info → openai_agents-0.6.8.dist-info}/WHEEL +1 -1
  95. openai_agents-0.2.8.dist-info/RECORD +0 -103
  96. {openai_agents-0.2.8.dist-info → openai_agents-0.6.8.dist-info}/licenses/LICENSE +0 -0
agents/__init__.py CHANGED
@@ -8,12 +8,15 @@ from . import _config
8
8
  from .agent import (
9
9
  Agent,
10
10
  AgentBase,
11
+ AgentToolStreamEvent,
11
12
  StopAtTools,
12
13
  ToolsToFinalOutputFunction,
13
14
  ToolsToFinalOutputResult,
14
15
  )
15
16
  from .agent_output import AgentOutputSchema, AgentOutputSchemaBase
17
+ from .apply_diff import apply_diff
16
18
  from .computer import AsyncComputer, Button, Computer, Environment
19
+ from .editor import ApplyPatchEditor, ApplyPatchOperation, ApplyPatchResult
17
20
  from .exceptions import (
18
21
  AgentsException,
19
22
  InputGuardrailTripwireTriggered,
@@ -21,6 +24,8 @@ from .exceptions import (
21
24
  ModelBehaviorError,
22
25
  OutputGuardrailTripwireTriggered,
23
26
  RunErrorDetails,
27
+ ToolInputGuardrailTripwireTriggered,
28
+ ToolOutputGuardrailTripwireTriggered,
24
29
  UserError,
25
30
  )
26
31
  from .guardrail import (
@@ -32,8 +37,19 @@ from .guardrail import (
32
37
  input_guardrail,
33
38
  output_guardrail,
34
39
  )
35
- from .handoffs import Handoff, HandoffInputData, HandoffInputFilter, handoff
40
+ from .handoffs import (
41
+ Handoff,
42
+ HandoffInputData,
43
+ HandoffInputFilter,
44
+ default_handoff_history_mapper,
45
+ get_conversation_history_wrappers,
46
+ handoff,
47
+ nest_handoff_history,
48
+ reset_conversation_history_wrappers,
49
+ set_conversation_history_wrappers,
50
+ )
36
51
  from .items import (
52
+ CompactionItem,
37
53
  HandoffCallItem,
38
54
  HandoffOutputItem,
39
55
  ItemHelpers,
@@ -46,7 +62,16 @@ from .items import (
46
62
  TResponseInputItem,
47
63
  )
48
64
  from .lifecycle import AgentHooks, RunHooks
49
- from .memory import Session, SQLiteSession
65
+ from .memory import (
66
+ OpenAIConversationsSession,
67
+ OpenAIResponsesCompactionArgs,
68
+ OpenAIResponsesCompactionAwareSession,
69
+ OpenAIResponsesCompactionSession,
70
+ Session,
71
+ SessionABC,
72
+ SQLiteSession,
73
+ is_openai_responses_compaction_aware_session,
74
+ )
50
75
  from .model_settings import ModelSettings
51
76
  from .models.interface import Model, ModelProvider, ModelTracing
52
77
  from .models.multi_provider import MultiProvider
@@ -57,7 +82,7 @@ from .prompts import DynamicPromptFunction, GenerateDynamicPromptData, Prompt
57
82
  from .repl import run_demo_loop
58
83
  from .result import RunResult, RunResultStreaming
59
84
  from .run import RunConfig, Runner
60
- from .run_context import RunContextWrapper, TContext
85
+ from .run_context import AgentHookContext, RunContextWrapper, TContext
61
86
  from .stream_events import (
62
87
  AgentUpdatedStreamEvent,
63
88
  RawResponsesStreamEvent,
@@ -65,7 +90,9 @@ from .stream_events import (
65
90
  StreamEvent,
66
91
  )
67
92
  from .tool import (
93
+ ApplyPatchTool,
68
94
  CodeInterpreterTool,
95
+ ComputerProvider,
69
96
  ComputerTool,
70
97
  FileSearchTool,
71
98
  FunctionTool,
@@ -78,10 +105,37 @@ from .tool import (
78
105
  MCPToolApprovalFunction,
79
106
  MCPToolApprovalFunctionResult,
80
107
  MCPToolApprovalRequest,
108
+ ShellActionRequest,
109
+ ShellCallData,
110
+ ShellCallOutcome,
111
+ ShellCommandOutput,
112
+ ShellCommandRequest,
113
+ ShellExecutor,
114
+ ShellResult,
115
+ ShellTool,
81
116
  Tool,
117
+ ToolOutputFileContent,
118
+ ToolOutputFileContentDict,
119
+ ToolOutputImage,
120
+ ToolOutputImageDict,
121
+ ToolOutputText,
122
+ ToolOutputTextDict,
82
123
  WebSearchTool,
83
124
  default_tool_error_function,
125
+ dispose_resolved_computers,
84
126
  function_tool,
127
+ resolve_computer,
128
+ )
129
+ from .tool_guardrails import (
130
+ ToolGuardrailFunctionOutput,
131
+ ToolInputGuardrail,
132
+ ToolInputGuardrailData,
133
+ ToolInputGuardrailResult,
134
+ ToolOutputGuardrail,
135
+ ToolOutputGuardrailData,
136
+ ToolOutputGuardrailResult,
137
+ tool_input_guardrail,
138
+ tool_output_guardrail,
85
139
  )
86
140
  from .tracing import (
87
141
  AgentSpanData,
@@ -125,7 +179,7 @@ from .version import __version__
125
179
 
126
180
 
127
181
  def set_default_openai_key(key: str, use_for_tracing: bool = True) -> None:
128
- """Set the default OpenAI API key to use for LLM requests (and optionally tracing(). This is
182
+ """Set the default OpenAI API key to use for LLM requests (and optionally tracing()). This is
129
183
  only necessary if the OPENAI_API_KEY environment variable is not already set.
130
184
 
131
185
  If provided, this key will be used instead of the OPENAI_API_KEY environment variable.
@@ -169,10 +223,17 @@ def enable_verbose_stdout_logging():
169
223
  __all__ = [
170
224
  "Agent",
171
225
  "AgentBase",
226
+ "AgentToolStreamEvent",
172
227
  "StopAtTools",
173
228
  "ToolsToFinalOutputFunction",
174
229
  "ToolsToFinalOutputResult",
230
+ "default_handoff_history_mapper",
231
+ "get_conversation_history_wrappers",
232
+ "nest_handoff_history",
233
+ "reset_conversation_history_wrappers",
234
+ "set_conversation_history_wrappers",
175
235
  "Runner",
236
+ "apply_diff",
176
237
  "run_demo_loop",
177
238
  "Model",
178
239
  "ModelProvider",
@@ -191,6 +252,8 @@ __all__ = [
191
252
  "AgentsException",
192
253
  "InputGuardrailTripwireTriggered",
193
254
  "OutputGuardrailTripwireTriggered",
255
+ "ToolInputGuardrailTripwireTriggered",
256
+ "ToolOutputGuardrailTripwireTriggered",
194
257
  "DynamicPromptFunction",
195
258
  "GenerateDynamicPromptData",
196
259
  "Prompt",
@@ -204,6 +267,15 @@ __all__ = [
204
267
  "GuardrailFunctionOutput",
205
268
  "input_guardrail",
206
269
  "output_guardrail",
270
+ "ToolInputGuardrail",
271
+ "ToolOutputGuardrail",
272
+ "ToolGuardrailFunctionOutput",
273
+ "ToolInputGuardrailData",
274
+ "ToolInputGuardrailResult",
275
+ "ToolOutputGuardrailData",
276
+ "ToolOutputGuardrailResult",
277
+ "tool_input_guardrail",
278
+ "tool_output_guardrail",
207
279
  "handoff",
208
280
  "Handoff",
209
281
  "HandoffInputData",
@@ -221,7 +293,15 @@ __all__ = [
221
293
  "RunHooks",
222
294
  "AgentHooks",
223
295
  "Session",
296
+ "SessionABC",
224
297
  "SQLiteSession",
298
+ "OpenAIConversationsSession",
299
+ "OpenAIResponsesCompactionSession",
300
+ "OpenAIResponsesCompactionArgs",
301
+ "OpenAIResponsesCompactionAwareSession",
302
+ "is_openai_responses_compaction_aware_session",
303
+ "CompactionItem",
304
+ "AgentHookContext",
225
305
  "RunContextWrapper",
226
306
  "TContext",
227
307
  "RunErrorDetails",
@@ -235,19 +315,40 @@ __all__ = [
235
315
  "FunctionTool",
236
316
  "FunctionToolResult",
237
317
  "ComputerTool",
318
+ "ComputerProvider",
238
319
  "FileSearchTool",
239
320
  "CodeInterpreterTool",
240
321
  "ImageGenerationTool",
241
322
  "LocalShellCommandRequest",
242
323
  "LocalShellExecutor",
243
324
  "LocalShellTool",
325
+ "ShellActionRequest",
326
+ "ShellCallData",
327
+ "ShellCallOutcome",
328
+ "ShellCommandOutput",
329
+ "ShellCommandRequest",
330
+ "ShellExecutor",
331
+ "ShellResult",
332
+ "ShellTool",
333
+ "ApplyPatchEditor",
334
+ "ApplyPatchOperation",
335
+ "ApplyPatchResult",
336
+ "ApplyPatchTool",
244
337
  "Tool",
245
338
  "WebSearchTool",
246
339
  "HostedMCPTool",
247
340
  "MCPToolApprovalFunction",
248
341
  "MCPToolApprovalRequest",
249
342
  "MCPToolApprovalFunctionResult",
343
+ "ToolOutputText",
344
+ "ToolOutputTextDict",
345
+ "ToolOutputImage",
346
+ "ToolOutputImageDict",
347
+ "ToolOutputFileContent",
348
+ "ToolOutputFileContentDict",
250
349
  "function_tool",
350
+ "resolve_computer",
351
+ "dispose_resolved_computers",
251
352
  "Usage",
252
353
  "add_trace_processor",
253
354
  "agent_span",
agents/_debug.py CHANGED
@@ -1,17 +1,28 @@
1
1
  import os
2
2
 
3
3
 
4
- def _debug_flag_enabled(flag: str) -> bool:
4
+ def _debug_flag_enabled(flag: str, default: bool = False) -> bool:
5
5
  flag_value = os.getenv(flag)
6
- return flag_value is not None and (flag_value == "1" or flag_value.lower() == "true")
6
+ if flag_value is None:
7
+ return default
8
+ else:
9
+ return flag_value == "1" or flag_value.lower() == "true"
7
10
 
8
11
 
9
- DONT_LOG_MODEL_DATA = _debug_flag_enabled("OPENAI_AGENTS_DONT_LOG_MODEL_DATA")
12
+ def _load_dont_log_model_data() -> bool:
13
+ return _debug_flag_enabled("OPENAI_AGENTS_DONT_LOG_MODEL_DATA", default=True)
14
+
15
+
16
+ def _load_dont_log_tool_data() -> bool:
17
+ return _debug_flag_enabled("OPENAI_AGENTS_DONT_LOG_TOOL_DATA", default=True)
18
+
19
+
20
+ DONT_LOG_MODEL_DATA = _load_dont_log_model_data()
10
21
  """By default we don't log LLM inputs/outputs, to prevent exposing sensitive information. Set this
11
22
  flag to enable logging them.
12
23
  """
13
24
 
14
- DONT_LOG_TOOL_DATA = _debug_flag_enabled("OPENAI_AGENTS_DONT_LOG_TOOL_DATA")
25
+ DONT_LOG_TOOL_DATA = _load_dont_log_tool_data()
15
26
  """By default we don't log tool call inputs/outputs, to prevent exposing sensitive information. Set
16
27
  this flag to enable logging them.
17
28
  """