bringyourownagent 0.0.1__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.
- bringyourownagent-0.0.1/.gitignore +8 -0
- bringyourownagent-0.0.1/LICENSE +202 -0
- bringyourownagent-0.0.1/PKG-INFO +118 -0
- bringyourownagent-0.0.1/README.md +90 -0
- bringyourownagent-0.0.1/pyproject.toml +48 -0
- bringyourownagent-0.0.1/src/bringyourownagent/__init__.py +59 -0
- bringyourownagent-0.0.1/src/bringyourownagent/__main__.py +8 -0
- bringyourownagent-0.0.1/src/bringyourownagent/_common.py +97 -0
- bringyourownagent-0.0.1/src/bringyourownagent/_money.py +52 -0
- bringyourownagent-0.0.1/src/bringyourownagent/_time.py +62 -0
- bringyourownagent-0.0.1/src/bringyourownagent/_version.py +1 -0
- bringyourownagent-0.0.1/src/bringyourownagent/cli.py +203 -0
- bringyourownagent-0.0.1/src/bringyourownagent/gate.py +618 -0
- bringyourownagent-0.0.1/src/bringyourownagent/manifest.py +240 -0
- bringyourownagent-0.0.1/src/bringyourownagent/py.typed +0 -0
- bringyourownagent-0.0.1/src/bringyourownagent/rules.py +65 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: bringyourownagent
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Early draft reference implementation of BYOA (Bring Your Own Agent): manifest validation and the call gate.
|
|
5
|
+
Project-URL: Homepage, https://bringyourownagent.org
|
|
6
|
+
Project-URL: Repository, https://github.com/bringyourownagent/bringyourownagent
|
|
7
|
+
Project-URL: Source, https://github.com/bringyourownagent/bringyourownagent/tree/main/sdk/python
|
|
8
|
+
Project-URL: Rules, https://github.com/bringyourownagent/bringyourownagent/blob/main/spec/rules-0.1-draft.md
|
|
9
|
+
Project-URL: Issues, https://github.com/bringyourownagent/bringyourownagent/issues
|
|
10
|
+
Author-email: ultrathinker <universeissilent42@gmail.com>
|
|
11
|
+
License-Expression: Apache-2.0
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: agent-wallet,agents,ai,bring-your-own-agent,byoa,grant,local-models,manifest,protocol
|
|
14
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# bringyourownagent (Python)
|
|
30
|
+
|
|
31
|
+
This is an early draft implementation of **BYOA (Bring Your Own Agent)**, an open protocol that lets websites and apps use the visitor's own AI agents (their subscriptions, API keys, connected accounts, local models or home servers) within limits the visitor sets. Version 0.0.1 implements only the first rules: it checks a requester's **manifest**, and it decides whether one **call** may go ahead under the visitor's **grant**. The rules are a [draft for discussion](https://github.com/bringyourownagent/bringyourownagent/blob/main/spec/rules-0.1-draft.md) and will change. Python 3.9 or newer, standard library only, no dependencies.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
pip install bringyourownagent
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The distribution, the package you import and the command are all named `bringyourownagent`.
|
|
40
|
+
|
|
41
|
+
## Example
|
|
42
|
+
|
|
43
|
+
With the manifest shown on the BYOA site ([`sdk/examples/manifest.json`](https://github.com/bringyourownagent/bringyourownagent/blob/main/sdk/examples/manifest.json): a family geography game, voice clips up to 15 seconds):
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import json
|
|
47
|
+
from bringyourownagent import check_call, validate_manifest
|
|
48
|
+
|
|
49
|
+
manifest = json.load(open("manifest.json"))
|
|
50
|
+
print(validate_manifest(manifest)["ok"]) # True
|
|
51
|
+
|
|
52
|
+
grant = {"byoa": "0.1-draft", "skills": ["audio.transcribe"],
|
|
53
|
+
"budget": {"perSession": "0.20 USD"}, "expiresAt": "2026-10-10T13:00:00Z"}
|
|
54
|
+
call = {"skill": "audio.transcribe", "at": "2026-10-10T12:00:00Z", "provider": "local-model",
|
|
55
|
+
"estimatedCost": "0 USD", "input": {"clipSeconds": 42}}
|
|
56
|
+
result = check_call(manifest, grant, call, {"spent": "0.04 USD"})
|
|
57
|
+
print(result["decision"], result["reasons"][0]["code"]) # blocked clip-too-long
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
- `validate_manifest(manifest)` returns `{"ok", "errors", "warnings"}`; each item is `{"code", "path", "message"}` with a stable code and a JSON Pointer path. Problems are returned as data, never raised.
|
|
61
|
+
- `check_call(manifest, grant, call, state=None)` returns `{"decision", "reasons"}`. The decision is one of `allowed`, `warn`, `ask`, `blocked`; each reason has a stable code. Invalid input blocks the call instead of raising.
|
|
62
|
+
- While a limit or warning needs a measurement, the call must state it: `input.clipSeconds` under a clip limit, `input.textChars` under a text limit or a "warn me if it sends text" condition. Use `0` when there is no such input; a missing value blocks the call.
|
|
63
|
+
- `check_call` only evaluates. Your wallet runs the call, then records its time and real cost in the state, and must not check two calls of one grant against the same state at once (see "Execution contract" in the rules).
|
|
64
|
+
- Money is handled as `Decimal`, never as float: `"0.1 USD"` plus `"0.2 USD"` fits a budget of `"0.3 USD"` exactly.
|
|
65
|
+
|
|
66
|
+
## The purpose judge hook
|
|
67
|
+
|
|
68
|
+
The hard limits are checked by code. Judging whether a call fits the declared purpose in words needs a model, and is not part of this library. It plugs in as a judge that returns an opinion (`{"decision", "code", "message"}`) or `None`. An opinion can only make the decision stricter; a judge that fails, returns something else or is not callable gives `ask`.
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
result = check_call(manifest, grant, call, state, judge=my_sync_judge)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
A judge that calls a model is usually asynchronous. Check first, and ask the judge only if the call is not already blocked:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from bringyourownagent import apply_opinion, check_call
|
|
78
|
+
|
|
79
|
+
async def decide(manifest, grant, call, state):
|
|
80
|
+
result = check_call(manifest, grant, call, state)
|
|
81
|
+
if result["decision"] == "blocked":
|
|
82
|
+
return result
|
|
83
|
+
try:
|
|
84
|
+
opinion = await my_async_judge(manifest, grant, call)
|
|
85
|
+
except Exception:
|
|
86
|
+
opinion = {"decision": "ask", "code": "purpose-judge-error", "message": "the purpose judge failed"}
|
|
87
|
+
return apply_opinion(result, opinion)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Command line
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
bringyourownagent validate manifest.json
|
|
94
|
+
bringyourownagent check --manifest manifest.json --grant grant.json --call call.json [--state state.json]
|
|
95
|
+
bringyourownagent check --json ... # machine-readable output
|
|
96
|
+
python -m bringyourownagent --help # the same tool
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Exit codes: `0` the manifest is valid or the call may proceed (`allowed`, `warn`); `1` the manifest is invalid or the call may not proceed (`ask`, `blocked`); `2` usage error or unreadable input. Example files are in [`sdk/examples/`](https://github.com/bringyourownagent/bringyourownagent/tree/main/sdk/examples).
|
|
100
|
+
|
|
101
|
+
## Development
|
|
102
|
+
|
|
103
|
+
The tests include the shared test vectors in `sdk/test-vectors/`, which the Node.js package must pass identically. From `sdk/python/` in the repository:
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
python -m unittest discover -s tests -t tests
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Links
|
|
110
|
+
|
|
111
|
+
- Website: <https://bringyourownagent.org>
|
|
112
|
+
- Repository: <https://github.com/bringyourownagent/bringyourownagent>
|
|
113
|
+
- Rules implemented here (draft): [spec/rules-0.1-draft.md](https://github.com/bringyourownagent/bringyourownagent/blob/main/spec/rules-0.1-draft.md)
|
|
114
|
+
- Node.js package with the same rules: [`bringyourownagent` on npm](https://www.npmjs.com/package/bringyourownagent)
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
[Apache License 2.0](LICENSE).
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# bringyourownagent (Python)
|
|
2
|
+
|
|
3
|
+
This is an early draft implementation of **BYOA (Bring Your Own Agent)**, an open protocol that lets websites and apps use the visitor's own AI agents (their subscriptions, API keys, connected accounts, local models or home servers) within limits the visitor sets. Version 0.0.1 implements only the first rules: it checks a requester's **manifest**, and it decides whether one **call** may go ahead under the visitor's **grant**. The rules are a [draft for discussion](https://github.com/bringyourownagent/bringyourownagent/blob/main/spec/rules-0.1-draft.md) and will change. Python 3.9 or newer, standard library only, no dependencies.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pip install bringyourownagent
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The distribution, the package you import and the command are all named `bringyourownagent`.
|
|
12
|
+
|
|
13
|
+
## Example
|
|
14
|
+
|
|
15
|
+
With the manifest shown on the BYOA site ([`sdk/examples/manifest.json`](https://github.com/bringyourownagent/bringyourownagent/blob/main/sdk/examples/manifest.json): a family geography game, voice clips up to 15 seconds):
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
import json
|
|
19
|
+
from bringyourownagent import check_call, validate_manifest
|
|
20
|
+
|
|
21
|
+
manifest = json.load(open("manifest.json"))
|
|
22
|
+
print(validate_manifest(manifest)["ok"]) # True
|
|
23
|
+
|
|
24
|
+
grant = {"byoa": "0.1-draft", "skills": ["audio.transcribe"],
|
|
25
|
+
"budget": {"perSession": "0.20 USD"}, "expiresAt": "2026-10-10T13:00:00Z"}
|
|
26
|
+
call = {"skill": "audio.transcribe", "at": "2026-10-10T12:00:00Z", "provider": "local-model",
|
|
27
|
+
"estimatedCost": "0 USD", "input": {"clipSeconds": 42}}
|
|
28
|
+
result = check_call(manifest, grant, call, {"spent": "0.04 USD"})
|
|
29
|
+
print(result["decision"], result["reasons"][0]["code"]) # blocked clip-too-long
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- `validate_manifest(manifest)` returns `{"ok", "errors", "warnings"}`; each item is `{"code", "path", "message"}` with a stable code and a JSON Pointer path. Problems are returned as data, never raised.
|
|
33
|
+
- `check_call(manifest, grant, call, state=None)` returns `{"decision", "reasons"}`. The decision is one of `allowed`, `warn`, `ask`, `blocked`; each reason has a stable code. Invalid input blocks the call instead of raising.
|
|
34
|
+
- While a limit or warning needs a measurement, the call must state it: `input.clipSeconds` under a clip limit, `input.textChars` under a text limit or a "warn me if it sends text" condition. Use `0` when there is no such input; a missing value blocks the call.
|
|
35
|
+
- `check_call` only evaluates. Your wallet runs the call, then records its time and real cost in the state, and must not check two calls of one grant against the same state at once (see "Execution contract" in the rules).
|
|
36
|
+
- Money is handled as `Decimal`, never as float: `"0.1 USD"` plus `"0.2 USD"` fits a budget of `"0.3 USD"` exactly.
|
|
37
|
+
|
|
38
|
+
## The purpose judge hook
|
|
39
|
+
|
|
40
|
+
The hard limits are checked by code. Judging whether a call fits the declared purpose in words needs a model, and is not part of this library. It plugs in as a judge that returns an opinion (`{"decision", "code", "message"}`) or `None`. An opinion can only make the decision stricter; a judge that fails, returns something else or is not callable gives `ask`.
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
result = check_call(manifest, grant, call, state, judge=my_sync_judge)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
A judge that calls a model is usually asynchronous. Check first, and ask the judge only if the call is not already blocked:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from bringyourownagent import apply_opinion, check_call
|
|
50
|
+
|
|
51
|
+
async def decide(manifest, grant, call, state):
|
|
52
|
+
result = check_call(manifest, grant, call, state)
|
|
53
|
+
if result["decision"] == "blocked":
|
|
54
|
+
return result
|
|
55
|
+
try:
|
|
56
|
+
opinion = await my_async_judge(manifest, grant, call)
|
|
57
|
+
except Exception:
|
|
58
|
+
opinion = {"decision": "ask", "code": "purpose-judge-error", "message": "the purpose judge failed"}
|
|
59
|
+
return apply_opinion(result, opinion)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Command line
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
bringyourownagent validate manifest.json
|
|
66
|
+
bringyourownagent check --manifest manifest.json --grant grant.json --call call.json [--state state.json]
|
|
67
|
+
bringyourownagent check --json ... # machine-readable output
|
|
68
|
+
python -m bringyourownagent --help # the same tool
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Exit codes: `0` the manifest is valid or the call may proceed (`allowed`, `warn`); `1` the manifest is invalid or the call may not proceed (`ask`, `blocked`); `2` usage error or unreadable input. Example files are in [`sdk/examples/`](https://github.com/bringyourownagent/bringyourownagent/tree/main/sdk/examples).
|
|
72
|
+
|
|
73
|
+
## Development
|
|
74
|
+
|
|
75
|
+
The tests include the shared test vectors in `sdk/test-vectors/`, which the Node.js package must pass identically. From `sdk/python/` in the repository:
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
python -m unittest discover -s tests -t tests
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Links
|
|
82
|
+
|
|
83
|
+
- Website: <https://bringyourownagent.org>
|
|
84
|
+
- Repository: <https://github.com/bringyourownagent/bringyourownagent>
|
|
85
|
+
- Rules implemented here (draft): [spec/rules-0.1-draft.md](https://github.com/bringyourownagent/bringyourownagent/blob/main/spec/rules-0.1-draft.md)
|
|
86
|
+
- Node.js package with the same rules: [`bringyourownagent` on npm](https://www.npmjs.com/package/bringyourownagent)
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
[Apache License 2.0](LICENSE).
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "bringyourownagent"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Early draft reference implementation of BYOA (Bring Your Own Agent): manifest validation and the call gate."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "ultrathinker", email = "universeissilent42@gmail.com" }]
|
|
14
|
+
keywords = ["byoa", "bring-your-own-agent", "ai", "agents", "agent-wallet", "protocol", "manifest", "grant", "local-models"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Topic :: Software Development :: Libraries",
|
|
27
|
+
"Typing :: Typed",
|
|
28
|
+
]
|
|
29
|
+
dependencies = []
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Homepage = "https://bringyourownagent.org"
|
|
33
|
+
Repository = "https://github.com/bringyourownagent/bringyourownagent"
|
|
34
|
+
Source = "https://github.com/bringyourownagent/bringyourownagent/tree/main/sdk/python"
|
|
35
|
+
Rules = "https://github.com/bringyourownagent/bringyourownagent/blob/main/spec/rules-0.1-draft.md"
|
|
36
|
+
Issues = "https://github.com/bringyourownagent/bringyourownagent/issues"
|
|
37
|
+
|
|
38
|
+
[project.scripts]
|
|
39
|
+
bringyourownagent = "bringyourownagent.cli:main"
|
|
40
|
+
|
|
41
|
+
[tool.hatch.version]
|
|
42
|
+
path = "src/bringyourownagent/_version.py"
|
|
43
|
+
|
|
44
|
+
[tool.hatch.build.targets.wheel]
|
|
45
|
+
packages = ["src/bringyourownagent"]
|
|
46
|
+
|
|
47
|
+
[tool.hatch.build.targets.sdist]
|
|
48
|
+
include = ["/src/bringyourownagent", "/README.md", "/LICENSE"]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""BYOA (Bring Your Own Agent): an early draft reference implementation.
|
|
2
|
+
|
|
3
|
+
Two things for now, both following spec/rules-0.1-draft.md (a draft for
|
|
4
|
+
discussion):
|
|
5
|
+
|
|
6
|
+
* ``validate_manifest(manifest)`` checks a requester's manifest and returns
|
|
7
|
+
``{"ok", "errors", "warnings"}``. Problems are data, never exceptions.
|
|
8
|
+
* ``check_call(manifest, grant, call, state)`` is the gate for one call:
|
|
9
|
+
it returns ``{"decision", "reasons"}`` where the decision is one of
|
|
10
|
+
``allowed``, ``warn``, ``ask``, ``blocked``.
|
|
11
|
+
|
|
12
|
+
https://bringyourownagent.org
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from ._version import __version__
|
|
16
|
+
from .gate import (
|
|
17
|
+
CheckResult,
|
|
18
|
+
Decision,
|
|
19
|
+
Opinion,
|
|
20
|
+
PurposeJudge,
|
|
21
|
+
Reason,
|
|
22
|
+
apply_opinion,
|
|
23
|
+
check_call,
|
|
24
|
+
no_opinion,
|
|
25
|
+
)
|
|
26
|
+
from .manifest import Issue, ValidationResult, validate_manifest
|
|
27
|
+
from .rules import (
|
|
28
|
+
COST_PERIODS,
|
|
29
|
+
DECISIONS,
|
|
30
|
+
KNOWN_LIMITS,
|
|
31
|
+
KNOWN_SKILLS,
|
|
32
|
+
LOCAL_PROVIDERS,
|
|
33
|
+
PRIVACY_CLASSES,
|
|
34
|
+
PROVIDER_KINDS,
|
|
35
|
+
SUPPORTED_VERSIONS,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
__all__ = [
|
|
39
|
+
"COST_PERIODS",
|
|
40
|
+
"CheckResult",
|
|
41
|
+
"DECISIONS",
|
|
42
|
+
"Decision",
|
|
43
|
+
"Issue",
|
|
44
|
+
"KNOWN_LIMITS",
|
|
45
|
+
"KNOWN_SKILLS",
|
|
46
|
+
"LOCAL_PROVIDERS",
|
|
47
|
+
"Opinion",
|
|
48
|
+
"PRIVACY_CLASSES",
|
|
49
|
+
"PROVIDER_KINDS",
|
|
50
|
+
"PurposeJudge",
|
|
51
|
+
"Reason",
|
|
52
|
+
"SUPPORTED_VERSIONS",
|
|
53
|
+
"ValidationResult",
|
|
54
|
+
"__version__",
|
|
55
|
+
"apply_opinion",
|
|
56
|
+
"check_call",
|
|
57
|
+
"no_opinion",
|
|
58
|
+
"validate_manifest",
|
|
59
|
+
]
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Small helpers shared by the validators. Internal; not part of the public API."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import math
|
|
7
|
+
import re
|
|
8
|
+
from collections.abc import Mapping
|
|
9
|
+
from typing import Any, List
|
|
10
|
+
|
|
11
|
+
from .rules import SKILL_ID_MAX_LENGTH
|
|
12
|
+
|
|
13
|
+
# Unicode White_Space, spelled out so that every implementation agrees exactly.
|
|
14
|
+
_BLANK_RE = re.compile(
|
|
15
|
+
"[\u0009-\u000d\u0020\u0085\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000]*"
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
_SEGMENT = "[a-z][a-z0-9]*(?:-[a-z0-9]+)*"
|
|
19
|
+
_SKILL_ID_RE = re.compile(_SEGMENT + r"\." + _SEGMENT)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def is_object(value: Any) -> bool:
|
|
23
|
+
"""A JSON object (a mapping)."""
|
|
24
|
+
return isinstance(value, Mapping)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def is_array(value: Any) -> bool:
|
|
28
|
+
"""A JSON array."""
|
|
29
|
+
return isinstance(value, (list, tuple))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def is_number(value: Any) -> bool:
|
|
33
|
+
"""A finite JSON number. Booleans are not numbers."""
|
|
34
|
+
if isinstance(value, bool):
|
|
35
|
+
return False
|
|
36
|
+
if isinstance(value, int):
|
|
37
|
+
return True
|
|
38
|
+
if isinstance(value, float):
|
|
39
|
+
return math.isfinite(value)
|
|
40
|
+
return False
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
#: The largest number accepted anywhere: 2**53 - 1, the largest integer every
|
|
44
|
+
#: JSON implementation reads exactly. Larger values are invalid, so all
|
|
45
|
+
#: implementations compare the same numbers the same way.
|
|
46
|
+
MAX_NUMBER = 9007199254740991
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def is_non_negative(value: Any) -> bool:
|
|
50
|
+
"""A number from 0 to MAX_NUMBER."""
|
|
51
|
+
return is_number(value) and 0 <= value <= MAX_NUMBER
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def is_count(value: Any) -> bool:
|
|
55
|
+
"""A whole number from 0 to MAX_NUMBER; 20.0 counts as whole."""
|
|
56
|
+
if not is_non_negative(value):
|
|
57
|
+
return False
|
|
58
|
+
return isinstance(value, int) or float(value).is_integer()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def is_blank(text: str) -> bool:
|
|
62
|
+
return _BLANK_RE.fullmatch(text) is not None
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def is_skill_id(value: Any) -> bool:
|
|
66
|
+
return (
|
|
67
|
+
isinstance(value, str)
|
|
68
|
+
and len(value) <= SKILL_ID_MAX_LENGTH
|
|
69
|
+
and _SKILL_ID_RE.fullmatch(value) is not None
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def present_keys(obj: Mapping) -> List[Any]:
|
|
74
|
+
"""Keys whose value is not null, in Unicode code point order.
|
|
75
|
+
|
|
76
|
+
A field whose value is null is treated as absent.
|
|
77
|
+
"""
|
|
78
|
+
return sorted((key for key, value in obj.items() if value is not None), key=str)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def pointer(*parts: Any) -> str:
|
|
82
|
+
"""Build a JSON Pointer (RFC 6901) from path segments."""
|
|
83
|
+
return "".join("/" + str(part).replace("~", "~0").replace("/", "~1") for part in parts)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def quote(value: Any) -> str:
|
|
87
|
+
"""Show a JSON value inside a message."""
|
|
88
|
+
try:
|
|
89
|
+
return json.dumps(value, ensure_ascii=False)
|
|
90
|
+
except (TypeError, ValueError):
|
|
91
|
+
return repr(value)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def format_number(value: Any) -> str:
|
|
95
|
+
if isinstance(value, float) and value.is_integer() and abs(value) < 1e21:
|
|
96
|
+
return str(int(value))
|
|
97
|
+
return str(value)
|