agentic-platform-sdk 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.
Files changed (43) hide show
  1. agentic_platform_sdk-0.1.0/.gitignore +7 -0
  2. agentic_platform_sdk-0.1.0/CHANGELOG.md +21 -0
  3. agentic_platform_sdk-0.1.0/LICENSE +202 -0
  4. agentic_platform_sdk-0.1.0/PKG-INFO +226 -0
  5. agentic_platform_sdk-0.1.0/README.md +190 -0
  6. agentic_platform_sdk-0.1.0/agentic_platform_sdk/__init__.py +9 -0
  7. agentic_platform_sdk-0.1.0/agentic_platform_sdk/_a2a.py +133 -0
  8. agentic_platform_sdk-0.1.0/agentic_platform_sdk/_client.py +152 -0
  9. agentic_platform_sdk-0.1.0/agentic_platform_sdk/_contract.py +72 -0
  10. agentic_platform_sdk-0.1.0/agentic_platform_sdk/_generated/__init__.py +0 -0
  11. agentic_platform_sdk-0.1.0/agentic_platform_sdk/_generated/_base.py +20 -0
  12. agentic_platform_sdk-0.1.0/agentic_platform_sdk/_generated/models.py +698 -0
  13. agentic_platform_sdk-0.1.0/agentic_platform_sdk/_paging.py +117 -0
  14. agentic_platform_sdk-0.1.0/agentic_platform_sdk/_spec/call_areas.json +13 -0
  15. agentic_platform_sdk-0.1.0/agentic_platform_sdk/_spec/chat-events.schema.json +371 -0
  16. agentic_platform_sdk-0.1.0/agentic_platform_sdk/_spec/errors.json +2365 -0
  17. agentic_platform_sdk-0.1.0/agentic_platform_sdk/_spec/operations.json +230 -0
  18. agentic_platform_sdk-0.1.0/agentic_platform_sdk/_transport.py +630 -0
  19. agentic_platform_sdk-0.1.0/agentic_platform_sdk/_util.py +133 -0
  20. agentic_platform_sdk-0.1.0/agentic_platform_sdk/agents.py +793 -0
  21. agentic_platform_sdk-0.1.0/agentic_platform_sdk/approvals.py +66 -0
  22. agentic_platform_sdk-0.1.0/agentic_platform_sdk/auth.py +336 -0
  23. agentic_platform_sdk-0.1.0/agentic_platform_sdk/chat.py +599 -0
  24. agentic_platform_sdk-0.1.0/agentic_platform_sdk/datasets.py +69 -0
  25. agentic_platform_sdk-0.1.0/agentic_platform_sdk/errors.py +204 -0
  26. agentic_platform_sdk-0.1.0/agentic_platform_sdk/kb.py +288 -0
  27. agentic_platform_sdk-0.1.0/agentic_platform_sdk/llm.py +40 -0
  28. agentic_platform_sdk-0.1.0/agentic_platform_sdk/me.py +28 -0
  29. agentic_platform_sdk-0.1.0/agentic_platform_sdk/models.py +91 -0
  30. agentic_platform_sdk-0.1.0/agentic_platform_sdk/ontology.py +209 -0
  31. agentic_platform_sdk-0.1.0/agentic_platform_sdk/py.typed +0 -0
  32. agentic_platform_sdk-0.1.0/agentic_platform_sdk/testing/__init__.py +19 -0
  33. agentic_platform_sdk-0.1.0/agentic_platform_sdk/testing/conformance.py +803 -0
  34. agentic_platform_sdk-0.1.0/agentic_platform_sdk/testing/fake.py +902 -0
  35. agentic_platform_sdk-0.1.0/agentic_platform_sdk/testing/standin.py +165 -0
  36. agentic_platform_sdk-0.1.0/agentic_platform_sdk/toolchains.py +137 -0
  37. agentic_platform_sdk-0.1.0/agentic_platform_sdk/tools/__init__.py +70 -0
  38. agentic_platform_sdk-0.1.0/agentic_platform_sdk/tools/_jcs.py +218 -0
  39. agentic_platform_sdk-0.1.0/agentic_platform_sdk/tools/asgi.py +228 -0
  40. agentic_platform_sdk-0.1.0/agentic_platform_sdk/tools/mcp.py +751 -0
  41. agentic_platform_sdk-0.1.0/agentic_platform_sdk/tools/verify.py +379 -0
  42. agentic_platform_sdk-0.1.0/agentic_platform_sdk/vision.py +300 -0
  43. agentic_platform_sdk-0.1.0/pyproject.toml +77 -0
