agentos-sdk-python 1.1.0__tar.gz → 1.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/CHANGELOG.md +45 -1
  2. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/PKG-INFO +154 -21
  3. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/README-zh_CN.md +137 -17
  4. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/README.md +153 -20
  5. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/RELEASE.md +7 -8
  6. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/__init__.py +10 -0
  7. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/clients/harnesskit.py +18 -0
  8. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/clients/modelkit.py +18 -5
  9. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/normalizers.py +57 -3
  10. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/protocol.py +59 -6
  11. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/sdk.py +27 -4
  12. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/pyproject.toml +1 -1
  13. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/tests/test_harnesskit.py +121 -1
  14. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/tests/test_modelkit.py +203 -19
  15. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/tests/test_normalizers.py +105 -0
  16. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/tests/test_sdk_facade.py +7 -7
  17. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/tests/typecheck/harnesskit_usage.py +36 -1
  18. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/tests/typecheck/modelkit_usage.py +14 -5
  19. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/.gitignore +0 -0
  20. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/LICENSE +0 -0
  21. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/clients/__init__.py +0 -0
  22. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/clients/agentkit.py +0 -0
  23. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/clients/appkit.py +0 -0
  24. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/clients/authkit.py +0 -0
  25. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/clients/cronkit.py +0 -0
  26. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/clients/discoverykit.py +0 -0
  27. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/clients/notifykit.py +0 -0
  28. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/clients/systemkit.py +0 -0
  29. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/clients/toolkit.py +0 -0
  30. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/clients/transferkit.py +0 -0
  31. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/handlers.py +0 -0
  32. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/py.typed +0 -0
  33. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/agentos_sdk/transport.py +0 -0
  34. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/tests/test_agentkit.py +0 -0
  35. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/tests/test_cronkit.py +0 -0
  36. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/tests/test_notifykit.py +0 -0
  37. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/tests/test_protocol.py +0 -0
  38. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/tests/test_toolkit.py +0 -0
  39. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/tests/test_transport.py +0 -0
  40. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/tests/typecheck/notifykit_usage.py +0 -0
  41. {agentos_sdk_python-1.1.0 → agentos_sdk_python-1.1.1}/tests/typecheck/toolkit_usage.py +0 -0
@@ -1,6 +1,50 @@
1
1
  # Changelog
2
2
 
