ai-protocol-client 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.
@@ -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,8 @@
1
+ include LICENSE README.md pyproject.toml
2
+ recursive-include python/ai_protocol *.py *.json
3
+ prune tests
4
+ prune benchmarks
5
+ prune integration
6
+ prune examples
7
+ prune target
8
+ global-exclude __pycache__ *.py[cod]
@@ -0,0 +1,215 @@
1
+ Metadata-Version: 2.4
2
+ Name: ai-protocol-client
3
+ Version: 0.1.0
4
+ Summary: Adaptive clients for cooperative agent access to HTTP services
5
+ Author: Nikita Chindin
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/Xenox-developer/ai-protocol
8
+ Project-URL: Issues, https://github.com/Xenox-developer/ai-protocol/issues
9
+ Keywords: agents,http,gateway,scheduling
10
+ Requires-Python: >=3.12
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: httpx==0.28.1
14
+ Requires-Dist: jsonschema==4.24.0
15
+ Requires-Dist: referencing==0.37.0
16
+ Provides-Extra: llm
17
+ Requires-Dist: openai==1.109.1; extra == "llm"
18
+ Provides-Extra: dev
19
+ Requires-Dist: build>=1.2; extra == "dev"
20
+ Dynamic: license-file
21
+
22
+ # AI Protocol
23
+
24
+ [![Unix checks](https://github.com/Xenox-developer/ai-protocol/actions/workflows/checks.yml/badge.svg)](https://github.com/Xenox-developer/ai-protocol/actions/workflows/checks.yml)
25
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](LICENSE)
26
+
27
+ A Rust framework and Python SDK for cooperative agent access to HTTP services.
28
+ Publish permitted read operations, enforce shared owner budgets, and let clients
29
+ adapt to changing capacity through protocol v3 discovery.
30
+
31
+ **Status:** experimental 0.1.0. The [release page](https://github.com/Xenox-developer/ai-protocol/releases/tag/v0.1.0)
32
+ provides verified archives and the current crates.io/PyPI publication status.
33
+ AI Protocol is a project contract, not a public standard. Supported scope is one in-memory gateway process per
34
+ service, read-only operations, and Linux/macOS for the optional dispatcher.
35
+
36
+ ## What it provides
37
+
38
+ - **Embeddable Rust gateway:** typed asynchronous native handlers in Axum, or
39
+ an owner-configured HTTP adapter. Native inputs can contain nested objects,
40
+ arrays, booleans and optional fields; the HTTP mapper supports flat required
41
+ strings/integers mapped from POST JSON to GET query parameters.
42
+ - **Server-enforced access and budgets:** operation grants and one outstanding
43
+ counter per owner/class, shared across tokens, connections and clients.
44
+ - **Bounded scheduling:** queues and execution slots, FIFO within each class,
45
+ interactive/agent selection weights of 3:1 under competition, queue expiry,
46
+ execution deadlines and bounded buffered responses.
47
+ - **Adaptive Python SDK:** full policy refresh, a local attempt gate, typed
48
+ failures, one task deadline and bounded safe retries. OpenAI is optional.
49
+ - **Optional local dispatcher:** coordinate several agent processes through one
50
+ Unix socket per service/owner, without replaying unknown results.
51
+ - **Operational controls:** host authentication callback, separate upstream/admin
52
+ credentials, graceful shutdown, probes, basic metrics and safe JSON logs.
53
+
54
+ ## Try it locally
55
+
56
+ Prerequisites: Rust/Cargo **1.98.1** (the pinned and tested minimum), Python
57
+ **3.12+**, and Linux or macOS. Run these commands from the repository root:
58
+
59
+ ```sh
60
+ git clone https://github.com/Xenox-developer/ai-protocol.git
61
+ cd ai-protocol
62
+ python3 -m venv .venv
63
+ source .venv/bin/activate
64
+ python -m pip install -e .
65
+ cargo build --locked --bins
66
+ python examples/quickstart.py
67
+ ```
68
+
69
+ Expected result: a successful catalog call, three independent clients through a
70
+ shared dispatcher, final `outstanding=0`, then cleanup of owned processes and
71
+ temporary credentials. The script uses free loopback ports and local fixture
72
+ data. No paid API or LLM is required. See the [quickstart](docs/QUICKSTART.md) for
73
+ roles, troubleshooting and the manual workflow.
74
+
75
+ For a persistent catalog demo, run `python examples/setup_demo.py` once, start
76
+ `python examples/catalog_service.py` in one terminal, then `source .env.demo`
77
+ and `cargo run --locked --bin ai-protocol` in another. The generated credential
78
+ file is private, ignored by Git, and never overwritten. Give each deployed agent
79
+ only its own credential.
80
+
81
+ ## Add a service in Rust
82
+
83
+ For source integration, add this checkout as a path dependency in your application:
84
+
85
+ ```toml
86
+ [dependencies]
87
+ ai-protocol = { path = "../ai-protocol" }
88
+ ```
89
+
90
+ Register an `Operation::new` with its name, description, POST path, JSON input
91
+ schema and typed async handler. Create `GatewayConfig::native` with credentials,
92
+ start a `Gateway`, and merge `gateway.router()` at the root of your Axum router.
93
+ The host owns the listener and keeps the gateway alive while serving requests.
94
+ Call `close()` and `shutdown()` as part of bounded server shutdown.
95
+
96
+ A complete runnable integration is [native_service.rs](examples/native_service.rs):
97
+
98
+ ```sh
99
+ export NATIVE_AGENT_TOKEN="$(python3 -c 'import secrets; print(secrets.token_urlsafe(24))')"
100
+ cargo run --locked --example native_service
101
+ ```
102
+
103
+ Native inputs use Serde validation before admission; the service owner keeps the
104
+ published schema consistent with that Rust type and validates extra constraints.
105
+ Handlers must be nonblocking and read-only. For an existing HTTP API, use a
106
+ [service manifest](docs/service-integration.md); the included catalog and support
107
+ services demonstrate the same generic clients without service-specific branches.
108
+ See [Rust integration](docs/rust-library.md) for public interfaces, live host
109
+ authentication, resource bounds, budget updates and lifecycle semantics.
110
+
111
+ ## Call it from Python
112
+
113
+ Install with `python -m pip install -e .` from the checkout, or install a verified
114
+ release wheel. The distribution is `ai-protocol-client`; the import is `ai_protocol`.
115
+ Use a separate client per service/credential and share it across concurrent tasks:
116
+
117
+ ```python
118
+ import asyncio
119
+ import os
120
+ from ai_protocol import AsyncClient, OperationError
121
+
122
+ async def main():
123
+ async with AsyncClient(
124
+ os.environ["SERVICE_URL"], os.environ["AGENT_TOKEN_1"]
125
+ ) as client:
126
+ print([op["name"] for op in client.policy["operations"]])
127
+ try:
128
+ result = await client.call("find_documents", {"query": "rust"}, timeout=10)
129
+ print(result)
130
+ except OperationError as error:
131
+ print(error.code, error.execution)
132
+
133
+ asyncio.run(main())
134
+ ```
135
+
136
+ For the Rust example above, set `SERVICE_URL=http://127.0.0.1:3000` and give the
137
+ client its `NATIVE_AGENT_TOKEN` value as `AGENT_TOKEN_1`. Operation names and
138
+ parameters come from discovery. Policy failures pause new attempts; shrinking a
139
+ limit preserves attempts already running. Only admission 429 and the documented
140
+ pre-execution queue timeout may be retried, at most five attempts under the same
141
+ deadline. Unknown outcomes are terminal. Cancellation propagates to the caller
142
+ and does not prove downstream work stopped.
143
+
144
+ See [Python SDK](docs/python-sdk.md) for deadlines, errors, legacy synchronous
145
+ helpers and the dispatcher connector. `examples/sdk_client.py` provides an
146
+ interactive generic client. An LLM example is available after
147
+ `python -m pip install -e '.[llm]'`; real model calls require your own API access.
148
+
149
+ ## How requests flow
150
+
151
+ ```mermaid
152
+ flowchart LR
153
+ Agent[Agent / Python SDK] -->|HTTP v3| Gateway[Gateway: auth, owner budget, queues]
154
+ Agents[Several agents] --> Dispatcher[Optional local dispatcher]
155
+ Dispatcher -->|HTTP v3| Gateway
156
+ Gateway --> Slots[Bounded executors]
157
+ Slots --> Native[Native Rust handler]
158
+ Slots --> HTTP[Fixed upstream HTTP API]
159
+ ```
160
+
161
+ The service owner defines operations, trusted classes, permissions and budgets.
162
+ Agent developers discover/call permitted operations. Owners of several agents
163
+ can add the shared dispatcher; the gateway remains the admission authority.
164
+
165
+ ## Configuration and guarantees
166
+
167
+ The executable binds to loopback by default. Configure the listener, executors,
168
+ queues, timeouts, body bounds and credentials using the [configuration and
169
+ operations guide](docs/operations.md). Public HTTPS uses a reverse proxy; that
170
+ guide includes a Caddy recipe, health/readiness routes, private admin metrics,
171
+ logging and shutdown behavior.
172
+
173
+ Budget accounting covers accepted queued and running work in **one process**.
174
+ Reducing a limit does not cancel accepted jobs. The 3:1 rule concerns selection,
175
+ not completion order or latency. Local timeout/drop cannot establish that a
176
+ remote operation did not execute. Errors carry explicit execution certainty;
177
+ there is no exactly-once or durable recovery guarantee.
178
+
179
+ This release does not provide replica coordination, durable queues, writes,
180
+ Windows dispatcher support, automatic API import, a UI, per-owner CPU isolation
181
+ or an independent security audit. See [protocol v3](docs/protocol.md),
182
+ [compatibility and schemas](docs/compatibility.md), and [security](SECURITY.md).
183
+
184
+ ## Develop and verify
185
+
186
+ ```sh
187
+ python -m pip install -r requirements.txt
188
+ bash scripts/verify.sh
189
+ # Build verified, unpublished crate/sdist/wheel files into a new local directory:
190
+ python scripts/check_packages.py --output dist/local-release
191
+ ```
192
+
193
+ The verification command checks formatting, all Rust targets/tests/docs, Python
194
+ tests, an external Rust application, HTTP demos, documentation links, and isolated
195
+ artifact installation. CI runs it on Ubuntu and macOS. Packaging excludes raw
196
+ benchmark data, virtual environments and local credentials. The wheel is built
197
+ from the source distribution and tested without OpenAI outside the checkout.
198
+ See [contributing](CONTRIBUTING.md), the [release procedure](docs/releasing.md),
199
+ and the [framework verification report](docs/FRAMEWORK_REPORT.md).
200
+
201
+ Historical measurements are reproducible experiments with workload-specific
202
+ limits, not performance promises: [benchmark overview](benchmarks/README.md),
203
+ [second-service report](integration/SECOND_SERVICE_REPORT.md), and the
204
+ [historical catalog runbook](docs/history/README-before-framework.md). New framework
205
+ changes have functional checks; the full historical load series was not rerun.
206
+ The external developer trial remains skipped; no independent usability evidence
207
+ is claimed.
208
+
209
+ ## Community and license
210
+
211
+ Use [GitHub issues](https://github.com/Xenox-developer/ai-protocol/issues) for bugs
212
+ and proposals, following [contribution guidance](CONTRIBUTING.md) and the
213
+ [code of conduct](CODE_OF_CONDUCT.md). Report vulnerabilities through the private
214
+ route in [SECURITY.md](SECURITY.md). Changes are recorded in [CHANGELOG.md](CHANGELOG.md).
215
+ Licensed under [Apache-2.0](LICENSE).
@@ -0,0 +1,194 @@
1
+ # AI Protocol
2
+
3
+ [![Unix checks](https://github.com/Xenox-developer/ai-protocol/actions/workflows/checks.yml/badge.svg)](https://github.com/Xenox-developer/ai-protocol/actions/workflows/checks.yml)
4
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](LICENSE)
5
+
6
+ A Rust framework and Python SDK for cooperative agent access to HTTP services.
7
+ Publish permitted read operations, enforce shared owner budgets, and let clients
8
+ adapt to changing capacity through protocol v3 discovery.
9
+
10
+ **Status:** experimental 0.1.0. The [release page](https://github.com/Xenox-developer/ai-protocol/releases/tag/v0.1.0)
11
+ provides verified archives and the current crates.io/PyPI publication status.
12
+ AI Protocol is a project contract, not a public standard. Supported scope is one in-memory gateway process per
13
+ service, read-only operations, and Linux/macOS for the optional dispatcher.
14
+
15
+ ## What it provides
16
+
17
+ - **Embeddable Rust gateway:** typed asynchronous native handlers in Axum, or
18
+ an owner-configured HTTP adapter. Native inputs can contain nested objects,
19
+ arrays, booleans and optional fields; the HTTP mapper supports flat required
20
+ strings/integers mapped from POST JSON to GET query parameters.
21
+ - **Server-enforced access and budgets:** operation grants and one outstanding
22
+ counter per owner/class, shared across tokens, connections and clients.
23
+ - **Bounded scheduling:** queues and execution slots, FIFO within each class,
24
+ interactive/agent selection weights of 3:1 under competition, queue expiry,
25
+ execution deadlines and bounded buffered responses.
26
+ - **Adaptive Python SDK:** full policy refresh, a local attempt gate, typed
27
+ failures, one task deadline and bounded safe retries. OpenAI is optional.
28
+ - **Optional local dispatcher:** coordinate several agent processes through one
29
+ Unix socket per service/owner, without replaying unknown results.
30
+ - **Operational controls:** host authentication callback, separate upstream/admin
31
+ credentials, graceful shutdown, probes, basic metrics and safe JSON logs.
32
+
33
+ ## Try it locally
34
+
35
+ Prerequisites: Rust/Cargo **1.98.1** (the pinned and tested minimum), Python
36
+ **3.12+**, and Linux or macOS. Run these commands from the repository root:
37
+
38
+ ```sh
39
+ git clone https://github.com/Xenox-developer/ai-protocol.git
40
+ cd ai-protocol
41
+ python3 -m venv .venv
42
+ source .venv/bin/activate
43
+ python -m pip install -e .
44
+ cargo build --locked --bins
45
+ python examples/quickstart.py
46
+ ```
47
+
48
+ Expected result: a successful catalog call, three independent clients through a
49
+ shared dispatcher, final `outstanding=0`, then cleanup of owned processes and
50
+ temporary credentials. The script uses free loopback ports and local fixture
51
+ data. No paid API or LLM is required. See the [quickstart](docs/QUICKSTART.md) for
52
+ roles, troubleshooting and the manual workflow.
53
+
54
+ For a persistent catalog demo, run `python examples/setup_demo.py` once, start
55
+ `python examples/catalog_service.py` in one terminal, then `source .env.demo`
56
+ and `cargo run --locked --bin ai-protocol` in another. The generated credential
57
+ file is private, ignored by Git, and never overwritten. Give each deployed agent
58
+ only its own credential.
59
+
60
+ ## Add a service in Rust
61
+
62
+ For source integration, add this checkout as a path dependency in your application:
63
+
64
+ ```toml
65
+ [dependencies]
66
+ ai-protocol = { path = "../ai-protocol" }
67
+ ```
68
+
69
+ Register an `Operation::new` with its name, description, POST path, JSON input
70
+ schema and typed async handler. Create `GatewayConfig::native` with credentials,
71
+ start a `Gateway`, and merge `gateway.router()` at the root of your Axum router.
72
+ The host owns the listener and keeps the gateway alive while serving requests.
73
+ Call `close()` and `shutdown()` as part of bounded server shutdown.
74
+
75
+ A complete runnable integration is [native_service.rs](examples/native_service.rs):
76
+
77
+ ```sh
78
+ export NATIVE_AGENT_TOKEN="$(python3 -c 'import secrets; print(secrets.token_urlsafe(24))')"
79
+ cargo run --locked --example native_service
80
+ ```
81
+
82
+ Native inputs use Serde validation before admission; the service owner keeps the
83
+ published schema consistent with that Rust type and validates extra constraints.
84
+ Handlers must be nonblocking and read-only. For an existing HTTP API, use a
85
+ [service manifest](docs/service-integration.md); the included catalog and support
86
+ services demonstrate the same generic clients without service-specific branches.
87
+ See [Rust integration](docs/rust-library.md) for public interfaces, live host
88
+ authentication, resource bounds, budget updates and lifecycle semantics.
89
+
90
+ ## Call it from Python
91
+
92
+ Install with `python -m pip install -e .` from the checkout, or install a verified
93
+ release wheel. The distribution is `ai-protocol-client`; the import is `ai_protocol`.
94
+ Use a separate client per service/credential and share it across concurrent tasks:
95
+
96
+ ```python
97
+ import asyncio
98
+ import os
99
+ from ai_protocol import AsyncClient, OperationError
100
+
101
+ async def main():
102
+ async with AsyncClient(
103
+ os.environ["SERVICE_URL"], os.environ["AGENT_TOKEN_1"]
104
+ ) as client:
105
+ print([op["name"] for op in client.policy["operations"]])
106
+ try:
107
+ result = await client.call("find_documents", {"query": "rust"}, timeout=10)
108
+ print(result)
109
+ except OperationError as error:
110
+ print(error.code, error.execution)
111
+
112
+ asyncio.run(main())
113
+ ```
114
+
115
+ For the Rust example above, set `SERVICE_URL=http://127.0.0.1:3000` and give the
116
+ client its `NATIVE_AGENT_TOKEN` value as `AGENT_TOKEN_1`. Operation names and
117
+ parameters come from discovery. Policy failures pause new attempts; shrinking a
118
+ limit preserves attempts already running. Only admission 429 and the documented
119
+ pre-execution queue timeout may be retried, at most five attempts under the same
120
+ deadline. Unknown outcomes are terminal. Cancellation propagates to the caller
121
+ and does not prove downstream work stopped.
122
+
123
+ See [Python SDK](docs/python-sdk.md) for deadlines, errors, legacy synchronous
124
+ helpers and the dispatcher connector. `examples/sdk_client.py` provides an
125
+ interactive generic client. An LLM example is available after
126
+ `python -m pip install -e '.[llm]'`; real model calls require your own API access.
127
+
128
+ ## How requests flow
129
+
130
+ ```mermaid
131
+ flowchart LR
132
+ Agent[Agent / Python SDK] -->|HTTP v3| Gateway[Gateway: auth, owner budget, queues]
133
+ Agents[Several agents] --> Dispatcher[Optional local dispatcher]
134
+ Dispatcher -->|HTTP v3| Gateway
135
+ Gateway --> Slots[Bounded executors]
136
+ Slots --> Native[Native Rust handler]
137
+ Slots --> HTTP[Fixed upstream HTTP API]
138
+ ```
139
+
140
+ The service owner defines operations, trusted classes, permissions and budgets.
141
+ Agent developers discover/call permitted operations. Owners of several agents
142
+ can add the shared dispatcher; the gateway remains the admission authority.
143
+
144
+ ## Configuration and guarantees
145
+
146
+ The executable binds to loopback by default. Configure the listener, executors,
147
+ queues, timeouts, body bounds and credentials using the [configuration and
148
+ operations guide](docs/operations.md). Public HTTPS uses a reverse proxy; that
149
+ guide includes a Caddy recipe, health/readiness routes, private admin metrics,
150
+ logging and shutdown behavior.
151
+
152
+ Budget accounting covers accepted queued and running work in **one process**.
153
+ Reducing a limit does not cancel accepted jobs. The 3:1 rule concerns selection,
154
+ not completion order or latency. Local timeout/drop cannot establish that a
155
+ remote operation did not execute. Errors carry explicit execution certainty;
156
+ there is no exactly-once or durable recovery guarantee.
157
+
158
+ This release does not provide replica coordination, durable queues, writes,
159
+ Windows dispatcher support, automatic API import, a UI, per-owner CPU isolation
160
+ or an independent security audit. See [protocol v3](docs/protocol.md),
161
+ [compatibility and schemas](docs/compatibility.md), and [security](SECURITY.md).
162
+
163
+ ## Develop and verify
164
+
165
+ ```sh
166
+ python -m pip install -r requirements.txt
167
+ bash scripts/verify.sh
168
+ # Build verified, unpublished crate/sdist/wheel files into a new local directory:
169
+ python scripts/check_packages.py --output dist/local-release
170
+ ```
171
+
172
+ The verification command checks formatting, all Rust targets/tests/docs, Python
173
+ tests, an external Rust application, HTTP demos, documentation links, and isolated
174
+ artifact installation. CI runs it on Ubuntu and macOS. Packaging excludes raw
175
+ benchmark data, virtual environments and local credentials. The wheel is built
176
+ from the source distribution and tested without OpenAI outside the checkout.
177
+ See [contributing](CONTRIBUTING.md), the [release procedure](docs/releasing.md),
178
+ and the [framework verification report](docs/FRAMEWORK_REPORT.md).
179
+
180
+ Historical measurements are reproducible experiments with workload-specific
181
+ limits, not performance promises: [benchmark overview](benchmarks/README.md),
182
+ [second-service report](integration/SECOND_SERVICE_REPORT.md), and the
183
+ [historical catalog runbook](docs/history/README-before-framework.md). New framework
184
+ changes have functional checks; the full historical load series was not rerun.
185
+ The external developer trial remains skipped; no independent usability evidence
186
+ is claimed.
187
+
188
+ ## Community and license
189
+
190
+ Use [GitHub issues](https://github.com/Xenox-developer/ai-protocol/issues) for bugs
191
+ and proposals, following [contribution guidance](CONTRIBUTING.md) and the
192
+ [code of conduct](CODE_OF_CONDUCT.md). Report vulnerabilities through the private
193
+ route in [SECURITY.md](SECURITY.md). Changes are recorded in [CHANGELOG.md](CHANGELOG.md).
194
+ Licensed under [Apache-2.0](LICENSE).
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0.3"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ai-protocol-client"
7
+ version = "0.1.0"
8
+ description = "Adaptive clients for cooperative agent access to HTTP services"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE"]
13
+ keywords = ["agents", "http", "gateway", "scheduling"]
14
+ authors = [{name = "Nikita Chindin"}]
15
+ dependencies = ["httpx==0.28.1", "jsonschema==4.24.0", "referencing==0.37.0"]
16
+
17
+ [project.optional-dependencies]
18
+ llm = ["openai==1.109.1"]
19
+ dev = ["build>=1.2"]
20
+
21
+ [project.urls]
22
+ Repository = "https://github.com/Xenox-developer/ai-protocol"
23
+ Issues = "https://github.com/Xenox-developer/ai-protocol/issues"
24
+
25
+ [tool.setuptools.packages.find]
26
+ where = ["python"]
27
+
28
+ [tool.setuptools.package-data]
29
+ ai_protocol = ["schemas/*.json"]
@@ -0,0 +1,7 @@
1
+ """Cooperative agent access: adaptive HTTP client and optional local dispatcher."""
2
+ from .client import AsyncClient, DeadlineExceeded, OperationError, ProtocolError
3
+ from .dispatcher import DispatcherClient
4
+ from .protocol import discover, execute, service_client
5
+
6
+ __all__ = ["AsyncClient", "DeadlineExceeded", "OperationError", "ProtocolError",
7
+ "DispatcherClient", "discover", "execute", "service_client"]