domino-agui 0.2.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.
- domino_agui-0.2.0/LICENSE +202 -0
- domino_agui-0.2.0/NOTICE +4 -0
- domino_agui-0.2.0/PKG-INFO +239 -0
- domino_agui-0.2.0/README.md +213 -0
- domino_agui-0.2.0/domino_agui/__init__.py +33 -0
- domino_agui-0.2.0/domino_agui/contract.py +243 -0
- domino_agui-0.2.0/domino_agui/convert.py +149 -0
- domino_agui-0.2.0/domino_agui/crewai.py +242 -0
- domino_agui-0.2.0/domino_agui/langgraph.py +221 -0
- domino_agui-0.2.0/domino_agui/loop.py +209 -0
- domino_agui-0.2.0/domino_agui/relay.py +136 -0
- domino_agui-0.2.0/domino_agui/run.py +186 -0
- domino_agui-0.2.0/domino_agui/server.py +75 -0
- domino_agui-0.2.0/domino_agui.egg-info/PKG-INFO +239 -0
- domino_agui-0.2.0/domino_agui.egg-info/SOURCES.txt +17 -0
- domino_agui-0.2.0/domino_agui.egg-info/dependency_links.txt +1 -0
- domino_agui-0.2.0/domino_agui.egg-info/top_level.txt +1 -0
- domino_agui-0.2.0/pyproject.toml +38 -0
- domino_agui-0.2.0/setup.cfg +4 -0
|
@@ -0,0 +1,202 @@
|
|
|
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.
|
|
202
|
+
|
domino_agui-0.2.0/NOTICE
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: domino-agui
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: AG-UI for framework agents on the Domino agent service: a ready-made agent for LangGraph, CrewAI and the Anthropic and OpenAI SDKs, and a standard-library core
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Source, https://github.com/ddl-subir-m/domino-agui
|
|
7
|
+
Project-URL: Issues, https://github.com/ddl-subir-m/domino-agui/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/ddl-subir-m/domino-agui/blob/main/CHANGELOG.md
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Framework :: AsyncIO
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: POSIX
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
License-File: NOTICE
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# domino-agui
|
|
28
|
+
|
|
29
|
+
domino-agui is the helper library for framework agents on the Domino agent service. The agent service runs your agent's code in a
|
|
30
|
+
Domino Job, in a sandbox, and talks to it in [AG-UI](https://docs.ag-ui.com) 1.0. This library speaks AG-UI for your agent, and
|
|
31
|
+
keeps the agent contract: the model, the governed tools, the questions to a person, and the thread.
|
|
32
|
+
|
|
33
|
+
It has three parts:
|
|
34
|
+
|
|
35
|
+
- **A ready-made agent for each framework:** a LangGraph graph, a CrewAI flow, and an agent loop for the Anthropic and OpenAI SDKs.
|
|
36
|
+
Your agent can be one line.
|
|
37
|
+
- **The helpers** that each ready-made agent is made from, for your own graph, flow or loop.
|
|
38
|
+
- **The core,** for a hand-written agent's handler: the server, the run's lifecycle rules, converters for the two model formats,
|
|
39
|
+
and a client for the relay (the agent's governed tools). The core needs only the Python standard library.
|
|
40
|
+
|
|
41
|
+
## Install
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
pip install domino-agui
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Python 3.10 or newer. The core has no dependencies. A framework module imports its framework only when you import that module, so
|
|
48
|
+
install the framework's packages too:
|
|
49
|
+
|
|
50
|
+
| Module | Its packages |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `domino_agui.langgraph` | `langgraph`, `langchain-core`, `langchain-mcp-adapters`, `httpx`, and `langchain-openai` or `langchain-anthropic` for the model |
|
|
53
|
+
| `domino_agui.crewai` | `crewai`, `ag-ui-crewai`, `litellm` |
|
|
54
|
+
| `domino_agui.loop` | `openai`, `anthropic` |
|
|
55
|
+
|
|
56
|
+
On Domino, you don't install anything: the platform's certified Environments have this library and the framework's packages, and
|
|
57
|
+
they pin the framework versions.
|
|
58
|
+
|
|
59
|
+
## Quick start: a ready-made agent
|
|
60
|
+
|
|
61
|
+
Add one file with one line to your project. The agent's entry point is the file, a colon, and the name that the line imports:
|
|
62
|
+
|
|
63
|
+
| Framework | The file's one line | The entry point, for the file `agent/<name>.py` |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| LangGraph | `from domino_agui.langgraph import build_graph` | `agent/graph.py:build_graph` |
|
|
66
|
+
| CrewAI | `from domino_agui.crewai import build_flow` | `agent/flow.py:build_flow` |
|
|
67
|
+
| The loop (Anthropic and OpenAI SDKs) | `from domino_agui.loop import handler` | `agent/handler.py:handler` |
|
|
68
|
+
|
|
69
|
+
In the agent service, give the agent its framework (LangGraph, CrewAI or Domino AG-UI SDK for the loop), the entry point, and the
|
|
70
|
+
certified Environment of the framework.
|
|
71
|
+
|
|
72
|
+
Each ready-made agent does the same things:
|
|
73
|
+
|
|
74
|
+
- It calls the model in `AGENT_MODEL`, in the format of `AGENT_MODEL_FORMAT`, through the Job's model proxy.
|
|
75
|
+
- It offers the model the agent-side tools that the relay lists, and runs them in the same AG-UI run. A denial comes back as the
|
|
76
|
+
tool's answer, and the model reads it.
|
|
77
|
+
- It offers the client-side tools of the run, and doesn't run them. A call to one ends the AG-UI run. The agent service runs the
|
|
78
|
+
tool, and the answer comes back in the next AG-UI run.
|
|
79
|
+
- It offers `ask_human`, the agent's tool for a question to a person. The AG-UI run ends with one interrupt, and the reply is the
|
|
80
|
+
tool's result.
|
|
81
|
+
- It uses the run's context (the agent's system prompt, the platform's operating rules and the task brief) as the model's system
|
|
82
|
+
prompt.
|
|
83
|
+
- It loops until the model's answer has no tool call. That last text is the task's result.
|
|
84
|
+
|
|
85
|
+
## The two options: `model=` and `tools=`
|
|
86
|
+
|
|
87
|
+
Each framework module has `agent()`, which makes its ready-made agent. `build_graph`, `build_flow` and `handler` are `agent()` with no
|
|
88
|
+
options. Two options make another entry point of the same shape:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from domino_agui.loop import agent
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def risk_score(customer_id: str, days: int = 30) -> str:
|
|
95
|
+
"""The customer's risk score for the last `days` days."""
|
|
96
|
+
return f"{customer_id}: low risk in the last {days} days"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
handler = agent(tools=[risk_score])
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**`tools=`** takes your own tools: plain functions (`def` or `async def`), with type hints and a docstring. The LangGraph module also
|
|
103
|
+
takes LangChain tools.
|
|
104
|
+
|
|
105
|
+
- The tool's name is the function's name, its description is the docstring's first paragraph, and its parameters come from the
|
|
106
|
+
type hints: `str`, `int`, `float`, `bool`, `list`, `dict`, `list[X]`, `dict[str, X]`, `Optional[X]` (or `X | None`) and
|
|
107
|
+
`Literal[...]`. A parameter with a default is optional.
|
|
108
|
+
- It returns a `str`, or a value that JSON can encode. An exception is the tool's answer: the model reads it, and the run goes on.
|
|
109
|
+
- It runs in the agent server, in the sandbox. It isn't a gateway tool, so the gateway doesn't decide or audit its calls. A tool that
|
|
110
|
+
needs a decision, an approval or an audit row must be a gateway tool.
|
|
111
|
+
- Its name must be its own. An own tool named `ask_human`, or two own tools with one name, fail when the entry point is built. An
|
|
112
|
+
own tool with the name of a gateway tool or a client-side tool fails the AG-UI run.
|
|
113
|
+
|
|
114
|
+
**`model=`** takes the framework's own model type, with the options of each model call, such as the maximum tokens:
|
|
115
|
+
|
|
116
|
+
| Module | `model=` |
|
|
117
|
+
|---|---|
|
|
118
|
+
| `domino_agui.langgraph` | A LangChain chat model: `ChatOpenAI(model=os.environ["AGENT_MODEL"], use_responses_api=False, max_tokens=1024)` |
|
|
119
|
+
| `domino_agui.crewai` | A LiteLLM model name, `"openai/" + os.environ["AGENT_MODEL"]`, or a `crewai.LLM(model=..., max_tokens=1024)` |
|
|
120
|
+
| `domino_agui.loop` | `Model(AsyncAnthropic(), max_tokens=1024)`, or an SDK client alone: `AsyncOpenAI(max_retries=5)` |
|
|
121
|
+
|
|
122
|
+
The model still goes through the Job's model proxy: the base URL and the key come from the environment. Give `ChatOpenAI`
|
|
123
|
+
`use_responses_api=False`, so that it uses chat completions. To limit the length of an answer, use `max_tokens`. Don't set a
|
|
124
|
+
temperature: a gpt-5 model can refuse a temperature other than 1.
|
|
125
|
+
|
|
126
|
+
## A hand-written handler on the core
|
|
127
|
+
|
|
128
|
+
A handler is `async def handler(run)`. `run` has the AG-UI run's inputs (`run.messages`, the full history; `run.state`;
|
|
129
|
+
`run.resume`; `run.client_tools`; `run.context`) and its outputs (`run.text()`, `run.tool_call()`, `run.client_tool_call()`,
|
|
130
|
+
`run.state_snapshot()`, `run.interrupt()`, `run.finish()`). The library keeps the lifecycle rules: it sends `RUN_STARTED` first and
|
|
131
|
+
one final event last, and a handler that raises ends the run with `RUN_ERROR`.
|
|
132
|
+
|
|
133
|
+
This handler owns its loop. It calls an OpenAI-compatible model through the converters, and runs the gateway tools through the relay:
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from openai import AsyncOpenAI
|
|
137
|
+
|
|
138
|
+
from domino_agui import contract, convert
|
|
139
|
+
|
|
140
|
+
client = AsyncOpenAI() # the base URL and the key come from the environment
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
async def handler(run):
|
|
144
|
+
client_side = {t["name"] for t in run.client_tools}
|
|
145
|
+
tools = run.client_tools + [t for t in await contract.relay_tools() if t["name"] not in client_side]
|
|
146
|
+
system = contract.system_prompt(run.context)
|
|
147
|
+
history = ([{"id": "context", "role": "system", "content": system}] if system else []) + run.messages
|
|
148
|
+
while True:
|
|
149
|
+
completion = await client.chat.completions.create(model=contract.model_alias(), **convert.to_openai(history, tools))
|
|
150
|
+
answer = convert.from_openai(completion)
|
|
151
|
+
history.append(answer.message())
|
|
152
|
+
if answer.text:
|
|
153
|
+
run.text(answer.text)
|
|
154
|
+
for call in answer.tool_calls:
|
|
155
|
+
if call.name in client_side: # the agent service runs it: the call stays open, and the run ends
|
|
156
|
+
run.client_tool_call(call.name, call.arguments, tool_call_id=call.id)
|
|
157
|
+
else: # a gateway tool, through the relay: a denial is an error result, not an exception
|
|
158
|
+
result = await contract.call_tool(call.name, call.arguments)
|
|
159
|
+
run.tool_call(call.name, call.arguments, result.text, tool_call_id=call.id)
|
|
160
|
+
history.append(result.message(call.id))
|
|
161
|
+
if not answer.tool_calls or any(c.name in client_side for c in answer.tool_calls):
|
|
162
|
+
return # the last text is the task's result, or the client-side calls stay open
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
For the Anthropic SDK, use `convert.to_anthropic()` and `convert.from_anthropic()` with `client.messages.create()`. To ask a person,
|
|
166
|
+
end the run with `run.interrupt(question)`: the answer is `run.resume` in the next run. The ready-made loop, `domino_agui.loop`, has
|
|
167
|
+
the whole loop with `ask_human`, and its helpers (`call_model()`, `ask_human()`, `answered_question()`) are public.
|
|
168
|
+
|
|
169
|
+
To try a handler on a laptop, serve it on a Unix socket and post an AG-UI run to it:
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
python -c 'import domino_agui, my_agent; domino_agui.serve(my_agent.handler, "agent.sock")' &
|
|
173
|
+
curl -sN --unix-socket agent.sock http://agent/agent -H 'Content-Type: application/json' \
|
|
174
|
+
-d '{"threadId": "t1", "runId": "r1", "messages": [{"id": "m1", "role": "user", "content": "Say hello in five words."}]}'
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
The answer is the run's AG-UI events, one per `data:` line.
|
|
178
|
+
|
|
179
|
+
## The agent contract
|
|
180
|
+
|
|
181
|
+
The platform sets these variables in the agent server's environment, in a Job:
|
|
182
|
+
|
|
183
|
+
| Variable | What it is |
|
|
184
|
+
|---|---|
|
|
185
|
+
| `AGENT_MODEL` | The model's alias at the model gateway. The ready-made agents call this model. |
|
|
186
|
+
| `AGENT_MODEL_FORMAT` | The model's format: `anthropic` (Anthropic Messages), else `openai` (OpenAI chat completions, which OpenAI-compatible models speak too). |
|
|
187
|
+
| `AGENT_SERVICE_URL` | The agent service. Its relay is MCP at `$AGENT_SERVICE_URL/mcp`: the agent-side tools. Not set outside a Job, so there are no agent-side tools on a laptop. |
|
|
188
|
+
| `SESSION_TOKEN` | The relay's bearer token for this Job. |
|
|
189
|
+
| `AGENT_FRAMEWORK` | The framework of the Environment. A framework module of another framework fails at its import, with an error that names the Environment to use. Not set on a laptop. |
|
|
190
|
+
|
|
191
|
+
The platform also sets each model SDK's base URL and key, so that each model call goes through the Job's model proxy and the model
|
|
192
|
+
gateway. On a laptop, set `AGENT_MODEL`, `AGENT_MODEL_FORMAT` and your provider's key.
|
|
193
|
+
|
|
194
|
+
The relay's rules:
|
|
195
|
+
|
|
196
|
+
- Each relay call goes through the gateway's decision and audit. A denial or a failed call is a result with `is_error`, for the
|
|
197
|
+
model to read. A `RelayError` means that the relay itself failed.
|
|
198
|
+
- The relay client of the ready-made agents connects within 30 seconds (`contract.CONNECT_TIMEOUT`), and waits up to 300 seconds
|
|
199
|
+
for each answer (`contract.READ_TIMEOUT`). A relay call can stay open for up to 45 seconds, so keep a read timeout of 60 seconds or
|
|
200
|
+
more. `Relay(url=None, token=None, *, timeout=120, read_timeout=None)`: `timeout` is the time to connect, and to wait for each
|
|
201
|
+
answer unless `read_timeout` is given.
|
|
202
|
+
- The relay client connects to the relay directly, never through the egress proxy in `HTTP_PROXY`.
|
|
203
|
+
|
|
204
|
+
The run's rules:
|
|
205
|
+
|
|
206
|
+
- Each AG-UI run brings the full history and the last state. The agent server keeps nothing between runs: the agent service keeps
|
|
207
|
+
the thread.
|
|
208
|
+
- A run ends with one interrupt at most, and an interrupt is a question, never an approval. A resume is `resolved`, with the reply
|
|
209
|
+
text, or `cancelled`, when the answer came after the question's `expiresAt`.
|
|
210
|
+
- A run with open client-side calls ends as a success that names them. Their answers are tool messages in the next run.
|
|
211
|
+
- The agent server listens on a Unix socket: `POST /agent` takes a `RunAgentInput` and answers with server-sent events, and
|
|
212
|
+
`GET /health` answers `{ok, framework, versions}`.
|
|
213
|
+
|
|
214
|
+
## Versions
|
|
215
|
+
|
|
216
|
+
The versions follow [semantic versioning](https://semver.org). The changes are in
|
|
217
|
+
[CHANGELOG.md](https://github.com/ddl-subir-m/domino-agui/blob/main/CHANGELOG.md).
|
|
218
|
+
|
|
219
|
+
## Report a problem
|
|
220
|
+
|
|
221
|
+
Open an issue on [GitHub](https://github.com/ddl-subir-m/domino-agui/issues). For a security problem, don't open an issue: read
|
|
222
|
+
[SECURITY.md](https://github.com/ddl-subir-m/domino-agui/blob/main/SECURITY.md).
|
|
223
|
+
|
|
224
|
+
## The checks
|
|
225
|
+
|
|
226
|
+
The checks need only the standard library. Most of them run against the installed package; `check_text.py` reads the repo's text:
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
pip install .
|
|
230
|
+
python tests/check_domino_agui.py
|
|
231
|
+
python tests/check_docstrings.py
|
|
232
|
+
python tests/check_release_tag.py
|
|
233
|
+
python tests/check_text.py
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## License
|
|
237
|
+
|
|
238
|
+
Apache License 2.0. Copyright Domino Data Lab, Inc. See [LICENSE](https://github.com/ddl-subir-m/domino-agui/blob/main/LICENSE)
|
|
239
|
+
and [NOTICE](https://github.com/ddl-subir-m/domino-agui/blob/main/NOTICE).
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# domino-agui
|
|
2
|
+
|
|
3
|
+
domino-agui is the helper library for framework agents on the Domino agent service. The agent service runs your agent's code in a
|
|
4
|
+
Domino Job, in a sandbox, and talks to it in [AG-UI](https://docs.ag-ui.com) 1.0. This library speaks AG-UI for your agent, and
|
|
5
|
+
keeps the agent contract: the model, the governed tools, the questions to a person, and the thread.
|
|
6
|
+
|
|
7
|
+
It has three parts:
|
|
8
|
+
|
|
9
|
+
- **A ready-made agent for each framework:** a LangGraph graph, a CrewAI flow, and an agent loop for the Anthropic and OpenAI SDKs.
|
|
10
|
+
Your agent can be one line.
|
|
11
|
+
- **The helpers** that each ready-made agent is made from, for your own graph, flow or loop.
|
|
12
|
+
- **The core,** for a hand-written agent's handler: the server, the run's lifecycle rules, converters for the two model formats,
|
|
13
|
+
and a client for the relay (the agent's governed tools). The core needs only the Python standard library.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
pip install domino-agui
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Python 3.10 or newer. The core has no dependencies. A framework module imports its framework only when you import that module, so
|
|
22
|
+
install the framework's packages too:
|
|
23
|
+
|
|
24
|
+
| Module | Its packages |
|
|
25
|
+
|---|---|
|
|
26
|
+
| `domino_agui.langgraph` | `langgraph`, `langchain-core`, `langchain-mcp-adapters`, `httpx`, and `langchain-openai` or `langchain-anthropic` for the model |
|
|
27
|
+
| `domino_agui.crewai` | `crewai`, `ag-ui-crewai`, `litellm` |
|
|
28
|
+
| `domino_agui.loop` | `openai`, `anthropic` |
|
|
29
|
+
|
|
30
|
+
On Domino, you don't install anything: the platform's certified Environments have this library and the framework's packages, and
|
|
31
|
+
they pin the framework versions.
|
|
32
|
+
|
|
33
|
+
## Quick start: a ready-made agent
|
|
34
|
+
|
|
35
|
+
Add one file with one line to your project. The agent's entry point is the file, a colon, and the name that the line imports:
|
|
36
|
+
|
|
37
|
+
| Framework | The file's one line | The entry point, for the file `agent/<name>.py` |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| LangGraph | `from domino_agui.langgraph import build_graph` | `agent/graph.py:build_graph` |
|
|
40
|
+
| CrewAI | `from domino_agui.crewai import build_flow` | `agent/flow.py:build_flow` |
|
|
41
|
+
| The loop (Anthropic and OpenAI SDKs) | `from domino_agui.loop import handler` | `agent/handler.py:handler` |
|
|
42
|
+
|
|
43
|
+
In the agent service, give the agent its framework (LangGraph, CrewAI or Domino AG-UI SDK for the loop), the entry point, and the
|
|
44
|
+
certified Environment of the framework.
|
|
45
|
+
|
|
46
|
+
Each ready-made agent does the same things:
|
|
47
|
+
|
|
48
|
+
- It calls the model in `AGENT_MODEL`, in the format of `AGENT_MODEL_FORMAT`, through the Job's model proxy.
|
|
49
|
+
- It offers the model the agent-side tools that the relay lists, and runs them in the same AG-UI run. A denial comes back as the
|
|
50
|
+
tool's answer, and the model reads it.
|
|
51
|
+
- It offers the client-side tools of the run, and doesn't run them. A call to one ends the AG-UI run. The agent service runs the
|
|
52
|
+
tool, and the answer comes back in the next AG-UI run.
|
|
53
|
+
- It offers `ask_human`, the agent's tool for a question to a person. The AG-UI run ends with one interrupt, and the reply is the
|
|
54
|
+
tool's result.
|
|
55
|
+
- It uses the run's context (the agent's system prompt, the platform's operating rules and the task brief) as the model's system
|
|
56
|
+
prompt.
|
|
57
|
+
- It loops until the model's answer has no tool call. That last text is the task's result.
|
|
58
|
+
|
|
59
|
+
## The two options: `model=` and `tools=`
|
|
60
|
+
|
|
61
|
+
Each framework module has `agent()`, which makes its ready-made agent. `build_graph`, `build_flow` and `handler` are `agent()` with no
|
|
62
|
+
options. Two options make another entry point of the same shape:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from domino_agui.loop import agent
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def risk_score(customer_id: str, days: int = 30) -> str:
|
|
69
|
+
"""The customer's risk score for the last `days` days."""
|
|
70
|
+
return f"{customer_id}: low risk in the last {days} days"
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
handler = agent(tools=[risk_score])
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**`tools=`** takes your own tools: plain functions (`def` or `async def`), with type hints and a docstring. The LangGraph module also
|
|
77
|
+
takes LangChain tools.
|
|
78
|
+
|
|
79
|
+
- The tool's name is the function's name, its description is the docstring's first paragraph, and its parameters come from the
|
|
80
|
+
type hints: `str`, `int`, `float`, `bool`, `list`, `dict`, `list[X]`, `dict[str, X]`, `Optional[X]` (or `X | None`) and
|
|
81
|
+
`Literal[...]`. A parameter with a default is optional.
|
|
82
|
+
- It returns a `str`, or a value that JSON can encode. An exception is the tool's answer: the model reads it, and the run goes on.
|
|
83
|
+
- It runs in the agent server, in the sandbox. It isn't a gateway tool, so the gateway doesn't decide or audit its calls. A tool that
|
|
84
|
+
needs a decision, an approval or an audit row must be a gateway tool.
|
|
85
|
+
- Its name must be its own. An own tool named `ask_human`, or two own tools with one name, fail when the entry point is built. An
|
|
86
|
+
own tool with the name of a gateway tool or a client-side tool fails the AG-UI run.
|
|
87
|
+
|
|
88
|
+
**`model=`** takes the framework's own model type, with the options of each model call, such as the maximum tokens:
|
|
89
|
+
|
|
90
|
+
| Module | `model=` |
|
|
91
|
+
|---|---|
|
|
92
|
+
| `domino_agui.langgraph` | A LangChain chat model: `ChatOpenAI(model=os.environ["AGENT_MODEL"], use_responses_api=False, max_tokens=1024)` |
|
|
93
|
+
| `domino_agui.crewai` | A LiteLLM model name, `"openai/" + os.environ["AGENT_MODEL"]`, or a `crewai.LLM(model=..., max_tokens=1024)` |
|
|
94
|
+
| `domino_agui.loop` | `Model(AsyncAnthropic(), max_tokens=1024)`, or an SDK client alone: `AsyncOpenAI(max_retries=5)` |
|
|
95
|
+
|
|
96
|
+
The model still goes through the Job's model proxy: the base URL and the key come from the environment. Give `ChatOpenAI`
|
|
97
|
+
`use_responses_api=False`, so that it uses chat completions. To limit the length of an answer, use `max_tokens`. Don't set a
|
|
98
|
+
temperature: a gpt-5 model can refuse a temperature other than 1.
|
|
99
|
+
|
|
100
|
+
## A hand-written handler on the core
|
|
101
|
+
|
|
102
|
+
A handler is `async def handler(run)`. `run` has the AG-UI run's inputs (`run.messages`, the full history; `run.state`;
|
|
103
|
+
`run.resume`; `run.client_tools`; `run.context`) and its outputs (`run.text()`, `run.tool_call()`, `run.client_tool_call()`,
|
|
104
|
+
`run.state_snapshot()`, `run.interrupt()`, `run.finish()`). The library keeps the lifecycle rules: it sends `RUN_STARTED` first and
|
|
105
|
+
one final event last, and a handler that raises ends the run with `RUN_ERROR`.
|
|
106
|
+
|
|
107
|
+
This handler owns its loop. It calls an OpenAI-compatible model through the converters, and runs the gateway tools through the relay:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from openai import AsyncOpenAI
|
|
111
|
+
|
|
112
|
+
from domino_agui import contract, convert
|
|
113
|
+
|
|
114
|
+
client = AsyncOpenAI() # the base URL and the key come from the environment
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
async def handler(run):
|
|
118
|
+
client_side = {t["name"] for t in run.client_tools}
|
|
119
|
+
tools = run.client_tools + [t for t in await contract.relay_tools() if t["name"] not in client_side]
|
|
120
|
+
system = contract.system_prompt(run.context)
|
|
121
|
+
history = ([{"id": "context", "role": "system", "content": system}] if system else []) + run.messages
|
|
122
|
+
while True:
|
|
123
|
+
completion = await client.chat.completions.create(model=contract.model_alias(), **convert.to_openai(history, tools))
|
|
124
|
+
answer = convert.from_openai(completion)
|
|
125
|
+
history.append(answer.message())
|
|
126
|
+
if answer.text:
|
|
127
|
+
run.text(answer.text)
|
|
128
|
+
for call in answer.tool_calls:
|
|
129
|
+
if call.name in client_side: # the agent service runs it: the call stays open, and the run ends
|
|
130
|
+
run.client_tool_call(call.name, call.arguments, tool_call_id=call.id)
|
|
131
|
+
else: # a gateway tool, through the relay: a denial is an error result, not an exception
|
|
132
|
+
result = await contract.call_tool(call.name, call.arguments)
|
|
133
|
+
run.tool_call(call.name, call.arguments, result.text, tool_call_id=call.id)
|
|
134
|
+
history.append(result.message(call.id))
|
|
135
|
+
if not answer.tool_calls or any(c.name in client_side for c in answer.tool_calls):
|
|
136
|
+
return # the last text is the task's result, or the client-side calls stay open
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
For the Anthropic SDK, use `convert.to_anthropic()` and `convert.from_anthropic()` with `client.messages.create()`. To ask a person,
|
|
140
|
+
end the run with `run.interrupt(question)`: the answer is `run.resume` in the next run. The ready-made loop, `domino_agui.loop`, has
|
|
141
|
+
the whole loop with `ask_human`, and its helpers (`call_model()`, `ask_human()`, `answered_question()`) are public.
|
|
142
|
+
|
|
143
|
+
To try a handler on a laptop, serve it on a Unix socket and post an AG-UI run to it:
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
python -c 'import domino_agui, my_agent; domino_agui.serve(my_agent.handler, "agent.sock")' &
|
|
147
|
+
curl -sN --unix-socket agent.sock http://agent/agent -H 'Content-Type: application/json' \
|
|
148
|
+
-d '{"threadId": "t1", "runId": "r1", "messages": [{"id": "m1", "role": "user", "content": "Say hello in five words."}]}'
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
The answer is the run's AG-UI events, one per `data:` line.
|
|
152
|
+
|
|
153
|
+
## The agent contract
|
|
154
|
+
|
|
155
|
+
The platform sets these variables in the agent server's environment, in a Job:
|
|
156
|
+
|
|
157
|
+
| Variable | What it is |
|
|
158
|
+
|---|---|
|
|
159
|
+
| `AGENT_MODEL` | The model's alias at the model gateway. The ready-made agents call this model. |
|
|
160
|
+
| `AGENT_MODEL_FORMAT` | The model's format: `anthropic` (Anthropic Messages), else `openai` (OpenAI chat completions, which OpenAI-compatible models speak too). |
|
|
161
|
+
| `AGENT_SERVICE_URL` | The agent service. Its relay is MCP at `$AGENT_SERVICE_URL/mcp`: the agent-side tools. Not set outside a Job, so there are no agent-side tools on a laptop. |
|
|
162
|
+
| `SESSION_TOKEN` | The relay's bearer token for this Job. |
|
|
163
|
+
| `AGENT_FRAMEWORK` | The framework of the Environment. A framework module of another framework fails at its import, with an error that names the Environment to use. Not set on a laptop. |
|
|
164
|
+
|
|
165
|
+
The platform also sets each model SDK's base URL and key, so that each model call goes through the Job's model proxy and the model
|
|
166
|
+
gateway. On a laptop, set `AGENT_MODEL`, `AGENT_MODEL_FORMAT` and your provider's key.
|
|
167
|
+
|
|
168
|
+
The relay's rules:
|
|
169
|
+
|
|
170
|
+
- Each relay call goes through the gateway's decision and audit. A denial or a failed call is a result with `is_error`, for the
|
|
171
|
+
model to read. A `RelayError` means that the relay itself failed.
|
|
172
|
+
- The relay client of the ready-made agents connects within 30 seconds (`contract.CONNECT_TIMEOUT`), and waits up to 300 seconds
|
|
173
|
+
for each answer (`contract.READ_TIMEOUT`). A relay call can stay open for up to 45 seconds, so keep a read timeout of 60 seconds or
|
|
174
|
+
more. `Relay(url=None, token=None, *, timeout=120, read_timeout=None)`: `timeout` is the time to connect, and to wait for each
|
|
175
|
+
answer unless `read_timeout` is given.
|
|
176
|
+
- The relay client connects to the relay directly, never through the egress proxy in `HTTP_PROXY`.
|
|
177
|
+
|
|
178
|
+
The run's rules:
|
|
179
|
+
|
|
180
|
+
- Each AG-UI run brings the full history and the last state. The agent server keeps nothing between runs: the agent service keeps
|
|
181
|
+
the thread.
|
|
182
|
+
- A run ends with one interrupt at most, and an interrupt is a question, never an approval. A resume is `resolved`, with the reply
|
|
183
|
+
text, or `cancelled`, when the answer came after the question's `expiresAt`.
|
|
184
|
+
- A run with open client-side calls ends as a success that names them. Their answers are tool messages in the next run.
|
|
185
|
+
- The agent server listens on a Unix socket: `POST /agent` takes a `RunAgentInput` and answers with server-sent events, and
|
|
186
|
+
`GET /health` answers `{ok, framework, versions}`.
|
|
187
|
+
|
|
188
|
+
## Versions
|
|
189
|
+
|
|
190
|
+
The versions follow [semantic versioning](https://semver.org). The changes are in
|
|
191
|
+
[CHANGELOG.md](https://github.com/ddl-subir-m/domino-agui/blob/main/CHANGELOG.md).
|
|
192
|
+
|
|
193
|
+
## Report a problem
|
|
194
|
+
|
|
195
|
+
Open an issue on [GitHub](https://github.com/ddl-subir-m/domino-agui/issues). For a security problem, don't open an issue: read
|
|
196
|
+
[SECURITY.md](https://github.com/ddl-subir-m/domino-agui/blob/main/SECURITY.md).
|
|
197
|
+
|
|
198
|
+
## The checks
|
|
199
|
+
|
|
200
|
+
The checks need only the standard library. Most of them run against the installed package; `check_text.py` reads the repo's text:
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
pip install .
|
|
204
|
+
python tests/check_domino_agui.py
|
|
205
|
+
python tests/check_docstrings.py
|
|
206
|
+
python tests/check_release_tag.py
|
|
207
|
+
python tests/check_text.py
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
Apache License 2.0. Copyright Domino Data Lab, Inc. See [LICENSE](https://github.com/ddl-subir-m/domino-agui/blob/main/LICENSE)
|
|
213
|
+
and [NOTICE](https://github.com/ddl-subir-m/domino-agui/blob/main/NOTICE).
|