agent-engine-sdk-openai-agents 0.11.8__tar.gz

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 (24) hide show
  1. agent_engine_sdk_openai_agents-0.11.8/LICENSE +201 -0
  2. agent_engine_sdk_openai_agents-0.11.8/PKG-INFO +229 -0
  3. agent_engine_sdk_openai_agents-0.11.8/README.md +212 -0
  4. agent_engine_sdk_openai_agents-0.11.8/pyproject.toml +45 -0
  5. agent_engine_sdk_openai_agents-0.11.8/src/agent_engine_sdk_openai_agents/__init__.py +13 -0
  6. agent_engine_sdk_openai_agents-0.11.8/src/agent_engine_sdk_openai_agents/agent.py +325 -0
  7. agent_engine_sdk_openai_agents-0.11.8/src/agent_engine_sdk_openai_agents/agent_tools.py +261 -0
  8. agent_engine_sdk_openai_agents-0.11.8/src/agent_engine_sdk_openai_agents/app.py +239 -0
  9. agent_engine_sdk_openai_agents-0.11.8/src/agent_engine_sdk_openai_agents/approvals.py +348 -0
  10. agent_engine_sdk_openai_agents-0.11.8/src/agent_engine_sdk_openai_agents/errors.py +11 -0
  11. agent_engine_sdk_openai_agents-0.11.8/src/agent_engine_sdk_openai_agents/graph.py +231 -0
  12. agent_engine_sdk_openai_agents-0.11.8/src/agent_engine_sdk_openai_agents/items.py +252 -0
  13. agent_engine_sdk_openai_agents-0.11.8/src/agent_engine_sdk_openai_agents/llm_adapter.py +336 -0
  14. agent_engine_sdk_openai_agents-0.11.8/src/agent_engine_sdk_openai_agents/py.typed +0 -0
  15. agent_engine_sdk_openai_agents-0.11.8/src/agent_engine_sdk_openai_agents/secure_model.py +284 -0
  16. agent_engine_sdk_openai_agents-0.11.8/src/agent_engine_sdk_openai_agents/state.py +147 -0
  17. agent_engine_sdk_openai_agents-0.11.8/src/agent_engine_sdk_openai_agents/tools.py +349 -0
  18. agent_engine_sdk_openai_agents-0.11.8/src/agent_engine_sdk_openai_agents/wire.py +210 -0
  19. agent_engine_sdk_openai_agents-0.11.8/tests/__init__.py +0 -0
  20. agent_engine_sdk_openai_agents-0.11.8/tests/conftest.py +23 -0
  21. agent_engine_sdk_openai_agents-0.11.8/tests/support.py +228 -0
  22. agent_engine_sdk_openai_agents-0.11.8/tests/test_app.py +2471 -0
  23. agent_engine_sdk_openai_agents-0.11.8/tests/test_model_routing.py +572 -0
  24. agent_engine_sdk_openai_agents-0.11.8/tests/test_state.py +308 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 MongoDB, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,229 @@