@@ -0,0 +1,7 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .env
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .venv/
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ First release on PyPI as `agentic-platform-sdk` (import package `agentic_platform_sdk`), Apache-2.0.
6
+ The `testing` extra installs `agentic-platform-standin` (pinned to the same version), and the HTTP
7
+ `User-Agent` is `agentic-platform-sdk-python/<version>`.
8
+
9
+ - Chat events (spec 4.6): new `agentic_platform_sdk.chat` with the typed events `TextDelta`, `ThinkingDelta`, `ToolCall`, `ToolResult`, `Approval`, `Sources`, `Plan`, `SubAgent`, `Status` and `Done` (`Ref`, `Source`, `PlanStep` as parts), each with `seq` (`None` for what the platform derives and does not log) and `raw`. `client.agents.stream(agent_id, text, chat_events=True, app_context=None, resume=True)` sends `A2A-Extensions: urn:agentic:a2a:ext:chat-events:v1` and `message.extensions`, puts `app_context` into `message.metadata["agentic.app_context"]` (at most 4096 bytes of compact UTF-8 JSON, checked here: `ValueError` before anything is sent) and yields typed events ending with `Done(task)`. `client.agents.subscribe(agent_id, task_id, after_seq=0, chat_events=True)` watches a task from a position. Both are in the sync and the async client. Without `chat_events` the requests and events are byte-identical to before.
10
+ - Resume: a chat stream that drops (a read error, or a body that ends before the task does) reconnects with `SubscribeToTask` and `agentic.after_seq` = the last `seq` it saw; each `seq` reaches the caller once (a replayed frame is dropped), in order. At most 3 reconnects with no new event between them (0, 0.5 s, 1 s waits), then the stream ends with `Done` holding a `GetTask` snapshot (check `done.task.state`: it may still be running). `a2a.events_unavailable` (the platform keeps the log 15 minutes) ends it the same way at once. `resume=False` leaves the drop to the caller (`Unavailable`). Text rule: `append=False` replaces the answer held so far, `append=True` adds; `Done.code` is the platform code of the end (`a2a.task_timeout` for the 210 s wall cap, `a2a.task_canceled`, ...).
11
+ - `approvals.decide` is documented with its codes (409 `approval.already_decided`, `approval.request_not_pending` (also a decision after the wall cap), `approval.step_not_open`; one 404 `approval.not_found`) and is never repeated after a 5xx.
12
+ - `FakeAgenticClient`: `agents.stream(chat_events=True)` replays the script (chat events allowed in `agent_script`; the default echoes the text as an answer) and ends with `Done`; `agents.subscribe` replays the logged events after `after_seq`; `approvals.decide` is modelled over `add_approval(request_id=None, decidable=True)` (unknown and not-decidable are the one `NotFound`, a decided one a `Conflict`). `agents.subscribe(chat_events=False)` is not modelled.
13
+ - Conformance: scenario `agents.stream` with `message.extensions: [<chat-events URI>]` runs the chat stream and its result is `{"events": [...], "end": {...}}`; new call `agents.subscribe`. `approvals.decide` of a nil-prefixed id that expects `approval.not_found` may run against a real platform (it writes nothing); every other decision is still refused there.
14
+ - Internal: the A2A value types and frame decoding moved to `agentic_platform_sdk._a2a` (still importable from `agentic_platform_sdk.agents`); `_spec/chat-events.schema.json` is generated into the package and a test keeps every event class and enum equal to it.
15
+ - New `agentic_platform_sdk.tools` (the app tool callback, spec §4.7): `verify_callback_token` checks the platform's HS256 callback token (signature against the live secrets, `aud`, `exp` with 30 s leeway, `purpose`, `tool`, the app-context hash, then a replayed `jti`) and returns a `ToolCaller`; `CallbackAuth` is the ASGI layer that puts it in front of an MCP endpoint (HTTP 401, no detail, on any refusal) and sets `current_caller`; `ReplayStore` / `AsyncReplayStore` / `InMemoryReplayStore` (a jti is remembered until `exp` + leeway); `averify_callback_token` (awaits an async store); `ref(kind, id)`. `secrets` must be a list of `ats_` strings (a bare string is a `TypeError`); the app-context hash is RFC 8785 (JCS); `CallbackAuth` serves only stateless Streamable HTTP, refuses non-http scopes, a body that is not JSON-RPC and any method but `initialize` / `notifications/initialized` / `tools/list` / `ping` on a sync token. Nothing here imports the MCP package unless `AgenticToolServer` is asked for. `agentic_platform_sdk.tools.mcp.AgenticToolServer` (the optional `[mcp]` extra, `mcp>=2.3,<3`) serves the app's tools on the official MCP SDK, stateless Streamable HTTP with JSON replies, behind `CallbackAuth`: `@server.tool()` handlers take a `caller: ToolCaller` filled from the verified token (not in the input schema) and may return a `ToolResult(text, ref=None, is_error=False)`; `server.asgi_app()` serves or mounts it (`server.lifespan` for a host app); `stateless=False` is refused. The `caller` parameter is recognised through `Optional` / `| None` / `Annotated` (or bare), any other annotation that mentions `ToolCaller` or a `caller` not annotated exactly so is a `TypeError` at registration, a plain handler runs in a worker thread, and the official server object is private (`_mcp`). CI pins `mcp==2.3.0` / `mcp-types==2.3.0` (constraints-generate.txt) for the recorded fixtures. Sample: `examples/app_tool_sample` (runnable: `python -m app_tool_sample`).
16
+ - `AgenticToolServer` adoption gaps closed (all in the `[mcp]` extra, offline tests in `tests/test_tools_mcp_adoption.py`): `@server.tool(input_schema={...})` lists the app's own object schema (a copy; the handler, the `caller` injection and the token check are unchanged) and is checked against the handler's signature at registration, a `TypeError` otherwise: a required handler parameter (no default, not the injected caller) must be in the schema's `properties` and in its `required`, the schema may not declare a property the handler does not accept (unless it takes `**kwargs`) nor the injected caller's name and a derived schema now has no pydantic `title` keys and `additionalProperties: false`; undeclared arguments are refused (they used to be dropped silently, so `caller` or an id in the arguments is now an error, not ignored); `@server.tool(validate=fn)` is a hook on the raw arguments (`raise InvalidArguments(text, code="tool.invalid_arguments")` or return a `ToolResult`), and a type / missing-field failure answers `tool.invalid_arguments: <tool>: invalid or missing argument(s): <names>` instead of pydantic text; an unknown tool answers an `isError` result `tool.unknown: ...` (not JSON-RPC -32602: the platform maps a JSON-RPC error to `app_tool.unavailable` and `isError` to `app_tool.tool_error` with the app's text); a batch POST is 400 `-32600 "one request per POST"` (a batch that holds a `tools/call` is refused earlier by `CallbackAuth` with its usual empty 401: one token cannot name two tools); `GET` / `DELETE` and any other method are 405 `Allow: POST` once the token verified; `initialize` advertises only `tools` (prompts / resources handlers are not served) and echoes a supported `protocolVersion` (the platform's `2025-06-18`), else the SDK's latest; the server works with no lifespan (a bare `TestClient(app)`, each request runs its own short-lived session manager) and `server.lifespan()` may be nested (an inner entry is only counted) and entered again once every earlier entry has exited (overlapping entries that exit out of order leave the count right; the others then finish on per-request managers) and the no-lifespan mode is safe across threads (each request reads the manager of the app it built, under a lock); `max_concurrency=` (server-wide or per tool) caps plain handlers. The platform's recorded MCP fixtures (`backend/tests/fixtures/mcp_streamable_http`) were re-recorded for the new `initialize` and `tools/list` answers.
17
+ - `approvals.decide(request_id, "approve" | "reject", comment=None)` (sync and async; `POST /approvals/{request_id}/decision`) decides the approval a composer run is waiting on, as an approver. The platform answers one `NotFound` (`approval.not_found`) for an unknown id, a kind apps may not decide, and a caller who may not decide; a decided one is `Conflict`. The fake models it (see the `FakeAgenticClient` entry above); conformance classes it as a creating call (refused in platform mode), except the nil-prefixed `approval.not_found` probe, which writes nothing.
18
+ - `vision.download` (sync and async) returns a `ModelDownload` (`sha256`, `label_map`: the `X-Model-Sha256` and `X-Label-Map` headers), exported from `agentic_platform_sdk`. It hashes the bytes as it copies them and raises `PlatformError("training.checksum_mismatch", http_status=200)` on a mismatch: a path target is left without a file, a stream target has already received the bytes (discard them).
19
+ - `vision.download` refuses by default a missing, empty or malformed (not 64 hex digits) `X-Model-Sha256`: `PlatformError("training.checksum_missing", http_status=200)`, raised before anything is written (no `.part` file, a stream receives nothing). The keyword `require_checksum=False` is the opt-out, for old or foreign servers only: a missing header is then accepted without a check and `sha256` is `None` (a header that is sent is still compared). User ruling 2026-11-17: refuse by default.
20
+ - `FakeAgenticClient.vision.download` is modelled, over models put in with `add_model(model_id, data, labels=..., sha256=...)`; it sends the checksum by default, `sha256=None` or `""` omits it, a malformed value is refused as on the real client, and it takes `require_checksum`.
21
+ - Every generated date-time field is a `UtcDatetime` (one type in `_generated/_base.py`, put into the models by `scripts/generate.py`): the platform answers with offset-less ISO date-times (`2026-10-16T08:32:00.332613`), which are read as UTC, so `models.list`, `kb.list` and the other lists no longer fail with `<area>.unavailable`. A value with an offset is kept as it came, garbage still fails. A naive `datetime` the caller passes in a request (which an earlier build refused) is taken as UTC and sent with an offset: pass an aware value if the time is local.
@@ -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,226 @@
1
+ Metadata-Version: 2.5
2
+ Name: agentic-platform-sdk
3
+ Version: 0.1.0
4
+ Summary: Python SDK for the Agentic Platform Open API (/open/v1)
5
+ Project-URL: Stand-in platform, https://pypi.org/project/agentic-platform-standin/
6
+ Author: Agentic Platform contributors
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Keywords: a2a,agentic-platform,llm,open-api,rag,sdk
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.11
21
+ Requires-Dist: httpx>=0.27
22
+ Requires-Dist: pydantic>=2.7
23
+ Requires-Dist: pyjwt[crypto]>=2.9
24
+ Provides-Extra: dev
25
+ Requires-Dist: datamodel-code-generator==0.96.0; extra == 'dev'
26
+ Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
27
+ Requires-Dist: pytest>=8; extra == 'dev'
28
+ Requires-Dist: respx>=0.21; extra == 'dev'
29
+ Requires-Dist: ruff==0.17.5; extra == 'dev'
30
+ Provides-Extra: mcp
31
+ Requires-Dist: mcp<3,>=2.3; extra == 'mcp'
32
+ Provides-Extra: testing
33
+ Requires-Dist: agentic-platform-standin==0.1.0; extra == 'testing'
34
+ Requires-Dist: pyyaml>=6; extra == 'testing'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # agentic-platform-sdk (Python)
38
+
39
+ The Python SDK of the Agentic Platform's open API (`/open/v1`): sync and async clients, API-key,
40
+ DPoP and token-callable auth, retries, paging, typed errors and models, and an in-memory fake for
41
+ tests. Python 3.11 or newer.
42
+
43
+ ```
44
+ pip install agentic-platform-sdk
45
+ pip install 'agentic-platform-sdk[testing]' # adds the stand-in platform (agentic-platform-standin)
46
+ ```
47
+
48
+ ```python
49
+ from agentic_platform_sdk import AgenticClient
50
+ from agentic_platform_sdk.auth import ApiKey
51
+
52
+ with AgenticClient("https://platform.example.com", ApiKey("agk_...")) as client:
53
+ print(client.me.get())
54
+ ```
55
+
56
+ `agentic_platform_sdk.testing` has `FakeAgenticClient` (in memory) and `run_standin()` (the stand-in
57
+ platform in a subprocess). The contract, the conformance scenarios and the call areas ship with the
58
+ platform's source repository, not with this package.
59
+
60
+ ## Logging
61
+
62
+ httpx logs every request at INFO with its full URL, query string included (ids, search terms).
63
+ Unless you want that in your logs, raise its level:
64
+
65
+ ```python
66
+ import logging
67
+
68
+ logging.getLogger("httpx").setLevel(logging.WARNING)
69
+ ```
70
+
71
+ ## Timeouts
72
+
73
+ Defaults, overridable per call (`timeout=`), per operation (`timeouts={"<operationId>": s}`) or per
74
+ area (`timeouts={"<area>": s}`), in that order; an area entry does not undo the upload and blocking
75
+ send defaults below:
76
+
77
+ | call | timeout |
78
+ |---|---|
79
+ | any area not listed | 30 s |
80
+ | `llm` | 180 s |
81
+ | `vision` | 600 s |
82
+ | a document upload (`kb.upload_document`) | 300 s |
83
+ | a blocking `agents.send` (the platform waits up to 240 s) | 250 s |
84
+ | `agents.stream` | no read timeout |
85
+
86
+ A timeout applies to each attempt. A retried call makes up to 3 attempts (`RetryConfig.tries`), so
87
+ the worst case for a blocking send that is retried is 3 x 250 s = 750 s, plus the backoff waits
88
+ (at most `RetryConfig.budget_s`, 30 s, in all). Pass a smaller `timeout=` or a `RetryConfig` with
89
+ fewer tries when a caller cannot wait that long.
90
+
91
+ ## Chat events (`agentic_platform_sdk.chat`)
92
+
93
+ `client.agents.stream(agent_id, text, chat_events=True)` activates the platform's chat-events extension and yields typed
94
+ events (`TextDelta`, `ThinkingDelta`, `ToolCall`, `ToolResult`, `Approval`, `Sources`, `Plan`, `SubAgent`, `Status`),
95
+ ending with `Done(task)`; an event type this SDK does not know arrives as `Unknown`, never an error. `app_context={...}`
96
+ (at most 4096 bytes of compact JSON) is handed to the app's tools. A dropped stream is resumed with
97
+ `client.agents.subscribe`'s mechanism (`after_seq` = the last `seq` seen) up to 3 times, each event reaching you once;
98
+ past that, or when the platform's event log is gone (`a2a.events_unavailable`), `Done` carries the task as `GetTask`
99
+ sees it, which may still be running: check `done.task.state`. `resume=False` raises the drop instead. A text event with
100
+ `append=False` replaces the answer so far. `approvals.decide(request_id, "approve")` answers an `Approval` event; a
101
+ late decision (the run's 210 s cap, `a2a.task_timeout`) is `Conflict` `approval.request_not_pending`.
102
+
103
+ ## App tool endpoints (`agentic_platform_sdk.tools`)
104
+
105
+ A platform agent can call an app's own tools, as the user whose task is running, at the app's registered MCP endpoint.
106
+ Every request carries a short-lived HS256 token signed with the app's `ats_` secret. The helper checks it and hands
107
+ the handler who is calling:
108
+
109
+ ```python
110
+ from agentic_platform_sdk.tools import CallbackAuth, InMemoryReplayStore, current_caller, ref
111
+
112
+ # in front of an ASGI app that serves MCP over STATELESS Streamable HTTP; pass both secrets (a list of `ats_`
113
+ # strings, never a bare string) while one is being rotated
114
+ guarded = CallbackAuth(
115
+ mcp_asgi_app,
116
+ audience="my-app-slug",
117
+ secrets=lambda: [CURRENT, PREVIOUS],
118
+ replay=InMemoryReplayStore(),
119
+ ) # several replicas: an AsyncReplayStore on Redis (SET NX EXAT)
120
+
121
+
122
+ async def start_job(spec: str):
123
+ caller = current_caller.get() # ToolCaller: user_sub, sub_iss, workspace_id, task_id, ...
124
+ user = my_users.by_subject(
125
+ caller.sub_iss, caller.user_sub
126
+ ) # your own user; run your normal access checks
127
+ job_id = queue.enqueue(user, spec)
128
+ return {
129
+ "ref": ref("my-app.job", job_id)
130
+ } # return at once; the UI fetches the job through your API
131
+ ```
132
+
133
+ - **Never take a user or workspace id from the tool's arguments.** The caller is the token's `sub`; arguments are the
134
+ model's input.
135
+ - A refused request (bad signature, expired, wrong audience, wrong tool, changed app context, a replayed token, a
136
+ `sync` token on `tools/call`) is HTTP 401 with no detail; `on_refused(code)` receives the `callback.*` code for your log.
137
+ - **Stateless mode only.** `current_caller` is a context variable, right only while the tool handler runs in the
138
+ HTTP request's own task. A stateless Streamable HTTP server does that; a stateful one (it sets `Mcp-Session-Id`)
139
+ runs handlers in a session task made by the first request, so a later call would see that request's caller (none,
140
+ or another user's). Never put `CallbackAuth` in front of a stateful server, and never run a handler in a
141
+ background task that reads `current_caller` (copy the `ToolCaller` out first).
142
+ - Only `initialize`, `notifications/initialized`, `tools/list` and `ping` are served on a `sync` token; any other
143
+ method, a body that does not parse as a JSON-RPC object (or array of objects), a batch holding a `tools/call`,
144
+ and a WebSocket are refused. `secrets` must be a list of `ats_` secrets (a bare string or a short secret raises at
145
+ construction); `iss` is informational (the app checks `aud`).
146
+ - A replay store is called on the event loop: `InMemoryReplayStore` (one process) is fine; a network store must
147
+ implement `AsyncReplayStore` (`async def seen_or_add(jti, until)`, awaited), so it never blocks the loop. It
148
+ remembers each jti until `exp` + the 30 s leeway.
149
+ - Token claims, the app-context hash (RFC 8785) and the codes: `sdk/spec/README.md`, "App tool callback".
150
+
151
+ ### The MCP server on the official SDK (`[mcp]` extra)
152
+
153
+ `AgenticToolServer` is the whole thing in one class: the official `mcp` SDK (`pip install 'agentic-platform-sdk[mcp]'`,
154
+ `mcp>=2.3,<3`; it is an optional extra, never a core dependency) in stateless Streamable HTTP with JSON replies, behind
155
+ `CallbackAuth`. A `caller: ToolCaller` parameter is filled from the verified token and is not in the tool's input schema:
156
+
157
+ ```python
158
+ from agentic_platform_sdk.tools import ToolCaller, ToolResult, ref
159
+ from agentic_platform_sdk.tools.mcp import (
160
+ AgenticToolServer,
161
+ ) # imports `mcp`; raises ImportError without the extra
162
+
163
+ server = AgenticToolServer("my-app-slug", secrets=lambda: [CURRENT, PREVIOUS])
164
+
165
+
166
+ @server.tool(description="Start a part-generation job")
167
+ async def start_job(spec: str, caller: ToolCaller) -> ToolResult:
168
+ user = my_users.by_subject(caller.sub_iss, caller.user_sub)
169
+ return ToolResult(
170
+ "started", ref=ref("my-app.job", queue.enqueue(user, spec))
171
+ ) # `ref` -> structuredContent.ref
172
+
173
+
174
+ app = server.asgi_app() # uvicorn.run(app): endpoint http://host:port/mcp
175
+ ```
176
+
177
+ - `stateless=False` is refused (see "Stateless mode only" above). Register every tool before calling `asgi_app()`.
178
+ - To mount it in another app (FastAPI `app.mount("/tools", server.asgi_app())`), give the host app
179
+ `lifespan=server.lifespan`: the MCP session manager then runs once for the process. Served on its own, `asgi_app()`
180
+ runs it itself. With no lifespan at all (a bare `TestClient(app)` without `with`, a host that does not forward
181
+ lifespan) each request runs its own short-lived manager: correct, a little slower. `server.lifespan()` may be nested
182
+ (an inner entry is only counted) and entered again once every earlier entry has exited. The first entry owns the
183
+ manager: if overlapping entries exit out of order, the others finish on per-request managers (correct, slower). The
184
+ no-lifespan mode is safe across threads.
185
+ - **Input schemas and arguments.** `tools/list` shows each tool's schema without pydantic's `title` keys and with
186
+ `additionalProperties: false`. `@server.tool(input_schema={...})` shows your own object schema instead (the handler is
187
+ still what runs, behind the same `caller` injection and token check; its signature still validates the types).
188
+ **The schema must match the handler**, checked at registration (a `TypeError`, so a mismatch never ships): every
189
+ required handler parameter (no default; not the injected `caller`) must be in `properties` and in `required`; the
190
+ schema may not declare a property the handler does not accept, unless the handler takes `**kwargs`; and it may not
191
+ declare the injected `caller`. An optional handler parameter may be left out of the schema.
192
+ Arguments are checked on the raw call before the handler runs: an **undeclared argument** (anything outside the
193
+ schema's `properties`, `caller` and ids included) is refused; `@server.tool(validate=fn)` runs `fn(arguments)` (sync
194
+ or async, must not block) on a copy of the raw arguments (the verified caller is `current_caller.get()` inside it) and refuses with your own text (`raise InvalidArguments("...")`,
195
+ optionally `code="my.code"`) or by returning a `ToolResult`; a type or missing-field failure answers
196
+ `tool.invalid_arguments: <tool>: invalid or missing argument(s): <names>` (names only, never values or library text).
197
+ Every refusal is a normal result with `isError: true`, which the platform shows the model as the app's own text
198
+ (`app_tool.tool_error`). With `additionalProperties: true` in your schema nothing undeclared is refused, but a handler
199
+ only receives its declared parameters.
200
+ - **Unknown tool** answers HTTP 200 with `isError: true` and `tool.unknown: no tool named '<name>'`, not a JSON-RPC
201
+ error: the platform's client maps a JSON-RPC `error` to `app_tool.unavailable` (the app is treated as down and the model
202
+ sees none of your text) and an `isError` result to `app_tool.tool_error` with your text. (The MCP spec says -32602 here;
203
+ this server chooses what the platform can use.)
204
+ - **One request per POST**: a JSON-RPC batch answers 400 `-32600 "one request per POST"` (a batch holding a `tools/call`
205
+ is refused earlier by `CallbackAuth`, empty 401). **Only POST**: `GET` / `DELETE` / any other method answer 405
206
+ `Allow: POST` once the token verified (stateless, JSON replies: no event stream, no session to end).
207
+ - **`initialize`** advertises `{"tools": {"listChanged": false}}` only (prompts, resources, subscriptions and
208
+ completions are not served). `protocolVersion`: the client's is echoed when the official SDK supports it (the
209
+ platform's client sends `2025-06-18` and gets it back), else the SDK's latest is answered and the client decides.
210
+ - `max_concurrency=N` (on `AgenticToolServer`, or per tool on `@server.tool`) caps how many plain (non-async) handlers run
211
+ at once; unset, anyio's default thread limiter (40) applies. Use one event loop per server when a cap is set (anyio's limiter is not safe to share between loops).
212
+ - The `caller` parameter may be written `ToolCaller`, `ToolCaller | None`, `Optional[ToolCaller]`, `Annotated[...]` of
213
+ those, or be a bare `caller`; it is always filled from the verified token. Any other annotation that mentions
214
+ `ToolCaller` (`list[ToolCaller]`, `ToolCaller | str`), or a parameter named `caller` that is not annotated exactly so,
215
+ is a `TypeError` at `@server.tool()`; a registered schema that would build a `ToolCaller` from the arguments is refused too.
216
+ - A plain (non-async) handler runs in a worker thread, so a blocking call does not stall other callers.
217
+ - The official server object is private (`server._mcp`). Registering a tool on it, or serving its
218
+ `streamable_http_app()`, bypasses both the `caller` injection and the token check; use `@server.tool()` and `asgi_app()` only.
219
+ - DNS-rebinding host checks are off by default: every request (every method, GET included) already needs an HS256 call
220
+ or sync token for your audience, valid for 120 s and single-use (`jti`), which a rebinding page cannot mint; the official
221
+ default accepts only `localhost`, which would refuse the platform's calls to your host name. `allowed_hosts=[...]` turns
222
+ them on. With it set, a request that carries an `Origin` header is refused (`allowed_origins=[]`: fine for the
223
+ platform's server-side client, not for a browser test tool), and the host check runs after the token check, so a
224
+ refused host has already used up its token's `jti`.
225
+ - `examples/app_tool_sample` is a runnable sample (`python -m app_tool_sample` from `examples/`, with
226
+ `SAMPLE_APP_TOOL_SECRET`): `start_job` returns a ref at once, `get_job`, `list_items`, per-user access.