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
@@ -0,0 +1,92 @@
1
+ from .codex import Codex
2
+ from .codex_options import CodexOptions
3
+ from .codex_tool import (
4
+ CodexToolOptions,
5
+ CodexToolResult,
6
+ CodexToolStreamEvent,
7
+ OutputSchemaDescriptor,
8
+ codex_tool,
9
+ )
10
+ from .events import (
11
+ ItemCompletedEvent,
12
+ ItemStartedEvent,
13
+ ItemUpdatedEvent,
14
+ ThreadError,
15
+ ThreadErrorEvent,
16
+ ThreadEvent,
17
+ ThreadStartedEvent,
18
+ TurnCompletedEvent,
19
+ TurnFailedEvent,
20
+ TurnStartedEvent,
21
+ Usage,
22
+ )
23
+ from .items import (
24
+ AgentMessageItem,
25
+ CommandExecutionItem,
26
+ ErrorItem,
27
+ FileChangeItem,
28
+ FileUpdateChange,
29
+ McpToolCallError,
30
+ McpToolCallItem,
31
+ McpToolCallResult,
32
+ ReasoningItem,
33
+ ThreadItem,
34
+ TodoItem,
35
+ TodoListItem,
36
+ WebSearchItem,
37
+ )
38
+ from .thread import Input, RunResult, RunStreamedResult, Thread, Turn, UserInput
39
+ from .thread_options import (
40
+ ApprovalMode,
41
+ ModelReasoningEffort,
42
+ SandboxMode,
43
+ ThreadOptions,
44
+ WebSearchMode,
45
+ )
46
+ from .turn_options import TurnOptions
47
+
48
+ __all__ = [
49
+ "Codex",
50
+ "CodexOptions",
51
+ "Thread",
52
+ "Turn",
53
+ "RunResult",
54
+ "RunStreamedResult",
55
+ "Input",
56
+ "UserInput",
57
+ "ThreadOptions",
58
+ "TurnOptions",
59
+ "ApprovalMode",
60
+ "SandboxMode",
61
+ "ModelReasoningEffort",
62
+ "WebSearchMode",
63
+ "ThreadEvent",
64
+ "ThreadStartedEvent",
65
+ "TurnStartedEvent",
66
+ "TurnCompletedEvent",
67
+ "TurnFailedEvent",
68
+ "ItemStartedEvent",
69
+ "ItemUpdatedEvent",
70
+ "ItemCompletedEvent",
71
+ "ThreadError",
72
+ "ThreadErrorEvent",
73
+ "Usage",
74
+ "ThreadItem",
75
+ "AgentMessageItem",
76
+ "ReasoningItem",
77
+ "CommandExecutionItem",
78
+ "FileChangeItem",
79
+ "FileUpdateChange",
80
+ "McpToolCallItem",
81
+ "McpToolCallResult",
82
+ "McpToolCallError",
83
+ "WebSearchItem",
84
+ "TodoItem",
85
+ "TodoListItem",
86
+ "ErrorItem",
87
+ "codex_tool",
88
+ "CodexToolOptions",
89
+ "CodexToolResult",
90
+ "CodexToolStreamEvent",
91
+ "OutputSchemaDescriptor",
92
+ ]
@@ -0,0 +1,89 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Mapping
4
+ from typing import Any, overload
5
+
6
+ from agents.exceptions import UserError
7
+
8
+ from .codex_options import CodexOptions, coerce_codex_options
9
+ from .exec import CodexExec
10
+ from .thread import Thread
11
+ from .thread_options import ThreadOptions, coerce_thread_options
12
+
13
+
14
+ class _UnsetType:
15
+ pass
16
+
17
+
18
+ _UNSET = _UnsetType()
19
+
20
+
21
+ class Codex:
22
+ @overload
23
+ def __init__(self, options: CodexOptions | Mapping[str, Any] | None = None) -> None: ...
24
+
25
+ @overload
26
+ def __init__(
27
+ self,
28
+ *,
29
+ codex_path_override: str | None = None,
30
+ base_url: str | None = None,
31
+ api_key: str | None = None,
32
+ env: Mapping[str, str] | None = None,
33
+ ) -> None: ...
34
+
35
+ def __init__(
36
+ self,
37
+ options: CodexOptions | Mapping[str, Any] | None = None,
38
+ *,
39
+ codex_path_override: str | None | _UnsetType = _UNSET,
40
+ base_url: str | None | _UnsetType = _UNSET,
41
+ api_key: str | None | _UnsetType = _UNSET,
42
+ env: Mapping[str, str] | None | _UnsetType = _UNSET,
43
+ ) -> None:
44
+ kw_values = {
45
+ "codex_path_override": codex_path_override,
46
+ "base_url": base_url,
47
+ "api_key": api_key,
48
+ "env": env,
49
+ }
50
+ has_kwargs = any(value is not _UNSET for value in kw_values.values())
51
+ if options is not None and has_kwargs:
52
+ raise UserError(
53
+ "Codex options must be provided as a CodexOptions/mapping or keyword arguments, "
54
+ "not both."
55
+ )
56
+ if has_kwargs:
57
+ options = {key: value for key, value in kw_values.items() if value is not _UNSET}
58
+ resolved_options = coerce_codex_options(options) or CodexOptions()
59
+ self._exec = CodexExec(
60
+ executable_path=resolved_options.codex_path_override,
61
+ env=_normalize_env(resolved_options),
62
+ )
63
+ self._options = resolved_options
64
+
65
+ def start_thread(self, options: ThreadOptions | Mapping[str, Any] | None = None) -> Thread:
66
+ resolved_options = coerce_thread_options(options) or ThreadOptions()
67
+ return Thread(
68
+ exec_client=self._exec,
69
+ options=self._options,
70
+ thread_options=resolved_options,
71
+ )
72
+
73
+ def resume_thread(
74
+ self, thread_id: str, options: ThreadOptions | Mapping[str, Any] | None = None
75
+ ) -> Thread:
76
+ resolved_options = coerce_thread_options(options) or ThreadOptions()
77
+ return Thread(
78
+ exec_client=self._exec,
79
+ options=self._options,
80
+ thread_options=resolved_options,
81
+ thread_id=thread_id,
82
+ )
83
+
84
+
85
+ def _normalize_env(options: CodexOptions) -> dict[str, str] | None:
86
+ if options.env is None:
87
+ return None
88
+ # Normalize mapping values to strings for subprocess environment.
89
+ return {str(key): str(value) for key, value in options.env.items()}
@@ -0,0 +1,35 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Mapping
4
+ from dataclasses import dataclass, fields
5
+ from typing import Any
6
+
7
+ from agents.exceptions import UserError
8
+
9
+
10
+ @dataclass(frozen=True)
11
+ class CodexOptions:
12
+ # Optional absolute path to the codex CLI binary.
13
+ codex_path_override: str | None = None
14
+ # Override OpenAI base URL for the Codex CLI process.
15
+ base_url: str | None = None
16
+ # API key passed to the Codex CLI (CODEX_API_KEY).
17
+ api_key: str | None = None
18
+ # Environment variables for the Codex CLI process (do not inherit os.environ).
19
+ env: Mapping[str, str] | None = None
20
+
21
+
22
+ def coerce_codex_options(
23
+ options: CodexOptions | Mapping[str, Any] | None,
24
+ ) -> CodexOptions | None:
25
+ if options is None or isinstance(options, CodexOptions):
26
+ return options
27
+ if not isinstance(options, Mapping):
28
+ raise UserError("CodexOptions must be a CodexOptions or a mapping.")
29
+
30
+ allowed = {field.name for field in fields(CodexOptions)}
31
+ unknown = set(options.keys()) - allowed
32
+ if unknown:
33
+ raise UserError(f"Unknown CodexOptions field(s): {sorted(unknown)}")
34
+
35
+ return CodexOptions(**dict(options))