1
+ Metadata-Version: 2.5
2
+ Name: agent-engine-sdk-openai-agents
3
+ Version: 0.11.8
4
+ Summary: OpenAI Agents SDK adapter for Atlas Agent Engine
5
+ License: Apache-2.0
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.11
8
+ Requires-Dist: agent-engine-runner-shared[mongodb,tracing]==0.11.8
9
+ Requires-Dist: agent-engine-sdk==0.11.8
10
+ Requires-Dist: openai-agents==0.22.0
11
+ Provides-Extra: dev
12
+ Requires-Dist: pyright>=1.1.414; extra == 'dev'
13
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
14
+ Requires-Dist: pytest>=9.1.1; extra == 'dev'
15
+ Requires-Dist: ruff>=0.9; extra == 'dev'
16
+ Description-Content-Type: text/markdown
17
+
18
+ # Agent Engine SDK OpenAI Agents
19
+
20
+ [![License](https://img.shields.io/badge/license-Apache-2.0-blue.svg)](LICENSE)
21
+
22
+ OpenAI Agents SDK adapter for the MongoDB Atlas Agent Engine SDK.
23
+
24
+ > **Status:** under construction. `framework: openai-agents` is not yet
25
+ > accepted by the CLI or the build service.
26
+
27
+ The adapter runs a native OpenAI Agents `Agent` through the SDK's own
28
+ `Runner` while the Orchestration Engine owns durable execution. The adapter
29
+ keeps no session database and never uses OpenAI Sessions, Conversations, or
30
+ `previous_response_id` as continuation state.
31
+
32
+ ## Building an agent
33
+
34
+ ```python
35
+ from agents import Agent, ModelSettings
36
+ from agent_engine_sdk_openai_agents import App
37
+
38
+ app = App(app_name="support")
39
+
40
+
41
+ @app.tool()
42
+ def lookup_order(order_id: str) -> str:
43
+ """Look up an order."""
44
+ ...
45
+
46
+
47
+ @app.entrypoint
48
+ def build() -> Agent:
49
+ return Agent(
50
+ name="support",
51
+ instructions="Help with orders.",
52
+ model=app.llm("gpt-4.1", settings=ModelSettings(temperature=0)),
53
+ tools=app.tools(),
54
+ )
55
+ ```
56
+
57
+ Use the model returned by `app.llm(...)` and the tools returned by
58
+ `app.tools()`; anything else fails the turn before any model or tool work.
59
+ Pass a configured `agents.Model` to `app.llm` to use a custom OpenAI client.
60
+ Tool parameters must be JSON values that can be passed by name (no
61
+ positional-only or `*args` parameters, and none named `tool_call_id`), because remote tools receive their
62
+ arguments as named JSON values. Set a tool's timeout with
63
+ `@app.tool(timeout=...)`; a native `timeout_seconds` on an issued tool fails
64
+ the turn. A non-string tool result, including nested models,
65
+ dataclasses, enums, and datetimes, reaches the model as JSON text. The text is
66
+ canonical, so a replayed turn sends the model the same text: keys are sorted
67
+ and a whole-number float such as `164.0` is written `164`. An integer beyond
68
+ 2**53 in a tool's result or arguments fails the call, because the durable
69
+ record cannot keep it exactly; pass such a value as a string.
70
+
71
+ Each invocation runs one native `Runner` turn and commits it to the
72
+ Orchestration Engine before returning the result. A failed tool call fails
73
+ the turn with the error the platform's tool path reports, such as a tool
74
+ execution error carrying the tool's message or a policy denial; a cancelled or
75
+ user-stopped call fails it too. Nothing is committed in any of these cases.
76
+ When the model calls several tools at once, they run concurrently. Each call
77
+ keeps the Orchestration Engine activity of its call id, and their results reach
78
+ the model in the order the model made the calls, whichever finishes first. If
79
+ one of them waits for approval, the calls that ran before the wait keep their
80
+ outputs ahead of the approved call's, as the SDK records them. When one call
81
+ fails, the turn fails once the calls still running beside it have finished.
82
+ MCP servers, guardrails, agent hooks, hosted prompts, dynamic instructions,
83
+ and a custom `tool_use_behavior` are not supported yet.
84
+
85
+ ## Handoffs
86
+
87
+ Use the SDK's own `handoffs=[...]`, with other agents or `agents.handoff(...)`.
88
+ The runtime reads the whole agent graph the entrypoint returns before each
89
+ turn and holds every reachable agent to the same rules as the first: its model
90
+ comes from `app.llm(...)` (give each agent's model its own `llm_id`) and its
91
+ tools from `app.tools()`, from which each agent can select its own by name.
92
+ Agent names must be unique.
93
+
94
+ A handoff changes which agent is active; the turn stays one execution. The
95
+ committed state records the active agent, so the next turn, also after a
96
+ restart, starts with the agent that ended the last one. An approval requested
97
+ by a handed-off agent suspends and resumes in that agent.
98
+
99
+ `agents.handoff(...)` may override the tool name and description. Agents may
100
+ hand off to each other in a cycle. An `input_filter`, `nest_handoff_history`,
101
+ an `on_handoff` callback, an `input_type`, a callable `is_enabled`, and a
102
+ hand-built `Handoff` fail the turn before any model or tool work. So does a
103
+ handoff on any agent whose tool name matches another handoff's or one of that
104
+ agent's tools: the SDK would otherwise keep one and drop the other.
105
+
106
+ ## Agents as tools
107
+
108
+ Use the SDK's own `Agent.as_tool(...)` and put the result in another agent's
109
+ `tools`. The nested agent follows the same rules as every other agent in the
110
+ graph. Each call runs the nested agent as its own operation: its model and
111
+ tool calls are Orchestration Engine activities under a path named after the
112
+ tool, and repeated or concurrent calls to the same agent tool stay distinct,
113
+ in the order the model made them.
114
+
115
+ The calling agent's model sees only the tool's answer, and only the calling
116
+ conversation is committed; a replacement attempt replays the nested run from
117
+ its recorded activities. The caller's stream carries the nested agent's text
118
+ between `subagent_start` and `subagent_end` events, tagged with the tool name
119
+ and the call id, apart from the calling agent's reply. A nested run that fails
120
+ fails the turn.
121
+
122
+ `max_turns`, `custom_output_extractor`, and structured input are supported. A
123
+ replacement attempt calls the extractor and a structured input's
124
+ `input_builder` again, so both must return the same value for the same input
125
+ and have no side effects; OE fails the turn when a replayed model call differs
126
+ from the recorded one.
127
+
128
+ An `on_stream` callback, `hooks`, a `run_config`, a `session`, provider
129
+ continuation ids, a callable `needs_approval` or `is_enabled`, tool guardrails,
130
+ a native `timeout_seconds`, and an agent that can reach itself through its own
131
+ agent tool fail the turn before any model or tool work. So does a tool that
132
+ needs approval anywhere a nested agent can reach, which is not supported yet;
133
+ approvals in the calling agent work as usual.
134
+
135
+ ## Approvals
136
+
137
+ Register a tool with `@app.tool(needs_approval=True)` to have a person approve
138
+ each call. The argument is the SDK's own `function_tool(needs_approval=...)`,
139
+ passed through to the `FunctionTool` that `app.tools()` returns; setting
140
+ `needs_approval` on that returned tool works too. When the model calls a tool
141
+ that needs approval, the turn suspends: the invocation returns
142
+ `status: suspended` with one interrupt per call waiting for approval, in the
143
+ order the model made the calls, each naming the tool and its arguments. Calls
144
+ in the same response that need no approval run first. Resume through the normal
145
+ invoke endpoint on the same session, with `resume_map` answering every
146
+ interrupt id at once:
147
+
148
+ ```json
149
+ {"resume_map": {"<interrupt id>": {"confirmed": true}}}
150
+ ```
151
+
152
+ `interrupts` lists every pending approval. `suspend_payload` carries only the
153
+ first one's value, for callers that read a single payload.
154
+
155
+ `{"confirmed": false, "rejection_message": "..."}` rejects the call; the model
156
+ sees the rejection message instead of a tool result, as with the SDK's own
157
+ `reject(..., rejection_message=...)`. Without a
158
+ `rejection_message` the model sees the SDK's default rejection text; an empty
159
+ one is refused. An approval
160
+ carries no message. The Orchestration Engine records the wait
161
+ and its answer. Resuming replays the turn from the recorded model calls, applies
162
+ the answer through the SDK's own `RunState`, and runs only what remains, so a
163
+ tool never runs before its approval, prefix output is not repeated, and a
164
+ restart while waiting loses nothing. A resume that leaves any interrupt
165
+ unanswered is refused; `needs_approval` must be `True` or `False`, not a
166
+ callable.
167
+
168
+ ## Durable state
169
+
170
+ Each committed turn stores the Runner's complete input list under the
171
+ `__agent_engine_openai_agents__` state property, together with the app and
172
+ session it belongs to and the name of the agent that ended the turn. The next
173
+ turn continues from that list with that agent. Committed
174
+ messages are an explicit-field projection for history readers; they are not
175
+ read back.
176
+
177
+ Supported items are text messages, function calls, and text function outputs.
178
+ The calls one model response made come together, followed by exactly one
179
+ output per call before anything else. Any other item, any state that belongs
180
+ to a different app or session, and an active agent the app no longer has fail
181
+ the turn before new model or tool work starts.
182
+
183
+ ## Model calls
184
+
185
+ Every model call the native `Runner` makes becomes an Orchestration Engine
186
+ LLM activity. The agent's model answers from the recorded activity, and the
187
+ model itself runs in the Tool Pod. A replacement attempt replays the recorded
188
+ response and gives the `Runner` identical output items.
189
+
190
+ Only per-call settings the platform carries cross that boundary: `max_tokens`,
191
+ `top_p`, `frequency_penalty`, `presence_penalty`, `timeout`,
192
+ `parallel_tool_calls`, `reasoning.effort`, `verbosity`, and a named
193
+ `tool_choice`. Provider settings such as `temperature` belong to the model you
194
+ register, and the Tool Pod applies them. A registered model cannot carry a
195
+ `tool_choice` or `timeout` (set them on the agent), or `extra_body` / `extra_args` fields that make the provider
196
+ continue a stored conversation (`previous_response_id`, `conversation`,
197
+ `conversation_id`, `prompt`) or that override what the adapter builds for
198
+ each call (such as `tools`, `input`, `instructions`, or the output format), or that set
199
+ `reasoning`, `reasoning_effort`, or `verbosity` as raw fields (use `ModelSettings.reasoning` and
200
+ `ModelSettings.verbosity`). Native tracing, provider-hosted
201
+ continuation, and stop sequences fail before the call is sent.
202
+
203
+ ### Reasoning
204
+
205
+ Set `reasoning=Reasoning(effort=...)` and `verbosity` on the registered model,
206
+ on the agent, or both; per-call values win over the registration. Prefer the
207
+ registration. The SDK cannot tell an agent's explicit settings from its own
208
+ defaults: when `Agent(model_settings=...)` equals the SDK's default settings
209
+ (currently `Reasoning(effort="none")` with `verbosity="low"`), the SDK clears
210
+ them at construction and the registered values apply. To use exactly that pair
211
+ per call, assign it after construction (`agent.model_settings = ...`). Other
212
+ reasoning settings, such as `reasoning.summary`, fail before the call is sent.
213
+ Reasoning-token counts are reported in the model call's usage. Providers may
214
+ limit these settings per model and API: for example, a Chat Completions
215
+ reasoning model can refuse function tools unless the effort is `none`. The
216
+ provider's refusal fails the model call.
217
+
218
+ A durable run does not carry a model's hidden reasoning from one model call to
219
+ the next. The provider's encrypted reasoning items are dropped in the Tool Pod
220
+ and never stored, so each call, including each step of a tool loop, reasons
221
+ from the durable conversation alone. If an agent needs a plan that persists
222
+ across calls, it should record the plan explicitly, for example in its own
223
+ messages or in Memory, rather than rely on the model's hidden reasoning.
224
+
225
+ The Tool Pod retries transient provider failures before any output streams.
226
+ The SDK's own `ModelSettings.retry` is rejected: on the agent it would make
227
+ the `Runner` issue extra model activities, and on a registered model it would
228
+ have no effect. A model stream that ends without a completed response fails
229
+ the call rather than being recorded as a truncated answer.
@@ -0,0 +1,212 @@
1
+ # Agent Engine SDK OpenAI Agents
2
+
3
+ [![License](https://img.shields.io/badge/license-Apache-2.0-blue.svg)](LICENSE)
4
+
5
+ OpenAI Agents SDK adapter for the MongoDB Atlas Agent Engine SDK.
6
+
7
+ > **Status:** under construction. `framework: openai-agents` is not yet
8
+ > accepted by the CLI or the build service.
9
+
10
+ The adapter runs a native OpenAI Agents `Agent` through the SDK's own
11
+ `Runner` while the Orchestration Engine owns durable execution. The adapter
12
+ keeps no session database and never uses OpenAI Sessions, Conversations, or
13
+ `previous_response_id` as continuation state.
14
+
15
+ ## Building an agent
16
+
17
+ ```python
18
+ from agents import Agent, ModelSettings
19
+ from agent_engine_sdk_openai_agents import App
20
+
21
+ app = App(app_name="support")
22
+
23
+
24
+ @app.tool()
25
+ def lookup_order(order_id: str) -> str:
26
+ """Look up an order."""
27
+ ...
28
+
29
+
30
+ @app.entrypoint
31
+ def build() -> Agent:
32
+ return Agent(
33
+ name="support",
34
+ instructions="Help with orders.",
35
+ model=app.llm("gpt-4.1", settings=ModelSettings(temperature=0)),
36
+ tools=app.tools(),
37
+ )
38
+ ```
39
+
40
+ Use the model returned by `app.llm(...)` and the tools returned by
41
+ `app.tools()`; anything else fails the turn before any model or tool work.
42
+ Pass a configured `agents.Model` to `app.llm` to use a custom OpenAI client.
43
+ Tool parameters must be JSON values that can be passed by name (no
44
+ positional-only or `*args` parameters, and none named `tool_call_id`), because remote tools receive their
45
+ arguments as named JSON values. Set a tool's timeout with
46
+ `@app.tool(timeout=...)`; a native `timeout_seconds` on an issued tool fails
47
+ the turn. A non-string tool result, including nested models,
48
+ dataclasses, enums, and datetimes, reaches the model as JSON text. The text is
49
+ canonical, so a replayed turn sends the model the same text: keys are sorted
50
+ and a whole-number float such as `164.0` is written `164`. An integer beyond
51
+ 2**53 in a tool's result or arguments fails the call, because the durable
52
+ record cannot keep it exactly; pass such a value as a string.
53
+
54
+ Each invocation runs one native `Runner` turn and commits it to the
55
+ Orchestration Engine before returning the result. A failed tool call fails
56
+ the turn with the error the platform's tool path reports, such as a tool
57
+ execution error carrying the tool's message or a policy denial; a cancelled or
58
+ user-stopped call fails it too. Nothing is committed in any of these cases.
59
+ When the model calls several tools at once, they run concurrently. Each call
60
+ keeps the Orchestration Engine activity of its call id, and their results reach
61
+ the model in the order the model made the calls, whichever finishes first. If
62
+ one of them waits for approval, the calls that ran before the wait keep their
63
+ outputs ahead of the approved call's, as the SDK records them. When one call
64
+ fails, the turn fails once the calls still running beside it have finished.
65
+ MCP servers, guardrails, agent hooks, hosted prompts, dynamic instructions,
66
+ and a custom `tool_use_behavior` are not supported yet.
67
+
68
+ ## Handoffs
69
+
70
+ Use the SDK's own `handoffs=[...]`, with other agents or `agents.handoff(...)`.
71
+ The runtime reads the whole agent graph the entrypoint returns before each
72
+ turn and holds every reachable agent to the same rules as the first: its model
73
+ comes from `app.llm(...)` (give each agent's model its own `llm_id`) and its
74
+ tools from `app.tools()`, from which each agent can select its own by name.
75
+ Agent names must be unique.
76
+
77
+ A handoff changes which agent is active; the turn stays one execution. The
78
+ committed state records the active agent, so the next turn, also after a
79
+ restart, starts with the agent that ended the last one. An approval requested
80
+ by a handed-off agent suspends and resumes in that agent.
81
+
82
+ `agents.handoff(...)` may override the tool name and description. Agents may
83
+ hand off to each other in a cycle. An `input_filter`, `nest_handoff_history`,
84
+ an `on_handoff` callback, an `input_type`, a callable `is_enabled`, and a
85
+ hand-built `Handoff` fail the turn before any model or tool work. So does a
86
+ handoff on any agent whose tool name matches another handoff's or one of that
87
+ agent's tools: the SDK would otherwise keep one and drop the other.
88
+
89
+ ## Agents as tools
90
+
91
+ Use the SDK's own `Agent.as_tool(...)` and put the result in another agent's
92
+ `tools`. The nested agent follows the same rules as every other agent in the
93
+ graph. Each call runs the nested agent as its own operation: its model and
94
+ tool calls are Orchestration Engine activities under a path named after the
95
+ tool, and repeated or concurrent calls to the same agent tool stay distinct,
96
+ in the order the model made them.
97
+
98
+ The calling agent's model sees only the tool's answer, and only the calling
99
+ conversation is committed; a replacement attempt replays the nested run from
100
+ its recorded activities. The caller's stream carries the nested agent's text
101
+ between `subagent_start` and `subagent_end` events, tagged with the tool name
102
+ and the call id, apart from the calling agent's reply. A nested run that fails
103
+ fails the turn.
104
+
105
+ `max_turns`, `custom_output_extractor`, and structured input are supported. A
106
+ replacement attempt calls the extractor and a structured input's
107
+ `input_builder` again, so both must return the same value for the same input
108
+ and have no side effects; OE fails the turn when a replayed model call differs
109
+ from the recorded one.
110
+
111
+ An `on_stream` callback, `hooks`, a `run_config`, a `session`, provider
112
+ continuation ids, a callable `needs_approval` or `is_enabled`, tool guardrails,
113
+ a native `timeout_seconds`, and an agent that can reach itself through its own
114
+ agent tool fail the turn before any model or tool work. So does a tool that
115
+ needs approval anywhere a nested agent can reach, which is not supported yet;
116
+ approvals in the calling agent work as usual.
117
+
118
+ ## Approvals
119
+
120
+ Register a tool with `@app.tool(needs_approval=True)` to have a person approve
121
+ each call. The argument is the SDK's own `function_tool(needs_approval=...)`,
122
+ passed through to the `FunctionTool` that `app.tools()` returns; setting
123
+ `needs_approval` on that returned tool works too. When the model calls a tool
124
+ that needs approval, the turn suspends: the invocation returns
125
+ `status: suspended` with one interrupt per call waiting for approval, in the
126
+ order the model made the calls, each naming the tool and its arguments. Calls
127
+ in the same response that need no approval run first. Resume through the normal
128
+ invoke endpoint on the same session, with `resume_map` answering every
129
+ interrupt id at once:
130
+
131
+ ```json
132
+ {"resume_map": {"<interrupt id>": {"confirmed": true}}}
133
+ ```
134
+
135
+ `interrupts` lists every pending approval. `suspend_payload` carries only the
136
+ first one's value, for callers that read a single payload.
137
+
138
+ `{"confirmed": false, "rejection_message": "..."}` rejects the call; the model
139
+ sees the rejection message instead of a tool result, as with the SDK's own
140
+ `reject(..., rejection_message=...)`. Without a
141
+ `rejection_message` the model sees the SDK's default rejection text; an empty
142
+ one is refused. An approval
143
+ carries no message. The Orchestration Engine records the wait
144
+ and its answer. Resuming replays the turn from the recorded model calls, applies
145
+ the answer through the SDK's own `RunState`, and runs only what remains, so a
146
+ tool never runs before its approval, prefix output is not repeated, and a
147
+ restart while waiting loses nothing. A resume that leaves any interrupt
148
+ unanswered is refused; `needs_approval` must be `True` or `False`, not a
149
+ callable.
150
+
151
+ ## Durable state
152
+
153
+ Each committed turn stores the Runner's complete input list under the
154
+ `__agent_engine_openai_agents__` state property, together with the app and
155
+ session it belongs to and the name of the agent that ended the turn. The next
156
+ turn continues from that list with that agent. Committed
157
+ messages are an explicit-field projection for history readers; they are not
158
+ read back.
159
+
160
+ Supported items are text messages, function calls, and text function outputs.
161
+ The calls one model response made come together, followed by exactly one
162
+ output per call before anything else. Any other item, any state that belongs
163
+ to a different app or session, and an active agent the app no longer has fail
164
+ the turn before new model or tool work starts.
165
+
166
+ ## Model calls
167
+
168
+ Every model call the native `Runner` makes becomes an Orchestration Engine
169
+ LLM activity. The agent's model answers from the recorded activity, and the
170
+ model itself runs in the Tool Pod. A replacement attempt replays the recorded
171
+ response and gives the `Runner` identical output items.
172
+
173
+ Only per-call settings the platform carries cross that boundary: `max_tokens`,
174
+ `top_p`, `frequency_penalty`, `presence_penalty`, `timeout`,
175
+ `parallel_tool_calls`, `reasoning.effort`, `verbosity`, and a named
176
+ `tool_choice`. Provider settings such as `temperature` belong to the model you
177
+ register, and the Tool Pod applies them. A registered model cannot carry a
178
+ `tool_choice` or `timeout` (set them on the agent), or `extra_body` / `extra_args` fields that make the provider
179
+ continue a stored conversation (`previous_response_id`, `conversation`,
180
+ `conversation_id`, `prompt`) or that override what the adapter builds for
181
+ each call (such as `tools`, `input`, `instructions`, or the output format), or that set
182
+ `reasoning`, `reasoning_effort`, or `verbosity` as raw fields (use `ModelSettings.reasoning` and
183
+ `ModelSettings.verbosity`). Native tracing, provider-hosted
184
+ continuation, and stop sequences fail before the call is sent.
185
+
186
+ ### Reasoning
187
+
188
+ Set `reasoning=Reasoning(effort=...)` and `verbosity` on the registered model,
189
+ on the agent, or both; per-call values win over the registration. Prefer the
190
+ registration. The SDK cannot tell an agent's explicit settings from its own
191
+ defaults: when `Agent(model_settings=...)` equals the SDK's default settings
192
+ (currently `Reasoning(effort="none")` with `verbosity="low"`), the SDK clears
193
+ them at construction and the registered values apply. To use exactly that pair
194
+ per call, assign it after construction (`agent.model_settings = ...`). Other
195
+ reasoning settings, such as `reasoning.summary`, fail before the call is sent.
196
+ Reasoning-token counts are reported in the model call's usage. Providers may
197
+ limit these settings per model and API: for example, a Chat Completions
198
+ reasoning model can refuse function tools unless the effort is `none`. The
199
+ provider's refusal fails the model call.
200
+
201
+ A durable run does not carry a model's hidden reasoning from one model call to
202
+ the next. The provider's encrypted reasoning items are dropped in the Tool Pod
203
+ and never stored, so each call, including each step of a tool loop, reasons
204
+ from the durable conversation alone. If an agent needs a plan that persists
205
+ across calls, it should record the plan explicitly, for example in its own
206
+ messages or in Memory, rather than rely on the model's hidden reasoning.
207
+
208
+ The Tool Pod retries transient provider failures before any output streams.
209
+ The SDK's own `ModelSettings.retry` is rejected: on the agent it would make
210
+ the `Runner` issue extra model activities, and on a registered model it would
211
+ have no effect. A model stream that ends without a completed response fails
212
+ the call rather than being recorded as a truncated answer.