3
- ## 1.1.0 - Unreleased
3
+ ## 1.1.1
4
+
5
+ - Added HarnessKit private App tool registration with `register_private_tools`
6
+ and `registerPrivateTools` on both the authenticated facade and explicit-token
7
+ client. Added registration, result and tool policy type declarations.
8
+ - Preserve the current AppKit token when HarnessKit returns
9
+ `harness_host_access_forbidden` for a restricted action.
10
+ - Added `billingType` (`ModelBillingType`: `"free"`, `"plan"` or `"payAsYouGo"`) to
11
+ model info for system models that are not benefit card models. It is omitted for
12
+ benefit card, local, custom and app models, and on gateways that predate the
13
+ field; blank and unknown values are dropped. Pickers can mark each type with a
14
+ badge.
15
+ - Added `isBenefitCard`, `benefitCardId` and `benefitCardName` to model info for
16
+ the models a benefit card serves. A card model keeps `source` `"platform"` and
17
+ its plain `name` / `alias`; the same model can be listed once for the plan and
18
+ once per card, and only `id` and the card fields tell them apart. Group card
19
+ models one group per card (for example `Remote · System · {benefitCardName}`,
20
+ falling back to `benefitCardId`). The fields are omitted for other models and
21
+ on gateways that predate them; blank values are dropped.
22
+ - Added `maxOutputTokens` (the maximum number of tokens a model can generate in
23
+ one response, the platform's `maxTokens`) to model info and app model
24
+ records/requests, next to `contextWindowSize`. It is omitted when the gateway
25
+ does not report it; the `AppModel*` type declarations include it.
26
+ - Model info now reports `source` (`ModelSource`: `"local"` / `"platform"` /
27
+ `"custom"` / `"app"`), the gateway's mutually exclusive model origin, and
28
+ `appName` for app models. Group and label models by `source` (for example
29
+ `App · {appName}`) instead of combining `isRemote` / `isCustom` /
30
+ `isAppModel`. `source` is always present: it is derived from those flags with
31
+ the gateway's rules when the gateway predates `source` or reports an unknown
32
+ value. `appName` is only present when the gateway reports a non-blank one.
33
+ The `ModelSource` type declaration was added.
34
+ - **Breaking:** The gateway generates app model IDs. `AppModelRegistration` takes
35
+ no `id`; the gateway derives a 12-character hashid from the app's bundle ID and
36
+ the model `name` and returns it as `AppModelWriteResult["id"]`. Store it: it is the
37
+ `model_id` of `update_app_model` / `unregister_app_model` /
38
+ `toggle_app_model` (looked up only among the calling app's models, otherwise
39
+ `404`) and the `model` of requests. `AppModel["id"]` and the model `id` in
40
+ `list_models()` report the same value. A model's `name` is unique within its
41
+ app: registering an existing `name` replaces that model and keeps its id
42
+ (`updated` is true), and renaming through `update_app_model` keeps the id.
43
+ `409` means the id derived from `name` is still held by a renamed model of the
44
+ same app, or `update_app_model` renames a model to a `name` another model of
45
+ the app already uses.
46
+
47
+ ## 1.1.0
4
48
 
5
49
  - Added HarnessKit support for the authenticated `/harnesskit/*` Gateway routes:
6
50
  `sdk.harnesskit` (with `health`, `get_runtime`, `switch_engine`,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agentos-sdk-python
3
- Version: 1.1.0
3
+ Version: 1.1.1
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
@@ -255,6 +255,62 @@ Normalized model capabilities include `vision`, `tool_call`, `stream`, and
255
255
  `reasoning` booleans. `reasoning` reflects only the server-provided
256
256
  `capabilities.reasoning` value and defaults to `False` when omitted.
257
257
 
258
+ Every model also carries `source`, the mutually exclusive origin of the model
259
+ (`ModelSource`). Group and label models by it instead of combining `isRemote` /
260
+ `isCustom` / `isAppModel`:
261
+
262
+ | `source` | Meaning | Suggested group |
263
+ | --- | --- | --- |
264
+ | `"local"` | Runs on this device | Local Models |
265
+ | `"platform"` | Remote model provided by the AgentOS platform | Platform Models, plus `Remote · System · {benefitCardName}` for each benefit card (see below) |
266
+ | `"custom"` | Remote model configured by the user | Custom Models |
267
+ | `"app"` | Registered by a third-party app | `App · {appName}` (one group per app) |
268
+
269
+ ```python
270
+ groups: dict[str, list[dict]] = {}
271
+ for model in await sdk.modelkit.list_models():
272
+ if model["source"] == "app":
273
+ title = f"App · {model.get('appName') or model.get('appBundleId')}"
274
+ else:
275
+ title = model["source"]
276
+ groups.setdefault(title, []).append(model)
277
+ ```
278
+
279
+ App models additionally report `appBundleId` and `appName` (the human-readable
280
+ app name, for group titles; `appName` is only present when the gateway reports
281
+ one, so fall back to `appBundleId`). Against gateways that predate `source`, or
282
+ when it holds an unknown value, `source` is derived from the legacy flags with
283
+ the gateway's rules.
284
+
285
+ Models served through a benefit card keep `source` `"platform"` and their plain
286
+ `name` / `alias`, and additionally report `isBenefitCard`, `benefitCardId` and
287
+ `benefitCardName` (`benefitCardName` is only present when the gateway reports
288
+ one, so fall back to `benefitCardId`). The same model can be listed once for the
289
+ plan and once per card, so tell them apart by `id` or the card fields, and show
290
+ each card as its own group:
291
+
292
+ ```python
293
+ def system_group_title(model: dict) -> str:
294
+ if model.get("isBenefitCard"):
295
+ return f"Remote · System · {model.get('benefitCardName') or model.get('benefitCardId')}"
296
+ return "Remote · System"
297
+ ```
298
+
299
+ System models that are not benefit card models also report `billingType`
300
+ (`"free"`, `"plan"` or `"payAsYouGo"`; omitted when unknown and for every other
301
+ model), so a picker can mark each type with a small badge.
302
+
303
+ Model dicts also carry `contextWindowSize` and `maxOutputTokens` (the maximum
304
+ number of tokens the model can generate in one response); `maxOutputTokens` is
305
+ only present when the gateway reports it. Only chat models report
306
+ `maxOutputTokens` (embedding, ASR, TTS and decision models do not generate
307
+ text, so the key is absent for them); a chat model that reports
308
+ `contextWindowSize` reports `maxOutputTokens` too, using the same number when it
309
+ has no value of its own. Apps can set both when registering a model
310
+ (`register_app_model(request={"name": ..., "contextWindowSize": 32768,
311
+ "maxOutputTokens": 4096})`); app model records report them back, and
312
+ `update_app_model` can change them.
313
+
258
314
  ModelKit also supports:
259
315
 
260
316
  - `sdk.modelkit.embedding.create(...)`
@@ -316,44 +372,58 @@ and related `TypedDict` definitions for annotations.
316
372
  ### App models
317
373
 
318
374
  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`.
375
+ in `list_models()` / `list_models_by_task()` with `source: "app"`,
376
+ `isAppModel: True`, the owning `appBundleId` and its `appName`.
377
+
378
+ You do not choose the model id: the gateway generates a 12-character hashid from
379
+ your bundle ID and the model `name` and returns it when you register. That same
380
+ id is the model `id` in `list_models()` and `list_app_models()`. Store it: it
381
+ maintains the model (`update_app_model` / `toggle_app_model` /
382
+ `unregister_app_model`) and is the `model` of requests that must reach exactly
383
+ your model. A `name` is unique within your app; different apps may use the same
384
+ `name` and get different ids.
321
385
 
322
386
  ```python
323
387
  async with AgentOSSDK() as sdk:
324
388
  await sdk.agentos.register_bundle({"bundleId": "com.example.app"})
325
389
 
326
- # Register (or replace) a model. Only "id" and "name" are required.
390
+ # Register (or replace) a model. Only "name" is required.
327
391
  result = await sdk.modelkit.register_app_model(
328
392
  request={
329
- "id": "my-router",
330
393
  "name": "my-router",
331
394
  "task": "decision",
332
395
  "baseUrl": "http://127.0.0.1:9000",
333
396
  "apiKey": "upstream-secret", # stored by the server, never returned
334
397
  }
335
398
  )
399
+ model_id = result["id"] # e.g. "6f78dcce6717": maintain the model with it, or use it as `model` in requests
336
400
  print(result.get("updated")) # True when an existing model of this app was replaced
337
401
 
338
402
  # Partial update: unset fields stay unchanged.
339
403
  await sdk.modelkit.update_app_model(
340
- model_id="my-router", request={"description": "Routes support tickets"}
404
+ model_id=model_id, request={"description": "Routes support tickets"}
341
405
  )
342
406
 
343
407
  # Enable/disable without deleting.
344
- await sdk.modelkit.toggle_app_model(model_id="my-router")
408
+ await sdk.modelkit.toggle_app_model(model_id=model_id)
345
409
 
346
410
  # List every app-registered model (public, no token needed).
347
411
  for model in await sdk.modelkit.list_app_models():
348
- print(model["id"], model["appBundleId"], model["isDisabled"])
412
+ print(model["id"], model["isDisabled"])
349
413
 
350
- await sdk.modelkit.unregister_app_model(model_id="my-router")
414
+ await sdk.modelkit.unregister_app_model(model_id=model_id)
351
415
  ```
352
416
 
353
417
  Write calls attach the app token automatically and refresh it once on `401`.
354
418
  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`.
419
+ `appBundleId` mismatch, `404` unknown id (`model_id` is looked up only among your
420
+ app's models), `409` the id derived from `name` is still held by a renamed model
421
+ of your app (or `update_app_model` renames a model to a `name` another model of
422
+ your app already uses), `400` invalid body, missing `name`, unknown `task`, or a
423
+ bundle ID outside the allowed characters or length.
424
+
425
+ Registering a `name` you already registered replaces that model and returns the
426
+ same id; renaming a model with `update_app_model` keeps its id.
357
427
 
358
428
  Decision models are normalized by the server: input `text` (+ optional
359
429
  `image`), output `decisions`, and `stream` / `tool_call` / `reasoning` all
@@ -518,12 +588,10 @@ optional `server` identity uses `namespace`, `name`, and `version`;
518
588
 
519
589
  ## HarnessKit
520
590
 
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.
591
+ HarnessKit forwards requests through the Gateway to the shared host runtime.
592
+ Register the app with `sdk.agentos.register_bundle()` first. The Gateway scopes
593
+ external Apps' threads, runs and events by their bundle ID. All `sdk.harnesskit`
594
+ methods use the active AppKit token and retry once after an authentication failure.
527
595
 
528
596
  | Method | Parameters | Description |
529
597
  | --- | --- | --- |
@@ -531,6 +599,7 @@ and retry once after an authentication failure.
531
599
  | `get_runtime()` / `switch_engine(engine=...)` | `engine` | Reads the runtime engine or requests an engine switch. |
532
600
  | `list_threads()` / `get_thread(thread_id=...)` | `thread_id` | Lists durable threads or reads one thread snapshot. |
533
601
  | `rename_thread(thread_id=..., title=...)` / `delete_thread(thread_id=...)` | `thread_id`, `title` | Updates a thread title or deletes an idle thread. |
602
+ | `register_private_tools(thread_id=..., registration=...)` | `thread_id`, `HarnessKitPrivateToolsRegistration` | Registers or replaces a local App's OpenTool callbacks for a thread. |
534
603
  | `start_run(thread_id=..., request=...)` | `thread_id`, run request | Starts a Harness run and returns its `runId`. |
535
604
  | `submit_command(thread_id=..., command=...)` | `thread_id`, command | Submits work or control commands; rejected commands return their receipt. |
536
605
  | `events(thread_id=..., after_sequence=0, run_id=None)` | `thread_id`, `after_sequence`, `run_id` | Opens a resumable SSE stream of typed events. |
@@ -596,10 +665,10 @@ through untouched; the exported `HarnessKit*` `TypedDict`s (for example
596
665
  - A command the Harness rejects comes back as HTTP `400` with a receipt body.
597
666
  `submit_command()` returns that receipt (`status == "rejected"`) instead of
598
667
  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.
668
+ - `switch_engine()` and `get_operational_snapshot()` are reserved for the
669
+ built-in Harness App. Other Apps receive an `ApiError` with status `403`.
670
+ `get_operational_snapshot()` also answers `501` when the configured engine
671
+ does not expose the optional reader.
603
672
  - Thread and run IDs are percent-encoded. Empty IDs and `.` / `..` raise
604
673
  `ValueError` before any request is sent.
605
674
  - `request()` and `request_stream()` accept paths relative to the Harness API
@@ -608,6 +677,70 @@ through untouched; the exported `HarnessKit*` `TypedDict`s (for example
608
677
  caller-supplied `authorization` header is replaced by the AppKit token. A query
609
678
  string in `path` is kept; keys in `query` override the same keys there.
610
679
 
680
+ ### Register private App tools
681
+
682
+ An external App can register OpenTool functions for its own thread over a direct
683
+ local connection to the Gateway. Start the App's HTTP callback service first and
684
+ use its UUID-shaped callback token in the registration. The callback token is
685
+ separate from the AppKit token used to authenticate the Gateway request.
686
+
687
+ ```python
688
+ import uuid
689
+
690
+ from agentos_sdk import AgentOSSDK
691
+
692
+
693
+ async def run_with_app_tools(callback_token: str):
694
+ async with AgentOSSDK(base_url="http://127.0.0.1:8888") as sdk:
695
+ await sdk.agentos.register_bundle({"bundleId": "com.example.app"})
696
+ binding = await sdk.harnesskit.register_private_tools(
697
+ thread_id="research-thread",
698
+ registration={
699
+ "endpoint": "http://127.0.0.1:8123/",
700
+ "token": callback_token,
701
+ "specification": {
702
+ "opentool": "1.0.0",
703
+ "info": {"title": "App tools", "version": "1.0.0"},
704
+ "functions": [{
705
+ "name": "list_assets",
706
+ "description": "List the app assets",
707
+ "parameters": [],
708
+ "return": {"name": "result", "schema": {"type": "object"}},
709
+ }],
710
+ },
711
+ },
712
+ )
713
+ return await sdk.harnesskit.start_run(
714
+ thread_id="research-thread",
715
+ request={
716
+ "requestId": str(uuid.uuid4()),
717
+ "goal": "List the app assets",
718
+ "llmConfig": {"model": "your-model"},
719
+ "toolPolicy": {"allowedToolIds": [binding["toolId"]]},
720
+ },
721
+ )
722
+ ```
723
+
724
+ The endpoint must be an `http://127.0.0.1:<port>/` root URL. The callback
725
+ service must accept `Authorization: Bearer <token>` and provide these routes.
726
+
727
+ - `GET /private-tools/opentool/version` returns HTTP `200` for health checks.
728
+ - `POST /private-tools/opentool/call` accepts JSON with `jsonrpc: "2.0.0"`,
729
+ `id`, `method` and `params`. Return HTTP `200` with the same `jsonrpc` and
730
+ `id`, plus a `result` or `error`.
731
+ - `POST /private-tools/opentool/streamCall` serves streaming functions as SSE
732
+ data events with the same JSON response format, followed by a `DONE` event.
733
+
734
+ The returned `toolId` identifies the thread's registered tools. Add it to
735
+ `toolPolicy.allowedToolIds` when using an allow-list. Omitting the allow-list or
736
+ setting it to `None` leaves tools unrestricted, while an empty list allows no
737
+ tools. A new registration replaces the thread's existing binding. Bindings are
738
+ removed when the thread is deleted or the callback repeatedly fails health
739
+ checks. Register again after a Harness restart or when a binding is removed.
740
+ The Gateway rejects remote registrations and registrations from the built-in
741
+ Harness App with HTTP `403` and `harness_host_access_forbidden`. That error does
742
+ not trigger an AppKit token refresh.
743
+
611
744
  ## NotifyKit
612
745
 
613
746
  NotifyKit lets an App submit user-facing events to the AgentOS notification
@@ -221,6 +221,53 @@ async with AgentOSSDK() as sdk:
221
221
  布尔字段。`reasoning` 只使用服务端返回的 `capabilities.reasoning`,字段缺失时
222
222
  默认为 `False`。
223
223
 
224
+ 每个模型还带有 `source`(`ModelSource`),表示模型互斥的来源。请按它分组/打标签,
225
+ 而不要再组合 `isRemote` / `isCustom` / `isAppModel` 自行推导:
226
+
227
+ | `source` | 含义 | 建议分组 |
228
+ | --- | --- | --- |
229
+ | `"local"` | 在本机运行 | 本地模型 |
230
+ | `"platform"` | AgentOS 平台提供的远端模型 | 平台模型,另为每张权益卡单独分组 `远端 · 系统 · {benefitCardName}`(见下) |
231
+ | `"custom"` | 用户自行配置的远端模型 | 自定义模型 |
232
+ | `"app"` | 第三方 app 注册的模型 | `App · {appName}`(每个 app 一组) |
233
+
234
+ ```python
235
+ groups: dict[str, list[dict]] = {}
236
+ for model in await sdk.modelkit.list_models():
237
+ if model["source"] == "app":
238
+ title = f"App · {model.get('appName') or model.get('appBundleId')}"
239
+ else:
240
+ title = model["source"]
241
+ groups.setdefault(title, []).append(model)
242
+ ```
243
+
244
+ app 模型还会带有 `appBundleId` 与 `appName`(app 的可读名称,用作分组标题;
245
+ `appName` 仅在网关返回时才有值,缺失时请回退到 `appBundleId`)。对于尚未提供
246
+ `source` 的旧网关,或 `source` 为未知值时,会按网关的规则由旧布尔字段推导。
247
+
248
+ 由权益卡提供的模型仍保持 `source` 为 `"platform"` 与原样的 `name` / `alias`,并额外带有
249
+ `isBenefitCard`、`benefitCardId` 与 `benefitCardName`(`benefitCardName` 仅在网关返回时才有值,
250
+ 缺失时请回退到 `benefitCardId`)。同一个模型可能在套餐和每张权益卡下各出现一次,请用 `id`
251
+ 或权益卡字段区分,并让每张权益卡各自成组:
252
+
253
+ ```python
254
+ def system_group_title(model: dict) -> str:
255
+ if model.get("isBenefitCard"):
256
+ return f"远端 · 系统 · {model.get('benefitCardName') or model.get('benefitCardId')}"
257
+ return "远端 · 系统"
258
+ ```
259
+
260
+ 非权益卡的系统模型还会带有 `billingType`(`"free"`、`"plan"` 或 `"payAsYouGo"`;未知时以及其他模型均不包含该键),
261
+ 选择器可以为每种类型加一个小标识。
262
+
263
+ 模型字典还会带有 `contextWindowSize` 与 `maxOutputTokens`(模型单次响应最多可生成的
264
+ token 数);`maxOutputTokens` 仅在网关返回时才存在。只有 chat 模型才会返回
265
+ `maxOutputTokens`(embedding、ASR、TTS、decision 模型不生成文本,不包含该键);返回了
266
+ `contextWindowSize` 的 chat 模型一定会返回 `maxOutputTokens`,模型自身没有该值时与
267
+ `contextWindowSize` 相同。App 注册模型时可同时设置两者
268
+ (`register_app_model(request={"name": ..., "contextWindowSize": 32768,
269
+ "maxOutputTokens": 4096})`);app 模型记录会原样返回,`update_app_model` 也可以修改。
270
+
224
271
  ModelKit 还支持:
225
272
 
226
273
  - `sdk.modelkit.embedding.create(...)`
@@ -281,42 +328,54 @@ async with AgentOSSDK() as sdk:
281
328
  ### App model
282
329
 
283
330
  App 可以把自己的模型注册到网关。注册后的模型会出现在 `list_models()` /
284
- `list_models_by_task()` 中,并带有 `isAppModel: True` 与所属的 `appBundleId`。
331
+ `list_models_by_task()` 中,并带有 `source: "app"`、`isAppModel: True`、所属的
332
+ `appBundleId` 与 `appName`。
333
+
334
+ 模型 id 不需要你指定:网关会根据你的 bundle ID 与模型 `name` 生成 12 位 hashid,并在
335
+ 注册成功时返回。`list_models()` 与 `list_app_models()` 里的模型 `id` 就是这个值。请
336
+ 保存它:维护模型(`update_app_model` / `toggle_app_model` / `unregister_app_model`)
337
+ 和请求的 `model` 都用它来精准指向你的模型。`name` 在你的 app 内唯一;不同 app 可以使用
338
+ 相同的 `name`,得到的 id 不同。
285
339
 
286
340
  ```python
287
341
  async with AgentOSSDK() as sdk:
288
342
  await sdk.agentos.register_bundle({"bundleId": "com.example.app"})
289
343
 
290
- # 注册(或替换)模型,只有 "id" 和 "name" 必填。
344
+ # 注册(或替换)模型,只有 "name" 必填。
291
345
  result = await sdk.modelkit.register_app_model(
292
346
  request={
293
- "id": "my-router",
294
347
  "name": "my-router",
295
348
  "task": "decision",
296
349
  "baseUrl": "http://127.0.0.1:9000",
297
350
  "apiKey": "upstream-secret", # 由服务端保存,不会再返回
298
351
  }
299
352
  )
300
- print(result.get("updated")) # 替换了该 app 已有的同 id 模型时为 True
353
+ model_id = result["id"] # 例如 "6f78dcce6717":用它维护模型,或作为请求的 `model`
354
+ print(result.get("updated")) # 替换了该 app 已有的同名模型时为 True
301
355
 
302
356
  # 局部更新:未设置的字段保持不变。
303
357
  await sdk.modelkit.update_app_model(
304
- model_id="my-router", request={"description": "分流客服工单"}
358
+ model_id=model_id, request={"description": "分流客服工单"}
305
359
  )
306
360
 
307
361
  # 启用/停用,无需删除。
308
- await sdk.modelkit.toggle_app_model(model_id="my-router")
362
+ await sdk.modelkit.toggle_app_model(model_id=model_id)
309
363
 
310
364
  # 列出所有 app 注册的模型(公开接口,无需 token)。
311
365
  for model in await sdk.modelkit.list_app_models():
312
- print(model["id"], model["appBundleId"], model["isDisabled"])
366
+ print(model["id"], model["isDisabled"])
313
367
 
314
- await sdk.modelkit.unregister_app_model(model_id="my-router")
368
+ await sdk.modelkit.unregister_app_model(model_id=model_id)
315
369
  ```
316
370
 
317
371
  写操作会自动附带 app token,并在 `401` 时刷新一次。失败时抛出带服务端状态码的
318
- `ApiError`:`401` token 无效,`403` 不是所属 app 或 `appBundleId` 不匹配,
319
- `404` id 不存在,`409` id 属于其他 app,`400` 请求体非法或 `task` 未知。
372
+ `ApiError`:`401` token 无效,`403` `appBundleId` 不匹配,`404` id 不存在
373
+ (`model_id` 只在本 app 的模型中查找),`409` 由 `name` 生成的 id 仍被本 app 里一个
374
+ 已改名的模型占用(或 `update_app_model` 把模型改成本 app 另一个模型已用的 `name`),
375
+ `400` 请求体非法、缺少 `name`、`task` 未知,或 bundleId 的字符或长度不合法。
376
+
377
+ 注册已注册过的 `name` 会替换该模型并返回同一个 id;用 `update_app_model` 改名时 id
378
+ 保持不变。
320
379
 
321
380
  Decision 模型会被服务端规范化:输入为 `text`(可选 `image`),输出为
322
381
  `decisions`,`stream` / `tool_call` / `reasoning` 均为 `False`。底层
@@ -476,10 +535,10 @@ async with AgentOSSDK() as sdk:
476
535
 
477
536
  ## HarnessKit
478
537
 
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,并在鉴权失败后重试一次。
538
+ HarnessKit 通过 Gateway 把请求转发到共享的宿主 Harness runtime。请先调用
539
+ `sdk.agentos.register_bundle()` 注册应用。Gateway 根据 bundle ID 隔离外部 App 的
540
+ 线程、run 和事件。`sdk.harnesskit` 的所有方法都会使用当前 AppKit token,并在鉴权
541
+ 失败后重试一次。
483
542
 
484
543
  | 方法 | 参数 | 说明 |
485
544
  | --- | --- | --- |
@@ -487,6 +546,7 @@ runtime。请先调用 `sdk.agentos.register_bundle()` 注册应用。安装型
487
546
  | `get_runtime()` / `switch_engine(engine=...)` | `engine` | 读取运行时引擎,或请求切换引擎。 |
488
547
  | `list_threads()` / `get_thread(thread_id=...)` | `thread_id` | 列出持久化会话线程,或读取单个线程快照。 |
489
548
  | `rename_thread(thread_id=..., title=...)` / `delete_thread(thread_id=...)` | `thread_id`、`title` | 修改线程标题,或删除空闲线程。 |
549
+ | `register_private_tools(thread_id=..., registration=...)` | `thread_id`、`HarnessKitPrivateToolsRegistration` | 为线程注册或替换本地 App 的 OpenTool 回调。 |
490
550
  | `start_run(thread_id=..., request=...)` | `thread_id`、run 请求 | 启动一次 Harness run 并返回其 `runId`。 |
491
551
  | `submit_command(thread_id=..., command=...)` | `thread_id`、命令 | 提交工作或控制命令;被拒绝的命令会返回其回执。 |
492
552
  | `events(thread_id=..., after_sequence=0, run_id=None)` | `thread_id`、`after_sequence`、`run_id` | 打开可续传的 SSE 事件流,返回带类型标注的事件。 |
@@ -548,9 +608,9 @@ finally:
548
608
 
549
609
  - Harness 拒绝的命令会以 HTTP `400` 加回执体返回。`submit_command()` 会把该回执
550
610
  (`status == "rejected"`)作为结果返回而不是抛出异常;其它错误一律抛出 `ApiError`。
551
- - 运行时控制(`get_runtime()`、`switch_engine()`)和 `get_operational_snapshot()`
552
- 仅限内置 Harness App 使用,其它 App 会得到状态码为 `403` 的 `ApiError`。当所配置的
553
- 引擎没有提供可选的读取器时,`get_operational_snapshot()` 还会返回 `501`。
611
+ - `switch_engine()` 和 `get_operational_snapshot()` 仅限内置 Harness App 使用,其它
612
+ App 会得到状态码为 `403` 的 `ApiError`。当所配置的引擎没有提供可选的读取器时,
613
+ `get_operational_snapshot()` 还会返回 `501`。
554
614
  - 线程 ID 与 run ID 会做百分号编码。空 ID 以及 `.` / `..` 会在发出请求前抛出
555
615
  `ValueError`。
556
616
  - `request()` 和 `request_stream()` 接受相对 Harness API 根的路径(`/harnesskit`
@@ -558,6 +618,66 @@ finally:
558
618
  `ValueError`,调用方传入的 `authorization` 头会被 AppKit token 替换。`path` 中自带的
559
619
  查询串会被保留,`query` 中的同名键会覆盖它。
560
620
 
621
+ ### 注册 App 私有工具
622
+
623
+ 外部 App 可以通过本机直接连接 Gateway,为自己的线程注册 OpenTool 函数。请先启动
624
+ App 的 HTTP 回调服务,注册时使用该服务配置的 UUID 格式回调 token。这个 token 与
625
+ 调用 Gateway 使用的 AppKit token 各自独立。
626
+
627
+ ```python
628
+ import uuid
629
+
630
+ from agentos_sdk import AgentOSSDK
631
+
632
+
633
+ async def run_with_app_tools(callback_token: str):
634
+ async with AgentOSSDK(base_url="http://127.0.0.1:8888") as sdk:
635
+ await sdk.agentos.register_bundle({"bundleId": "com.example.app"})
636
+ binding = await sdk.harnesskit.register_private_tools(
637
+ thread_id="research-thread",
638
+ registration={
639
+ "endpoint": "http://127.0.0.1:8123/",
640
+ "token": callback_token,
641
+ "specification": {
642
+ "opentool": "1.0.0",
643
+ "info": {"title": "App tools", "version": "1.0.0"},
644
+ "functions": [{
645
+ "name": "list_assets",
646
+ "description": "List the app assets",
647
+ "parameters": [],
648
+ "return": {"name": "result", "schema": {"type": "object"}},
649
+ }],
650
+ },
651
+ },
652
+ )
653
+ return await sdk.harnesskit.start_run(
654
+ thread_id="research-thread",
655
+ request={
656
+ "requestId": str(uuid.uuid4()),
657
+ "goal": "列出 App 的资源",
658
+ "llmConfig": {"model": "your-model"},
659
+ "toolPolicy": {"allowedToolIds": [binding["toolId"]]},
660
+ },
661
+ )
662
+ ```
663
+
664
+ `endpoint` 必须是 `http://127.0.0.1:<port>/` 格式的根地址。回调服务需要接受
665
+ `Authorization: Bearer <token>`,并提供以下接口。
666
+
667
+ - `GET /private-tools/opentool/version` 用于健康检查,返回 HTTP `200`。
668
+ - `POST /private-tools/opentool/call` 接收包含 `jsonrpc: "2.0.0"`、`id`、`method` 和
669
+ `params` 的 JSON。响应返回 HTTP `200`,JSON 中包含相同的 `jsonrpc`、`id`,以及
670
+ `result` 或 `error`。
671
+ - `POST /private-tools/opentool/streamCall` 用于流式函数。返回 SSE 数据事件,事件数据
672
+ 使用相同的 JSON 响应格式,最后发送 `DONE` 事件。
673
+
674
+ 返回的 `toolId` 标识该线程注册的工具。如果使用 `toolPolicy.allowedToolIds` 允许列表,
675
+ 需要把它加入列表。省略允许列表或设置为 `None` 表示不限制工具,空列表表示不允许
676
+ 任何工具。同一线程再次注册会替换原有绑定。删除线程或回调服务连续未通过健康检查时,
677
+ 绑定会被移除。Harness 重启或绑定被移除后,需要重新注册。Gateway 对远程注册和内置
678
+ Harness App 的注册返回 HTTP `403` 和 `harness_host_access_forbidden`,该错误不会触发
679
+ AppKit token 刷新。
680
+
561
681
  ## NotifyKit
562
682
 
563
683
  NotifyKit 让 App 向 AgentOS 通知中心提交面向用户的事件。请先调用