agentos-sdk-python 1.0.0__tar.gz → 1.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.
- agentos_sdk_python-1.1.0/CHANGELOG.md +69 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/PKG-INFO +241 -5
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/README-zh_CN.md +222 -2
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/README.md +238 -2
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/RELEASE.md +2 -2
- agentos_sdk_python-1.1.0/agentos_sdk/__init__.py +143 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/agentos_sdk/clients/__init__.py +4 -0
- agentos_sdk_python-1.1.0/agentos_sdk/clients/harnesskit.py +384 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/agentos_sdk/clients/modelkit.py +98 -1
- agentos_sdk_python-1.1.0/agentos_sdk/clients/notifykit.py +47 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/agentos_sdk/normalizers.py +44 -9
- agentos_sdk_python-1.1.0/agentos_sdk/protocol.py +646 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/agentos_sdk/sdk.py +250 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/agentos_sdk/transport.py +8 -2
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/pyproject.toml +2 -2
- agentos_sdk_python-1.1.0/tests/test_harnesskit.py +913 -0
- agentos_sdk_python-1.1.0/tests/test_modelkit.py +334 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/tests/test_normalizers.py +53 -0
- agentos_sdk_python-1.1.0/tests/test_notifykit.py +224 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/tests/test_sdk_facade.py +88 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/tests/test_transport.py +28 -0
- agentos_sdk_python-1.1.0/tests/typecheck/harnesskit_usage.py +91 -0
- agentos_sdk_python-1.1.0/tests/typecheck/modelkit_usage.py +85 -0
- agentos_sdk_python-1.1.0/tests/typecheck/notifykit_usage.py +54 -0
- agentos_sdk_python-1.0.0/CHANGELOG.md +0 -35
- agentos_sdk_python-1.0.0/agentos_sdk/__init__.py +0 -67
- agentos_sdk_python-1.0.0/agentos_sdk/protocol.py +0 -239
- agentos_sdk_python-1.0.0/tests/test_modelkit.py +0 -79
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/.gitignore +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/LICENSE +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/agentos_sdk/clients/agentkit.py +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/agentos_sdk/clients/appkit.py +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/agentos_sdk/clients/authkit.py +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/agentos_sdk/clients/cronkit.py +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/agentos_sdk/clients/discoverykit.py +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/agentos_sdk/clients/systemkit.py +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/agentos_sdk/clients/toolkit.py +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/agentos_sdk/clients/transferkit.py +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/agentos_sdk/handlers.py +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/agentos_sdk/py.typed +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/tests/test_agentkit.py +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/tests/test_cronkit.py +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/tests/test_protocol.py +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/tests/test_toolkit.py +0 -0
- {agentos_sdk_python-1.0.0 → agentos_sdk_python-1.1.0}/tests/typecheck/toolkit_usage.py +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.1.0 - Unreleased
|
|
4
|
+
|
|
5
|
+
- Added HarnessKit support for the authenticated `/harnesskit/*` Gateway routes:
|
|
6
|
+
`sdk.harnesskit` (with `health`, `get_runtime`, `switch_engine`,
|
|
7
|
+
`list_threads`, `get_thread`, `rename_thread`, `delete_thread`, `start_run`,
|
|
8
|
+
`submit_command`, `events`, `get_run_result`, `get_operational_snapshot`,
|
|
9
|
+
`request` and `request_stream`, plus camelCase aliases) and the explicit-token
|
|
10
|
+
`HarnessKitClient` (`sdk.harnessKit`). Calls use the app token from
|
|
11
|
+
`register_bundle` and refresh it once on `401`/`403`. `events()` is a
|
|
12
|
+
resumable SSE stream (`after_sequence`, `run_id`) that releases its connection
|
|
13
|
+
when finished or closed. Rejected commands (HTTP `400` with a receipt body) are
|
|
14
|
+
returned as receipts. Thread/run IDs and `request()` paths are validated so
|
|
15
|
+
they cannot escape the Harness API root. The `HarnessKit*` type declarations
|
|
16
|
+
were added.
|
|
17
|
+
- Added NotifyKit support: `sdk.notifykit.publish(request=...)` and the
|
|
18
|
+
explicit-token `NotifyKitClient` (`sdk.notifyKit`) for
|
|
19
|
+
`POST /notifykit/notifications`, with `NotifyKitEvent`, `NotifyKitNotification`,
|
|
20
|
+
`NotifyKitPublishResult` and `NotifyKitLevel` type declarations. Invalid events
|
|
21
|
+
and rate limits (`retryAfterSeconds`) surface as `ApiError`.
|
|
22
|
+
- Fixed a query string already present in a request path being dropped when no
|
|
23
|
+
`query` argument was given.
|
|
24
|
+
- Added ModelKit decision inference: task `"decision"`, modality `"decisions"`
|
|
25
|
+
and `sdk.modelkit.decision.create(...)` (`POST /modelkit/decision`), plus the
|
|
26
|
+
`DecisionRequest`, `DecisionQuestion`, `DecisionResponse`, `DecisionAnswer` and
|
|
27
|
+
`DecisionUsage` type declarations.
|
|
28
|
+
- Added app model registration: `list_app_models`, `register_app_model`,
|
|
29
|
+
`update_app_model`, `unregister_app_model` and `toggle_app_model` for
|
|
30
|
+
`/modelkit/app-models` (with camelCase aliases). Write calls reuse the app token
|
|
31
|
+
from `register_bundle` and refresh it once on `401`. `ModelKitClient` exposes
|
|
32
|
+
the same methods with an explicit `bearer_token` argument.
|
|
33
|
+
- Model info now reports `isAppModel` and `appBundleId` for models registered
|
|
34
|
+
by apps, and `AppModel*` type declarations were added.
|
|
35
|
+
- Fixed models with `decisions` output being reported as `text` output.
|
|
36
|
+
|
|
37
|
+
## 1.0.0 - 2026-09-01
|
|
38
|
+
|
|
39
|
+
- Updated AgentKit for the LiteAgent SDK 0.4 gateway contract.
|
|
40
|
+
- Added support and coverage for recursively nested inline agents through
|
|
41
|
+
`Capability.subAgentList`.
|
|
42
|
+
- **Breaking:** Removed the AgentKit agent CRUD methods because the corresponding
|
|
43
|
+
gateway routes no longer exist.
|
|
44
|
+
- **Breaking:** `init_session` now requires a Capability request body and no
|
|
45
|
+
longer accepts the removed `agent_id` argument.
|
|
46
|
+
- Removed the obsolete `agentId` field from AgentKit message type declarations.
|
|
47
|
+
|
|
48
|
+
## 0.2.0 - 2026-07-17
|
|
49
|
+
|
|
50
|
+
- **Breaking:** Updated OpenTool server identities to daemon 0.5
|
|
51
|
+
`namespace` / `name` / `version` fields.
|
|
52
|
+
- Added public `ToolContentState` and `ToolLifecycleEventDto` types.
|
|
53
|
+
- Added `materializedArtifactDigest` and `contentState` ToolKit metadata.
|
|
54
|
+
- Added OpenTool server declarations, registration statuses, and AppKit provisioning/availability events.
|
|
55
|
+
- Added paginated AgentKit history, summary history, and process history APIs.
|
|
56
|
+
- Added child-session routing and structured function-call lifecycle errors.
|
|
57
|
+
- Added ToolKit server metadata types and hardened SSE parsing.
|
|
58
|
+
- Added automatic app registration Bearer authentication to ToolKit list and load requests.
|
|
59
|
+
- Added one-time app token refresh and retry for ToolKit requests that return 401 or 403.
|
|
60
|
+
- Added `sdk.toolkit.call()` for non-streaming tool function calls.
|
|
61
|
+
- Added `sdk.toolkit.stream_call()` / `streamCall()` with typed stream events and safe
|
|
62
|
+
response closure after normal completion, errors, cancellation, or explicit early close.
|
|
63
|
+
- **Breaking:** Replaced `AgentOSEventHandler.on_call_app` / `onCallApp` with `on_app_event` / `onAppEvent`.
|
|
64
|
+
|
|
65
|
+
## 0.1.0 - 2026-06-12
|
|
66
|
+
|
|
67
|
+
- Initial public release of the AgentOS Python SDK.
|
|
68
|
+
- Added async clients for AgentOS, AgentKit, CronKit, ModelKit, and ToolKit APIs.
|
|
69
|
+
- Added facade helpers for bearer token reuse, token refresh retry, stream callbacks, and TS-style alias compatibility.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: agentos-sdk-python
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: Async Python SDK for AgentOS APIs.
|
|
5
5
|
Project-URL: Repository, https://gitlab.litevar.com/litevar/agentos/agentos-sdk-python
|
|
6
6
|
Project-URL: Issues, https://gitlab.litevar.com/litevar/agentos/agentos-sdk-python/-/issues
|
|
7
7
|
Author: LiteVar
|
|
8
8
|
License-Expression: MIT
|
|
9
9
|
License-File: LICENSE
|
|
10
|
-
Keywords: agentkit,agentos,async,modelkit,sdk,toolkit
|
|
10
|
+
Keywords: agentkit,agentos,async,harnesskit,modelkit,notifykit,sdk,toolkit
|
|
11
11
|
Classifier: Development Status :: 3 - Alpha
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
13
13
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -95,7 +95,7 @@ Use `async with AgentOSSDK(...)` or call `await sdk.aclose()` when done.
|
|
|
95
95
|
|
|
96
96
|
## Token Handling
|
|
97
97
|
|
|
98
|
-
`sdk.agentos.register_bundle(...)` stores the active app token. Protected facade methods in `sdk.agentkit`, `sdk.cronkit`, `sdk.authkit`, `sdk.discoverykit`, and `sdk.
|
|
98
|
+
`sdk.agentos.register_bundle(...)` stores the active app token. Protected facade methods in `sdk.agentkit`, `sdk.cronkit`, `sdk.authkit`, `sdk.discoverykit`, `sdk.transferkit`, `sdk.harnesskit`, and `sdk.notifykit` use that token automatically.
|
|
99
99
|
|
|
100
100
|
If a protected call fails with HTTP `401`, HTTP `403`, or recognizable invalid-token text, the SDK re-runs registration for the same bundle once and retries the call. The cached bundle is a defensive copy and retains its `opentoolServers` declarations during refresh.
|
|
101
101
|
|
|
@@ -261,6 +261,106 @@ ModelKit also supports:
|
|
|
261
261
|
- `sdk.modelkit.asr.transcribe(...)`
|
|
262
262
|
- `sdk.modelkit.tts.synthesize(...)`
|
|
263
263
|
- `sdk.modelkit.tts.list_voices()`
|
|
264
|
+
- `sdk.modelkit.decision.create(...)`: typed-question decisions, see below
|
|
265
|
+
- `sdk.modelkit.list_app_models()` and the app-model registration methods, see below
|
|
266
|
+
|
|
267
|
+
### Decision
|
|
268
|
+
|
|
269
|
+
Decision models (task `"decision"`, served by llama.cpp `/v1/systemone`) do not
|
|
270
|
+
generate text. They score the options of typed questions about a given `state`.
|
|
271
|
+
`POST /modelkit/decision` needs no app token.
|
|
272
|
+
|
|
273
|
+
```python
|
|
274
|
+
async with AgentOSSDK() as sdk:
|
|
275
|
+
decision_models = await sdk.modelkit.list_models_by_task("decision")
|
|
276
|
+
|
|
277
|
+
response = await sdk.modelkit.decision.create(
|
|
278
|
+
{
|
|
279
|
+
"model": decision_models[0]["name"], # optional, the gateway picks a default
|
|
280
|
+
"state": {"text": "My order is late and I am furious!"},
|
|
281
|
+
"questions": {
|
|
282
|
+
# Pick one option (option -> description).
|
|
283
|
+
"route": {
|
|
284
|
+
"type": "choice",
|
|
285
|
+
"instructions": "Which team should handle this?",
|
|
286
|
+
"criteria": {
|
|
287
|
+
"billing": "Payment and invoices",
|
|
288
|
+
"support": "Product or delivery problems",
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
# Ordinal scale with 2-10 level descriptions.
|
|
292
|
+
"urgency": {
|
|
293
|
+
"type": "score",
|
|
294
|
+
"instructions": "How urgent is this?",
|
|
295
|
+
"criteria": ["low", "medium", "high"],
|
|
296
|
+
},
|
|
297
|
+
# Yes/no judgement. "criteria" ({"true": ..., "false": ...}) is optional.
|
|
298
|
+
"angry": {"type": "noul", "instructions": "Is the user angry?"},
|
|
299
|
+
},
|
|
300
|
+
# "images": ["data:image/png;base64,..."], # for models with image input
|
|
301
|
+
}
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
route = response["answers"]["route"]
|
|
305
|
+
print(route["choice"], route["confidence"])
|
|
306
|
+
print(response["answers"]["urgency"]["score"], response["answers"]["angry"]["noul"])
|
|
307
|
+
print(response["usage"]["input_tokens"], response["usage"]["output_tokens"])
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
The response is returned as sent by the server (wire field names). Each answer
|
|
311
|
+
carries the field matching its question `type` (`choice` + `confidence`,
|
|
312
|
+
`score`, or `noul`); `probabilities` and `legend` are passed through untouched.
|
|
313
|
+
`agentos_sdk` exports `DecisionRequest`, `DecisionQuestion`, `DecisionResponse`
|
|
314
|
+
and related `TypedDict` definitions for annotations.
|
|
315
|
+
|
|
316
|
+
### App models
|
|
317
|
+
|
|
318
|
+
Apps can register their own models into the gateway. Registered models show up
|
|
319
|
+
in `list_models()` / `list_models_by_task()` with `isAppModel: True` and the
|
|
320
|
+
owning `appBundleId`.
|
|
321
|
+
|
|
322
|
+
```python
|
|
323
|
+
async with AgentOSSDK() as sdk:
|
|
324
|
+
await sdk.agentos.register_bundle({"bundleId": "com.example.app"})
|
|
325
|
+
|
|
326
|
+
# Register (or replace) a model. Only "id" and "name" are required.
|
|
327
|
+
result = await sdk.modelkit.register_app_model(
|
|
328
|
+
request={
|
|
329
|
+
"id": "my-router",
|
|
330
|
+
"name": "my-router",
|
|
331
|
+
"task": "decision",
|
|
332
|
+
"baseUrl": "http://127.0.0.1:9000",
|
|
333
|
+
"apiKey": "upstream-secret", # stored by the server, never returned
|
|
334
|
+
}
|
|
335
|
+
)
|
|
336
|
+
print(result.get("updated")) # True when an existing model of this app was replaced
|
|
337
|
+
|
|
338
|
+
# Partial update: unset fields stay unchanged.
|
|
339
|
+
await sdk.modelkit.update_app_model(
|
|
340
|
+
model_id="my-router", request={"description": "Routes support tickets"}
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
# Enable/disable without deleting.
|
|
344
|
+
await sdk.modelkit.toggle_app_model(model_id="my-router")
|
|
345
|
+
|
|
346
|
+
# List every app-registered model (public, no token needed).
|
|
347
|
+
for model in await sdk.modelkit.list_app_models():
|
|
348
|
+
print(model["id"], model["appBundleId"], model["isDisabled"])
|
|
349
|
+
|
|
350
|
+
await sdk.modelkit.unregister_app_model(model_id="my-router")
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
Write calls attach the app token automatically and refresh it once on `401`.
|
|
354
|
+
They raise `ApiError` carrying the server status: `401` invalid token, `403`
|
|
355
|
+
not the owning app or `appBundleId` mismatch, `404` unknown id, `409` the id
|
|
356
|
+
belongs to another app, `400` invalid body or unknown `task`.
|
|
357
|
+
|
|
358
|
+
Decision models are normalized by the server: input `text` (+ optional
|
|
359
|
+
`image`), output `decisions`, and `stream` / `tool_call` / `reasoning` all
|
|
360
|
+
`False`. The low-level `ModelKitClient` (`sdk.modelKit`) offers the same
|
|
361
|
+
app-model methods with the bearer token as the first argument, for example
|
|
362
|
+
`sdk.modelKit.register_app_model(token, request)`. camelCase aliases such as
|
|
363
|
+
`registerAppModel` and `listAppModels` are available on both.
|
|
264
364
|
|
|
265
365
|
## ToolKit
|
|
266
366
|
|
|
@@ -416,9 +516,145 @@ optional `server` identity uses `namespace`, `name`, and `version`;
|
|
|
416
516
|
`materializedArtifactDigest` identifies installed content when available, and
|
|
417
517
|
`contentState` reports whether it is current.
|
|
418
518
|
|
|
519
|
+
## HarnessKit
|
|
520
|
+
|
|
521
|
+
HarnessKit forwards requests through the Gateway to the Harness runtime selected
|
|
522
|
+
for the currently registered AppKit bundle. Register the app with
|
|
523
|
+
`sdk.agentos.register_bundle()` first. An installable process App must declare
|
|
524
|
+
`harnessKit` to receive a Harness runtime; the built-in Harness App uses the
|
|
525
|
+
host's default runtime. All `sdk.harnesskit` methods use the active AppKit token
|
|
526
|
+
and retry once after an authentication failure.
|
|
527
|
+
|
|
528
|
+
| Method | Parameters | Description |
|
|
529
|
+
| --- | --- | --- |
|
|
530
|
+
| `health()` | none | Checks Harness runtime health through the authenticated Gateway route. |
|
|
531
|
+
| `get_runtime()` / `switch_engine(engine=...)` | `engine` | Reads the runtime engine or requests an engine switch. |
|
|
532
|
+
| `list_threads()` / `get_thread(thread_id=...)` | `thread_id` | Lists durable threads or reads one thread snapshot. |
|
|
533
|
+
| `rename_thread(thread_id=..., title=...)` / `delete_thread(thread_id=...)` | `thread_id`, `title` | Updates a thread title or deletes an idle thread. |
|
|
534
|
+
| `start_run(thread_id=..., request=...)` | `thread_id`, run request | Starts a Harness run and returns its `runId`. |
|
|
535
|
+
| `submit_command(thread_id=..., command=...)` | `thread_id`, command | Submits work or control commands; rejected commands return their receipt. |
|
|
536
|
+
| `events(thread_id=..., after_sequence=0, run_id=None)` | `thread_id`, `after_sequence`, `run_id` | Opens a resumable SSE stream of typed events. |
|
|
537
|
+
| `get_run_result(run_id=...)` | `run_id` | Reads the current or terminal run result. |
|
|
538
|
+
| `get_operational_snapshot()` | none | Reads an operational snapshot when the runtime supports it. |
|
|
539
|
+
| `request(path, ...)` | Harness-relative path, `method`, `query`, `data`, `headers` | Calls other JSON Harness endpoints through `/harnesskit/*`. |
|
|
540
|
+
| `request_stream(path, ...)` | same as `request` | Opens a raw streaming response for other Harness endpoints. |
|
|
541
|
+
|
|
542
|
+
```python
|
|
543
|
+
import uuid
|
|
544
|
+
|
|
545
|
+
from agentos_sdk import AgentOSSDK
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
async def main():
|
|
549
|
+
async with AgentOSSDK() as sdk:
|
|
550
|
+
await sdk.agentos.register_bundle({"bundleId": "com.demo.harness-app"})
|
|
551
|
+
|
|
552
|
+
runtime = await sdk.harnesskit.get_runtime()
|
|
553
|
+
print("Harness engine:", runtime.get("activeEngine", runtime["engine"]))
|
|
554
|
+
|
|
555
|
+
accepted = await sdk.harnesskit.start_run(
|
|
556
|
+
thread_id="research-thread",
|
|
557
|
+
request={
|
|
558
|
+
"requestId": str(uuid.uuid4()),
|
|
559
|
+
"goal": "Summarize the latest project status",
|
|
560
|
+
"llmConfig": {
|
|
561
|
+
"provider": "openai-compatible",
|
|
562
|
+
"baseUrl": "http://127.0.0.1:1234/v1",
|
|
563
|
+
"model": "local-model",
|
|
564
|
+
},
|
|
565
|
+
},
|
|
566
|
+
)
|
|
567
|
+
|
|
568
|
+
async for event in sdk.harnesskit.events(
|
|
569
|
+
thread_id="research-thread",
|
|
570
|
+
run_id=accepted["runId"],
|
|
571
|
+
after_sequence=0,
|
|
572
|
+
):
|
|
573
|
+
print(event["type"], event["data"])
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
`events()` returns an async generator and opens the connection on first
|
|
577
|
+
iteration. Pass the `sequence` of the last event you processed as
|
|
578
|
+
`after_sequence` to resume a stream. Frames that are not JSON objects raise
|
|
579
|
+
`ValueError`. To stop early, call `aclose()` on the generator so the connection
|
|
580
|
+
is released:
|
|
581
|
+
|
|
582
|
+
```python
|
|
583
|
+
events = sdk.harnesskit.events(thread_id="research-thread")
|
|
584
|
+
try:
|
|
585
|
+
async for event in events:
|
|
586
|
+
if event["type"] == "run.completed":
|
|
587
|
+
break
|
|
588
|
+
finally:
|
|
589
|
+
await events.aclose()
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
Request and response bodies are plain dicts, so newer Harness fields pass
|
|
593
|
+
through untouched; the exported `HarnessKit*` `TypedDict`s (for example
|
|
594
|
+
`HarnessKitRunRequest` and `HarnessKitCommand`) are only annotations. Notes:
|
|
595
|
+
|
|
596
|
+
- A command the Harness rejects comes back as HTTP `400` with a receipt body.
|
|
597
|
+
`submit_command()` returns that receipt (`status == "rejected"`) instead of
|
|
598
|
+
raising; every other error raises `ApiError`.
|
|
599
|
+
- Runtime controls (`get_runtime()`, `switch_engine()`) and
|
|
600
|
+
`get_operational_snapshot()` are reserved for the built-in Harness App; other
|
|
601
|
+
Apps get an `ApiError` with status `403`. `get_operational_snapshot()` also
|
|
602
|
+
answers `501` when the configured engine does not expose the optional reader.
|
|
603
|
+
- Thread and run IDs are percent-encoded. Empty IDs and `.` / `..` raise
|
|
604
|
+
`ValueError` before any request is sent.
|
|
605
|
+
- `request()` and `request_stream()` accept paths relative to the Harness API
|
|
606
|
+
root (the `/harnesskit` prefix is optional). Absolute URLs, `.` / `..` path
|
|
607
|
+
segments, and malformed URL encoding raise `ValueError`, and any
|
|
608
|
+
caller-supplied `authorization` header is replaced by the AppKit token. A query
|
|
609
|
+
string in `path` is kept; keys in `query` override the same keys there.
|
|
610
|
+
|
|
611
|
+
## NotifyKit
|
|
612
|
+
|
|
613
|
+
NotifyKit lets an App submit user-facing events to the AgentOS notification
|
|
614
|
+
center. Register the app with `sdk.agentos.register_bundle()` first;
|
|
615
|
+
`sdk.notifykit.publish()` uses the active AppKit token and retries once after an
|
|
616
|
+
authentication failure.
|
|
617
|
+
|
|
618
|
+
```python
|
|
619
|
+
from agentos_sdk import AgentOSSDK, ApiError
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
async def main():
|
|
623
|
+
async with AgentOSSDK() as sdk:
|
|
624
|
+
await sdk.agentos.register_bundle({"bundleId": "com.demo.billing"})
|
|
625
|
+
|
|
626
|
+
try:
|
|
627
|
+
result = await sdk.notifykit.publish(
|
|
628
|
+
request={
|
|
629
|
+
"eventType": "billing.invoice_ready",
|
|
630
|
+
"title": "Invoice ready",
|
|
631
|
+
"message": "Your October invoice is ready.",
|
|
632
|
+
"subjectId": "invoice-1",
|
|
633
|
+
}
|
|
634
|
+
)
|
|
635
|
+
except ApiError as error:
|
|
636
|
+
if error.status == 429:
|
|
637
|
+
print("Retry in", error.data["retryAfterSeconds"], "seconds")
|
|
638
|
+
else:
|
|
639
|
+
raise
|
|
640
|
+
else:
|
|
641
|
+
print(result["accepted"], result["notification"]["id"])
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
An App only provides content: `eventType` (a lowercase dotted name such as
|
|
645
|
+
`task.completed`), `title`, `message`, and an optional `subjectId`. The platform
|
|
646
|
+
decides the level, category, grouping, and deduplication, so repeated events can
|
|
647
|
+
collapse into one notification whose `count` grows. Invalid events raise
|
|
648
|
+
`ApiError` with status `400`. When the App exceeds the per-minute rate limit the
|
|
649
|
+
call raises `ApiError` with status `429`; `error.data["retryAfterSeconds"]` says
|
|
650
|
+
how long to wait.
|
|
651
|
+
|
|
419
652
|
## Direct Clients
|
|
420
653
|
|
|
421
|
-
The low-level clients are available for explicit-token or custom transport usage
|
|
654
|
+
The low-level clients are available for explicit-token or custom transport usage.
|
|
655
|
+
`sdk.harnessKit` and `sdk.notifyKit` expose the HarnessKit and NotifyKit clients
|
|
656
|
+
on an existing `AgentOSSDK`; they take the AppKit bearer token as the first
|
|
657
|
+
argument:
|
|
422
658
|
|
|
423
659
|
```python
|
|
424
660
|
from agentos_sdk.clients import AgentKitClient, CronKitClient, ModelKitClient
|
|
@@ -61,7 +61,7 @@ sdk = AgentOSSDK(
|
|
|
61
61
|
|
|
62
62
|
## Token 处理
|
|
63
63
|
|
|
64
|
-
`sdk.agentos.register_bundle(...)` 会保存当前 app token。`sdk.agentkit`、`sdk.cronkit`、`sdk.authkit`、`sdk.discoverykit` 和 `sdk.
|
|
64
|
+
`sdk.agentos.register_bundle(...)` 会保存当前 app token。`sdk.agentkit`、`sdk.cronkit`、`sdk.authkit`、`sdk.discoverykit`、`sdk.transferkit`、`sdk.harnesskit` 和 `sdk.notifykit` 下的受保护 facade 方法会自动使用该 token。
|
|
65
65
|
|
|
66
66
|
如果请求遇到 HTTP `401`、HTTP `403`,或响应文本包含可识别的 token 失效信息,SDK 会使用同一个 bundle 重新注册一次,并重试当前请求一次。SDK 会保存 bundle 的防御性副本,因此刷新 token 时会保留原始 `opentoolServers` 声明。
|
|
67
67
|
|
|
@@ -227,6 +227,102 @@ ModelKit 还支持:
|
|
|
227
227
|
- `sdk.modelkit.asr.transcribe(...)`
|
|
228
228
|
- `sdk.modelkit.tts.synthesize(...)`
|
|
229
229
|
- `sdk.modelkit.tts.list_voices()`
|
|
230
|
+
- `sdk.modelkit.decision.create(...)`:带类型问题的 decision 推理,见下文
|
|
231
|
+
- `sdk.modelkit.list_app_models()` 及 app model 注册相关方法,见下文
|
|
232
|
+
|
|
233
|
+
### Decision
|
|
234
|
+
|
|
235
|
+
Decision 模型(task 为 `"decision"`,由 llama.cpp `/v1/systemone` 提供)不生成
|
|
236
|
+
文本,而是针对给定的 `state`,对带类型问题的选项打分。`POST /modelkit/decision`
|
|
237
|
+
不需要 app token。
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
async with AgentOSSDK() as sdk:
|
|
241
|
+
decision_models = await sdk.modelkit.list_models_by_task("decision")
|
|
242
|
+
|
|
243
|
+
response = await sdk.modelkit.decision.create(
|
|
244
|
+
{
|
|
245
|
+
"model": decision_models[0]["name"], # 可选,缺省时由网关选择默认模型
|
|
246
|
+
"state": {"text": "我的订单迟迟不到,太让人生气了!"},
|
|
247
|
+
"questions": {
|
|
248
|
+
# 单选(选项 -> 描述)
|
|
249
|
+
"route": {
|
|
250
|
+
"type": "choice",
|
|
251
|
+
"instructions": "应该交给哪个团队处理?",
|
|
252
|
+
"criteria": {
|
|
253
|
+
"billing": "支付与发票",
|
|
254
|
+
"support": "商品或物流问题",
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
# 有序评分,2-10 个等级描述
|
|
258
|
+
"urgency": {
|
|
259
|
+
"type": "score",
|
|
260
|
+
"instructions": "这件事有多紧急?",
|
|
261
|
+
"criteria": ["低", "中", "高"],
|
|
262
|
+
},
|
|
263
|
+
# 是/否判断,"criteria"({"true": ..., "false": ...})可选
|
|
264
|
+
"angry": {"type": "noul", "instructions": "用户是否生气了?"},
|
|
265
|
+
},
|
|
266
|
+
# "images": ["data:image/png;base64,..."], # 支持图片输入的模型可用
|
|
267
|
+
}
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
route = response["answers"]["route"]
|
|
271
|
+
print(route["choice"], route["confidence"])
|
|
272
|
+
print(response["answers"]["urgency"]["score"], response["answers"]["angry"]["noul"])
|
|
273
|
+
print(response["usage"]["input_tokens"], response["usage"]["output_tokens"])
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
响应按服务端原样返回(使用 wire 字段名)。每个答案包含与问题 `type` 对应的字段
|
|
277
|
+
(`choice` + `confidence`、`score` 或 `noul`);`probabilities` 和 `legend` 原样透传。
|
|
278
|
+
`agentos_sdk` 导出了 `DecisionRequest`、`DecisionQuestion`、`DecisionResponse`
|
|
279
|
+
等 `TypedDict` 定义,可用于类型标注。
|
|
280
|
+
|
|
281
|
+
### App model
|
|
282
|
+
|
|
283
|
+
App 可以把自己的模型注册到网关。注册后的模型会出现在 `list_models()` /
|
|
284
|
+
`list_models_by_task()` 中,并带有 `isAppModel: True` 与所属的 `appBundleId`。
|
|
285
|
+
|
|
286
|
+
```python
|
|
287
|
+
async with AgentOSSDK() as sdk:
|
|
288
|
+
await sdk.agentos.register_bundle({"bundleId": "com.example.app"})
|
|
289
|
+
|
|
290
|
+
# 注册(或替换)模型,只有 "id" 和 "name" 必填。
|
|
291
|
+
result = await sdk.modelkit.register_app_model(
|
|
292
|
+
request={
|
|
293
|
+
"id": "my-router",
|
|
294
|
+
"name": "my-router",
|
|
295
|
+
"task": "decision",
|
|
296
|
+
"baseUrl": "http://127.0.0.1:9000",
|
|
297
|
+
"apiKey": "upstream-secret", # 由服务端保存,不会再返回
|
|
298
|
+
}
|
|
299
|
+
)
|
|
300
|
+
print(result.get("updated")) # 替换了该 app 已有的同 id 模型时为 True
|
|
301
|
+
|
|
302
|
+
# 局部更新:未设置的字段保持不变。
|
|
303
|
+
await sdk.modelkit.update_app_model(
|
|
304
|
+
model_id="my-router", request={"description": "分流客服工单"}
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
# 启用/停用,无需删除。
|
|
308
|
+
await sdk.modelkit.toggle_app_model(model_id="my-router")
|
|
309
|
+
|
|
310
|
+
# 列出所有 app 注册的模型(公开接口,无需 token)。
|
|
311
|
+
for model in await sdk.modelkit.list_app_models():
|
|
312
|
+
print(model["id"], model["appBundleId"], model["isDisabled"])
|
|
313
|
+
|
|
314
|
+
await sdk.modelkit.unregister_app_model(model_id="my-router")
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
写操作会自动附带 app token,并在 `401` 时刷新一次。失败时抛出带服务端状态码的
|
|
318
|
+
`ApiError`:`401` token 无效,`403` 不是所属 app 或 `appBundleId` 不匹配,
|
|
319
|
+
`404` id 不存在,`409` id 属于其他 app,`400` 请求体非法或 `task` 未知。
|
|
320
|
+
|
|
321
|
+
Decision 模型会被服务端规范化:输入为 `text`(可选 `image`),输出为
|
|
322
|
+
`decisions`,`stream` / `tool_call` / `reasoning` 均为 `False`。底层
|
|
323
|
+
`ModelKitClient`(`sdk.modelKit`)提供同样的 app model 方法,只是 bearer token
|
|
324
|
+
作为第一个参数显式传入,例如 `sdk.modelKit.register_app_model(token, request)`。
|
|
325
|
+
两者都提供 `registerAppModel`、`listAppModels` 等 camelCase 别名。
|
|
230
326
|
|
|
231
327
|
## ToolKit
|
|
232
328
|
|
|
@@ -378,9 +474,133 @@ async with AgentOSSDK() as sdk:
|
|
|
378
474
|
`materializedArtifactDigest` 在可用时标识已安装内容,`contentState` 表示内容
|
|
379
475
|
是否为最新状态。
|
|
380
476
|
|
|
477
|
+
## HarnessKit
|
|
478
|
+
|
|
479
|
+
HarnessKit 通过 Gateway 把请求转发到当前已注册 AppKit bundle 所对应的 Harness
|
|
480
|
+
runtime。请先调用 `sdk.agentos.register_bundle()` 注册应用。安装型进程 App 需要声明
|
|
481
|
+
`harnessKit` 才能获得 Harness runtime;内置 Harness App 使用宿主的默认 runtime。
|
|
482
|
+
`sdk.harnesskit` 的所有方法都会使用当前 AppKit token,并在鉴权失败后重试一次。
|
|
483
|
+
|
|
484
|
+
| 方法 | 参数 | 说明 |
|
|
485
|
+
| --- | --- | --- |
|
|
486
|
+
| `health()` | 无 | 通过已鉴权的 Gateway 路由检查 Harness runtime 健康状态。 |
|
|
487
|
+
| `get_runtime()` / `switch_engine(engine=...)` | `engine` | 读取运行时引擎,或请求切换引擎。 |
|
|
488
|
+
| `list_threads()` / `get_thread(thread_id=...)` | `thread_id` | 列出持久化会话线程,或读取单个线程快照。 |
|
|
489
|
+
| `rename_thread(thread_id=..., title=...)` / `delete_thread(thread_id=...)` | `thread_id`、`title` | 修改线程标题,或删除空闲线程。 |
|
|
490
|
+
| `start_run(thread_id=..., request=...)` | `thread_id`、run 请求 | 启动一次 Harness run 并返回其 `runId`。 |
|
|
491
|
+
| `submit_command(thread_id=..., command=...)` | `thread_id`、命令 | 提交工作或控制命令;被拒绝的命令会返回其回执。 |
|
|
492
|
+
| `events(thread_id=..., after_sequence=0, run_id=None)` | `thread_id`、`after_sequence`、`run_id` | 打开可续传的 SSE 事件流,返回带类型标注的事件。 |
|
|
493
|
+
| `get_run_result(run_id=...)` | `run_id` | 读取 run 的当前结果或终态结果。 |
|
|
494
|
+
| `get_operational_snapshot()` | 无 | 在运行时支持时读取运行状态快照。 |
|
|
495
|
+
| `request(path, ...)` | 相对 Harness 的路径、`method`、`query`、`data`、`headers` | 通过 `/harnesskit/*` 调用其它 JSON Harness 端点。 |
|
|
496
|
+
| `request_stream(path, ...)` | 与 `request` 相同 | 为其它 Harness 端点打开原始流式响应。 |
|
|
497
|
+
|
|
498
|
+
```python
|
|
499
|
+
import uuid
|
|
500
|
+
|
|
501
|
+
from agentos_sdk import AgentOSSDK
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
async def main():
|
|
505
|
+
async with AgentOSSDK() as sdk:
|
|
506
|
+
await sdk.agentos.register_bundle({"bundleId": "com.demo.harness-app"})
|
|
507
|
+
|
|
508
|
+
runtime = await sdk.harnesskit.get_runtime()
|
|
509
|
+
print("Harness 引擎:", runtime.get("activeEngine", runtime["engine"]))
|
|
510
|
+
|
|
511
|
+
accepted = await sdk.harnesskit.start_run(
|
|
512
|
+
thread_id="research-thread",
|
|
513
|
+
request={
|
|
514
|
+
"requestId": str(uuid.uuid4()),
|
|
515
|
+
"goal": "总结项目的最新进展",
|
|
516
|
+
"llmConfig": {
|
|
517
|
+
"provider": "openai-compatible",
|
|
518
|
+
"baseUrl": "http://127.0.0.1:1234/v1",
|
|
519
|
+
"model": "local-model",
|
|
520
|
+
},
|
|
521
|
+
},
|
|
522
|
+
)
|
|
523
|
+
|
|
524
|
+
async for event in sdk.harnesskit.events(
|
|
525
|
+
thread_id="research-thread",
|
|
526
|
+
run_id=accepted["runId"],
|
|
527
|
+
after_sequence=0,
|
|
528
|
+
):
|
|
529
|
+
print(event["type"], event["data"])
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
`events()` 返回异步生成器,首次迭代时才会建立连接。续传时把已处理的最后一个事件的
|
|
533
|
+
`sequence` 作为 `after_sequence` 传入即可。如果某一帧不是 JSON 对象,会抛出
|
|
534
|
+
`ValueError`。需要提前结束时,对生成器调用 `aclose()` 以释放连接:
|
|
535
|
+
|
|
536
|
+
```python
|
|
537
|
+
events = sdk.harnesskit.events(thread_id="research-thread")
|
|
538
|
+
try:
|
|
539
|
+
async for event in events:
|
|
540
|
+
if event["type"] == "run.completed":
|
|
541
|
+
break
|
|
542
|
+
finally:
|
|
543
|
+
await events.aclose()
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
请求体与响应体都是普通 dict,因此 Harness 新增的字段会原样透传;导出的
|
|
547
|
+
`HarnessKit*` `TypedDict`(例如 `HarnessKitRunRequest`、`HarnessKitCommand`)只用于类型标注。说明:
|
|
548
|
+
|
|
549
|
+
- Harness 拒绝的命令会以 HTTP `400` 加回执体返回。`submit_command()` 会把该回执
|
|
550
|
+
(`status == "rejected"`)作为结果返回而不是抛出异常;其它错误一律抛出 `ApiError`。
|
|
551
|
+
- 运行时控制(`get_runtime()`、`switch_engine()`)和 `get_operational_snapshot()`
|
|
552
|
+
仅限内置 Harness App 使用,其它 App 会得到状态码为 `403` 的 `ApiError`。当所配置的
|
|
553
|
+
引擎没有提供可选的读取器时,`get_operational_snapshot()` 还会返回 `501`。
|
|
554
|
+
- 线程 ID 与 run ID 会做百分号编码。空 ID 以及 `.` / `..` 会在发出请求前抛出
|
|
555
|
+
`ValueError`。
|
|
556
|
+
- `request()` 和 `request_stream()` 接受相对 Harness API 根的路径(`/harnesskit`
|
|
557
|
+
前缀可省略)。绝对 URL、`.` / `..` 路径段以及格式错误的 URL 编码会抛出
|
|
558
|
+
`ValueError`,调用方传入的 `authorization` 头会被 AppKit token 替换。`path` 中自带的
|
|
559
|
+
查询串会被保留,`query` 中的同名键会覆盖它。
|
|
560
|
+
|
|
561
|
+
## NotifyKit
|
|
562
|
+
|
|
563
|
+
NotifyKit 让 App 向 AgentOS 通知中心提交面向用户的事件。请先调用
|
|
564
|
+
`sdk.agentos.register_bundle()` 注册应用;`sdk.notifykit.publish()` 会使用当前
|
|
565
|
+
AppKit token,并在鉴权失败后重试一次。
|
|
566
|
+
|
|
567
|
+
```python
|
|
568
|
+
from agentos_sdk import AgentOSSDK, ApiError
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
async def main():
|
|
572
|
+
async with AgentOSSDK() as sdk:
|
|
573
|
+
await sdk.agentos.register_bundle({"bundleId": "com.demo.billing"})
|
|
574
|
+
|
|
575
|
+
try:
|
|
576
|
+
result = await sdk.notifykit.publish(
|
|
577
|
+
request={
|
|
578
|
+
"eventType": "billing.invoice_ready",
|
|
579
|
+
"title": "账单已生成",
|
|
580
|
+
"message": "你的 10 月账单已生成。",
|
|
581
|
+
"subjectId": "invoice-1",
|
|
582
|
+
}
|
|
583
|
+
)
|
|
584
|
+
except ApiError as error:
|
|
585
|
+
if error.status == 429:
|
|
586
|
+
print("请在", error.data["retryAfterSeconds"], "秒后重试")
|
|
587
|
+
else:
|
|
588
|
+
raise
|
|
589
|
+
else:
|
|
590
|
+
print(result["accepted"], result["notification"]["id"])
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
App 只需提供内容:`eventType`(小写点分名称,例如 `task.completed`)、`title`、
|
|
594
|
+
`message`,以及可选的 `subjectId`。通知级别、分类、分组和去重由平台决定,因此重复事件
|
|
595
|
+
可能被合并为同一条通知,其 `count` 会递增。无效事件会抛出状态码为 `400` 的
|
|
596
|
+
`ApiError`。当 App 超出每分钟的速率限制时,调用会抛出状态码为 `429` 的 `ApiError`,
|
|
597
|
+
`error.data["retryAfterSeconds"]` 表示需要等待的秒数。
|
|
598
|
+
|
|
381
599
|
## 直接使用低层 Client
|
|
382
600
|
|
|
383
|
-
低层 client 可用于显式 token
|
|
601
|
+
低层 client 可用于显式 token 或自定义传输层场景。`sdk.harnessKit` 和 `sdk.notifyKit`
|
|
602
|
+
在已有的 `AgentOSSDK` 上暴露 HarnessKit 与 NotifyKit 的 client,它们的第一个参数是
|
|
603
|
+
AppKit Bearer Token:
|
|
384
604
|
|
|
385
605
|
```python
|
|
386
606
|
from agentos_sdk.clients import AgentKitClient, CronKitClient, ModelKitClient
|