openai-agents-submilli 0.1.0__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.
- openai_agents_submilli-0.1.0/.gitignore +17 -0
- openai_agents_submilli-0.1.0/CHANGELOG.md +24 -0
- openai_agents_submilli-0.1.0/LICENSE +201 -0
- openai_agents_submilli-0.1.0/NOTES.md +181 -0
- openai_agents_submilli-0.1.0/PKG-INFO +245 -0
- openai_agents_submilli-0.1.0/README.md +217 -0
- openai_agents_submilli-0.1.0/pyproject.toml +76 -0
- openai_agents_submilli-0.1.0/src/openai_agents_submilli/__init__.py +31 -0
- openai_agents_submilli-0.1.0/src/openai_agents_submilli/_app_tools.py +196 -0
- openai_agents_submilli-0.1.0/src/openai_agents_submilli/_program.py +297 -0
- openai_agents_submilli-0.1.0/src/openai_agents_submilli/_sessions.py +114 -0
- openai_agents_submilli-0.1.0/src/openai_agents_submilli/_toolkit.py +496 -0
- openai_agents_submilli-0.1.0/src/openai_agents_submilli/_tools.py +263 -0
- openai_agents_submilli-0.1.0/src/openai_agents_submilli/py.typed +0 -0
- openai_agents_submilli-0.1.0/tests/__init__.py +0 -0
- openai_agents_submilli-0.1.0/tests/integration_tests/__init__.py +0 -0
- openai_agents_submilli-0.1.0/tests/integration_tests/conftest.py +108 -0
- openai_agents_submilli-0.1.0/tests/integration_tests/test_server.py +339 -0
- openai_agents_submilli-0.1.0/tests/scripted.py +110 -0
- openai_agents_submilli-0.1.0/tests/unit_tests/__init__.py +0 -0
- openai_agents_submilli-0.1.0/tests/unit_tests/fake_server.py +284 -0
- openai_agents_submilli-0.1.0/tests/unit_tests/test_app_tools.py +270 -0
- openai_agents_submilli-0.1.0/tests/unit_tests/test_toolkit.py +315 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
.venv/
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.pyc
|
|
4
|
+
.pytest_cache/
|
|
5
|
+
.mypy_cache/
|
|
6
|
+
.ruff_cache/
|
|
7
|
+
dist/
|
|
8
|
+
build/
|
|
9
|
+
*.egg-info/
|
|
10
|
+
.submilli-bin/
|
|
11
|
+
|
|
12
|
+
# Local only: model and service keys, the test server's home and token
|
|
13
|
+
.env
|
|
14
|
+
.submilli-test/
|
|
15
|
+
.submilli-test.log
|
|
16
|
+
.submilli-token
|
|
17
|
+
.benchmarks/
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are recorded here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [0.1.0] - 2026-10-30
|
|
8
|
+
|
|
9
|
+
First release, for submilli-server 0.4.1, the `submilli` SDK 0.1.2, and openai-agents 0.24.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `SubmilliTools` for OpenAI Agents SDK agents: the server's six tools as `FunctionTool`s,
|
|
14
|
+
with the Blueprint's descriptions, and one session per conversation, bound to the variables
|
|
15
|
+
and secrets from the run's context.
|
|
16
|
+
- Sessions kept in a `SessionStore`: `InMemorySessionStore` (default) or `SQLiteSessionStore`.
|
|
17
|
+
`aclose_conversation` ends a conversation's session.
|
|
18
|
+
- Retries with an `Idempotency-Key` per tool call. A session that ended is replaced, and the
|
|
19
|
+
model is told. A conversation whose variables changed is refused before the model runs.
|
|
20
|
+
- Execution and session ids, and the program's application-tool calls, in the output item's
|
|
21
|
+
`custom_data`.
|
|
22
|
+
- `ptc` (programmatic tool calling): programs call the application's function tools as
|
|
23
|
+
`@tools`. Each call runs as an SDK tool call, and a tool's `needs_approval` pauses the run
|
|
24
|
+
with a `ToolApprovalItem` for that call, resumed with `RunState.approve` or `reject`.
|
|
@@ -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 [yyyy] [name of copyright owner]
|
|
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,181 @@
|
|
|
1
|
+
# Notes
|
|
2
|
+
|
|
3
|
+
These are the decisions the brief (Linear SUB-2053) left open, and what got in the way. The
|
|
4
|
+
package mirrors `langchain-submilli` where the frameworks allow it; where they differ, this file
|
|
5
|
+
says why. It was built and tested against openai-agents 0.24.0, the `submilli` SDK 0.1.2 from this
|
|
6
|
+
workspace, and submilli-server 0.4.1 and 0.4.3 release binaries.
|
|
7
|
+
|
|
8
|
+
## Decisions
|
|
9
|
+
|
|
10
|
+
### The shape: a toolkit, not middleware
|
|
11
|
+
|
|
12
|
+
The Agents SDK has no middleware. Its extension point for a code-mode harness is a list of
|
|
13
|
+
`FunctionTool`s on `Agent(tools=...)`, so the package is `SubmilliTools`, whose `tools` are the
|
|
14
|
+
server's six tools. Names, arguments, and the result shape are the same as `langchain-submilli`'s:
|
|
15
|
+
the server's own tool names (its responses refer to them), the MCP tools' field descriptions,
|
|
16
|
+
and `result`, `console`, `error`, `denied` (plus `note`, `notice`, `discovery_warnings`) as JSON
|
|
17
|
+
text for the model.
|
|
18
|
+
|
|
19
|
+
- **Strict schemas.** The SDK sends function tools in strict mode by default, where every
|
|
20
|
+
property is required. `packages__search` therefore has a required `query`; its description
|
|
21
|
+
says that `""` lists everything.
|
|
22
|
+
- **Descriptions.** They come from `GET /v1/blueprints/{name}/prompt` before the first model
|
|
23
|
+
call, and are cached for the toolkit. The SDK has no hook before a model call, but it calls a
|
|
24
|
+
tool's `is_enabled` callable (async allowed) on every turn before it reads the tools, so the
|
|
25
|
+
toolkit fetches there and sets the descriptions on its tool objects. Until then each tool has a
|
|
26
|
+
short fallback description. It does not fetch in `__init__`, which would need a blocking
|
|
27
|
+
request while the agent is built.
|
|
28
|
+
- **What the application gets.** LangChain has message artifacts; the SDK has
|
|
29
|
+
`ToolCallOutputItem.custom_data`, filled by a tool's `custom_data_extractor`, which the model
|
|
30
|
+
never sees and `RunState` serializes. It holds `execution_id`, `session_id`, `tool_calls`, and
|
|
31
|
+
on refusals `refusal` or `run_status`, as the LangChain artifact does. Unlike LangChain, the
|
|
32
|
+
model also sees `tool_calls` without their ids, as in `@submilli/ai-sdk`: in a live run with a
|
|
33
|
+
real model, a program that refunded one order and was refused the next left the model unable
|
|
34
|
+
to say which refund had gone through.
|
|
35
|
+
- **Errors.** Application errors raise. Those found in `is_enabled` (a bad token, an unknown
|
|
36
|
+
Blueprint, a variables mismatch) come out of `Runner.run` as they are. Those found while a
|
|
37
|
+
tool runs (invalid variables, a missing conversation id) come out as the cause of the SDK's
|
|
38
|
+
`UserError("Error running tool ...")`, because the SDK wraps every exception a tool raises that
|
|
39
|
+
is not its own. Program failures, denials, idempotency refusals, and lost runs are tool
|
|
40
|
+
results.
|
|
41
|
+
- **Nothing to hide.** The SDK adds no file or shell tools of its own (its hosted and shell tools
|
|
42
|
+
are opt-in), so there is no `hide_filesystem_tools`.
|
|
43
|
+
|
|
44
|
+
### Sessions
|
|
45
|
+
|
|
46
|
+
- **Keyed by a conversation id from the run context.** A tool sees `ToolContext.context`, the
|
|
47
|
+
application's own context object, but not the SDK `Session` the run uses, nor any thread id.
|
|
48
|
+
So the conversation id comes from the context: `conversation_id` by default (key or
|
|
49
|
+
attribute), or a function. Without one, the tool raises `SubmilliConversationError`: falling
|
|
50
|
+
back to a session per process or per context object would silently share sessions, or leak
|
|
51
|
+
one per turn.
|
|
52
|
+
- **Stored in a `SessionStore`.** LangChain keeps the session in checkpointed graph state. The
|
|
53
|
+
SDK has no such state for tools, so the toolkit keeps `{id, server, blueprint, variables,
|
|
54
|
+
tools}` per conversation in a store: `InMemorySessionStore` by default, `SQLiteSessionStore`
|
|
55
|
+
(its own table, which can live in the same file as the SDK's `SQLiteSession`), or the
|
|
56
|
+
application's own implementation of the two-method protocol. Secrets are never stored.
|
|
57
|
+
- **Where the session opens.** Inside the tool, under a per-conversation lock, and it is written
|
|
58
|
+
to the store before any program runs. The SDK does not checkpoint between the model's turn and
|
|
59
|
+
the tools, so there is no earlier point that would survive a crash. A tool call resumed from a
|
|
60
|
+
`RunState` finds the stored session and replays its run with the same key.
|
|
61
|
+
- **Mismatch.** The execute tool's `is_enabled` hook compares the context's variables with the
|
|
62
|
+
stored session's before every model call, and raises `SubmilliSessionMismatchError` before the
|
|
63
|
+
model runs. The tools check again before each call.
|
|
64
|
+
- **Blueprint, server, or catalog change.** A stored session opened for another Blueprint,
|
|
65
|
+
server, or set of application tools is ignored and replaced, as in LangChain.
|
|
66
|
+
- **Closing.** `aclose_conversation(id)` deletes the session and forgets it. Nothing closes a
|
|
67
|
+
session automatically.
|
|
68
|
+
- **Retries.** As in LangChain: `404 unknown session` opens a replacement once per call (calls
|
|
69
|
+
that find the same session gone share one replacement) and tells the model; `409
|
|
70
|
+
session_requires_secrets` rebinds once.
|
|
71
|
+
|
|
72
|
+
### Idempotency
|
|
73
|
+
|
|
74
|
+
The key is `submilli.idempotency_key(ToolContext.tool_call_id)`: the id as is when it is
|
|
75
|
+
printable ASCII of at most 120 bytes, otherwise its sha256. OpenAI's call ids are unique within a
|
|
76
|
+
conversation. The SDK's own model contract requires call ids to be stable and unique for an
|
|
77
|
+
invocation across resumes, which is what the key needs.
|
|
78
|
+
|
|
79
|
+
### Application tools (`ptc`) and approvals
|
|
80
|
+
|
|
81
|
+
This is where the design differs most from LangChain, and it is worth reading before changing
|
|
82
|
+
`_program.py`.
|
|
83
|
+
|
|
84
|
+
- **The problem.** A program suspends at each `@tools` call. The application's tool should run
|
|
85
|
+
as the SDK would run it, with `needs_approval`, guardrails, timeouts, context injection, and
|
|
86
|
+
tracing, and an approval should pause the whole agent run so that a person can decide, possibly
|
|
87
|
+
much later and in another process. The SDK can only pause a run for an approval *before* it
|
|
88
|
+
invokes a tool, judged on the tool call's arguments. A program's calls happen *inside* the
|
|
89
|
+
execute tool, and are not known before it runs. `needs_approval` on the execute tool would
|
|
90
|
+
pause once per program, for the code, not once per call.
|
|
91
|
+
- **The answer: a nested agent whose "model" is the program.** The SDK supports agents used as
|
|
92
|
+
tools (`Agent.as_tool`), and pauses the outer run for approvals inside the nested run: the
|
|
93
|
+
outer `RunResult.interruptions` holds the nested tool's `ToolApprovalItem`, `RunState.approve`
|
|
94
|
+
and `reject` apply to it, and `to_string` / `from_string` serialize the nested state with the
|
|
95
|
+
outer. With application tools, the execute tool is built that way. Its nested agent has the
|
|
96
|
+
`ptc` tools, and its model is `ProgramModel`, which calls no LLM: on each turn it replays the
|
|
97
|
+
execute with the same idempotency key to get the run's current state, answers the calls whose
|
|
98
|
+
outputs the SDK recorded, and either returns a function call for the call the run waits on
|
|
99
|
+
next (with the server's `call_id`), or, when the run has finished, a final message holding the
|
|
100
|
+
execute result. The SDK runs each function call as a normal tool call, approvals included.
|
|
101
|
+
- **Stateless model.** Everything `ProgramModel` needs is in its input: the first message carries
|
|
102
|
+
the code, the session id, and the key, and the SDK's recorded function calls and outputs carry
|
|
103
|
+
the rest. That is what makes a resume in another process work. The session id travels in the
|
|
104
|
+
nested input as well as in the store, so a resumed program finds its run even if the store
|
|
105
|
+
changed.
|
|
106
|
+
- **Always through the nested agent.** With application tools, the nested agent runs the
|
|
107
|
+
program from its first execute on. On a resume, the SDK holds the nested run's pending result
|
|
108
|
+
and expects the agent tool to consume it; returning without it made the SDK raise the same
|
|
109
|
+
approvals again. An earlier version executed once in the outer tool first, which on a resume
|
|
110
|
+
with a lost store started the program again in a new session. Session replacement and secret
|
|
111
|
+
rebinds still happen in the outer tool, which has the run's context: the nested model lets
|
|
112
|
+
`404 unknown session` and `409 session_requires_secrets` propagate on its first turn, and the
|
|
113
|
+
outer tool retries. A `404` after the program has made calls is a lost run, reported to the
|
|
114
|
+
model, never a restart.
|
|
115
|
+
- **A resume without the store** still finishes the program in the session it began in, because
|
|
116
|
+
the nested input names it. The outer tool resolves the conversation's session before handing
|
|
117
|
+
over, so with an empty store it opens a session that this call does not use; later calls in
|
|
118
|
+
the conversation use it.
|
|
119
|
+
- **Tool outputs.** Each `ptc` tool is copied so that its exceptions are raised instead of
|
|
120
|
+
formatted for a model, and its output is wrapped as `{"__submilli_program_call__": "ok",
|
|
121
|
+
value}` or `"failed"`, `message`. Anything else the SDK records in its place, which is the
|
|
122
|
+
approval's rejection message, a guardrail's refusal, or a timeout message, is answered as
|
|
123
|
+
`denied` with that text, so the program throws `PermissionDeniedError`. The copy drops the
|
|
124
|
+
tool's `output_json_schema` and output adapter, which the SDK would check the envelope against
|
|
125
|
+
(the schema is still declared to the server). These are private dataclass fields of
|
|
126
|
+
`FunctionTool` (`_failure_error_function`, `_use_default_failure_error_function`,
|
|
127
|
+
`_output_type_adapter`), set through `dataclasses.replace`. That, and building the execute tool
|
|
128
|
+
from an `as_tool` template so that `RunState.from_string` finds the nested agent through the
|
|
129
|
+
tool's `_agent_instance`, are the package's two dependencies on SDK internals. The dependency
|
|
130
|
+
is pinned below the next minor release, and the tests exercise both paths.
|
|
131
|
+
- **Declaring.** The input schema is the tool's `params_json_schema` (what the model would see,
|
|
132
|
+
without the injected context). The output schema is the tool's `output_json_schema`, else
|
|
133
|
+
the return annotation's through a pydantic `TypeAdapter`, else `string`, where the program gets
|
|
134
|
+
the text the model would get. Local `$ref`s are inlined, because the server's mapper does not
|
|
135
|
+
resolve them.
|
|
136
|
+
- **The nested run's settings.** The SDK passes the outer `RunConfig` to an agent tool unless it
|
|
137
|
+
is given one, and `RunConfig.model` overrides every agent's model, which would send the
|
|
138
|
+
program's turns to an LLM. The nested run gets a `RunConfig` with the outer run's tracing
|
|
139
|
+
settings only. Each program call is one nested turn; `max_turns` is 10,000.
|
|
140
|
+
- **What the model is told.** The execute description gains the same paragraph as in LangChain,
|
|
141
|
+
naming the tools and, when any needs approval, saying that a refusal is final.
|
|
142
|
+
- **Discovery** includes `@tools` through `/v1/sessions/{id}/packages/...` when there are
|
|
143
|
+
application tools, which opens the conversation's session.
|
|
144
|
+
- **Not done: deciding at the call.** LangChain's `interrupt_on` is not mirrored. The SDK's own
|
|
145
|
+
setting on the tool, `needs_approval` (a bool, or an async function of the arguments), already
|
|
146
|
+
says which calls need approval, and it applies unchanged.
|
|
147
|
+
|
|
148
|
+
### Packaging, tests, CI
|
|
149
|
+
|
|
150
|
+
- Name `openai-agents-submilli`, module `openai_agents_submilli`, as `langchain-submilli` is
|
|
151
|
+
named. Apache-2.0, Python 3.11 or later. `openai-agents>=0.24.0,<0.25`: the SDK is below 1.0,
|
|
152
|
+
so a minor release may break, and the package touches the internals named above.
|
|
153
|
+
- Unit tests run the SDK's real `Runner` with a scripted model against the same respx fake of
|
|
154
|
+
the HTTP API as `langchain-submilli` (copied, not shared, so each package's tests stand alone).
|
|
155
|
+
They cover sessions, refusals, replays, approvals (approve, reject, two in one program, a
|
|
156
|
+
serialized `RunState`, and a streamed run), and `run_sync`.
|
|
157
|
+
- Integration tests start their own server from `SUBMILLI_BIN` or `PATH` with Blueprints
|
|
158
|
+
registered over the admin API, so CI runs all of them. They cover typed tools with the run's
|
|
159
|
+
context, the Blueprint refusing a tool, a failing tool, two approvals resumed in "another
|
|
160
|
+
process" (a new toolkit and agent, `RunState.from_string`, a shared `SQLiteSessionStore`),
|
|
161
|
+
a resume without the store, session reuse and isolation, replay, a mismatch, a restart, and an
|
|
162
|
+
expired session.
|
|
163
|
+
- Typing: `mypy --strict`, pyright, and `pyright --verifytypes` at 100%, as for the other
|
|
164
|
+
packages.
|
|
165
|
+
|
|
166
|
+
### What this shares with `langchain-submilli`
|
|
167
|
+
|
|
168
|
+
The model-facing texts (denial note, idempotency and run-state messages) and the session
|
|
169
|
+
policy are the same, copied rather than shared, because they are private to each package. If a
|
|
170
|
+
third integration needs them, they belong in the `submilli` SDK.
|
|
171
|
+
|
|
172
|
+
## What in submilli-runtime got in the way
|
|
173
|
+
|
|
174
|
+
Nothing new. The gaps `langchain-submilli` recorded (SUB-1685..1693) apply unchanged; two matter
|
|
175
|
+
more here:
|
|
176
|
+
|
|
177
|
+
1. **A run's answered calls are not readable.** (as in langchain-submilli's notes) The nested
|
|
178
|
+
model rebuilds a program's progress from the SDK's recorded outputs. A server-side history of
|
|
179
|
+
a run's answered calls would make the records in `custom_data["tool_calls"]` authoritative.
|
|
180
|
+
2. **HTTP execute cannot carry the tool call id** (SUB-1686), so the run's audit record has the
|
|
181
|
+
idempotency key, which is the tool call id unless it was hashed.
|