agentos-sdk-python 1.1.0__py3-none-any.whl → 1.1.1__py3-none-any.whl
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/__init__.py +10 -0
- agentos_sdk/clients/harnesskit.py +18 -0
- agentos_sdk/clients/modelkit.py +18 -5
- agentos_sdk/normalizers.py +57 -3
- agentos_sdk/protocol.py +59 -6
- agentos_sdk/sdk.py +27 -4
- {agentos_sdk_python-1.1.0.dist-info → agentos_sdk_python-1.1.1.dist-info}/METADATA +154 -21
- {agentos_sdk_python-1.1.0.dist-info → agentos_sdk_python-1.1.1.dist-info}/RECORD +10 -10
- {agentos_sdk_python-1.1.0.dist-info → agentos_sdk_python-1.1.1.dist-info}/WHEEL +0 -0
- {agentos_sdk_python-1.1.0.dist-info → agentos_sdk_python-1.1.1.dist-info}/licenses/LICENSE +0 -0
agentos_sdk/__init__.py
CHANGED
|
@@ -34,6 +34,8 @@ from .protocol import (
|
|
|
34
34
|
HarnessKitHealth,
|
|
35
35
|
HarnessKitLlmConfig,
|
|
36
36
|
HarnessKitOperationalSnapshot,
|
|
37
|
+
HarnessKitPrivateToolsRegistration,
|
|
38
|
+
HarnessKitPrivateToolsRegistrationResult,
|
|
37
39
|
HarnessKitRunAccepted,
|
|
38
40
|
HarnessKitRunError,
|
|
39
41
|
HarnessKitRunRequest,
|
|
@@ -44,9 +46,12 @@ from .protocol import (
|
|
|
44
46
|
HarnessKitThreadMessage,
|
|
45
47
|
HarnessKitThreadRenameResult,
|
|
46
48
|
HarnessKitThreadSnapshot,
|
|
49
|
+
HarnessKitToolPolicy,
|
|
47
50
|
HistoryTurnStatus,
|
|
48
51
|
HistoryTurnSummary,
|
|
49
52
|
Modality,
|
|
53
|
+
ModelBillingType,
|
|
54
|
+
ModelSource,
|
|
50
55
|
ModelTask,
|
|
51
56
|
NotifyKitEvent,
|
|
52
57
|
NotifyKitLevel,
|
|
@@ -106,6 +111,8 @@ __all__ = [
|
|
|
106
111
|
"HarnessKitHealth",
|
|
107
112
|
"HarnessKitLlmConfig",
|
|
108
113
|
"HarnessKitOperationalSnapshot",
|
|
114
|
+
"HarnessKitPrivateToolsRegistration",
|
|
115
|
+
"HarnessKitPrivateToolsRegistrationResult",
|
|
109
116
|
"HarnessKitRunAccepted",
|
|
110
117
|
"HarnessKitRunError",
|
|
111
118
|
"HarnessKitRunRequest",
|
|
@@ -116,9 +123,12 @@ __all__ = [
|
|
|
116
123
|
"HarnessKitThreadMessage",
|
|
117
124
|
"HarnessKitThreadRenameResult",
|
|
118
125
|
"HarnessKitThreadSnapshot",
|
|
126
|
+
"HarnessKitToolPolicy",
|
|
119
127
|
"HistoryTurnStatus",
|
|
120
128
|
"HistoryTurnSummary",
|
|
121
129
|
"Modality",
|
|
130
|
+
"ModelBillingType",
|
|
131
|
+
"ModelSource",
|
|
122
132
|
"ModelTask",
|
|
123
133
|
"NotifyKitEvent",
|
|
124
134
|
"NotifyKitLevel",
|
|
@@ -16,6 +16,7 @@ from agentos_sdk.protocol import (
|
|
|
16
16
|
HarnessKitEvent,
|
|
17
17
|
HarnessKitHealth,
|
|
18
18
|
HarnessKitOperationalSnapshot,
|
|
19
|
+
HarnessKitPrivateToolsRegistrationResult,
|
|
19
20
|
HarnessKitRunAccepted,
|
|
20
21
|
HarnessKitRunResult,
|
|
21
22
|
HarnessKitRuntimeInfo,
|
|
@@ -88,6 +89,22 @@ class HarnessKitClient:
|
|
|
88
89
|
"""Delete an idle thread (``DELETE /v1/threads/{threadId}``)."""
|
|
89
90
|
return await self.request(bearer_token, _thread_path(thread_id), method="DELETE")
|
|
90
91
|
|
|
92
|
+
async def register_private_tools(
|
|
93
|
+
self, bearer_token: str, thread_id: str, registration: Mapping[str, Any]
|
|
94
|
+
) -> HarnessKitPrivateToolsRegistrationResult:
|
|
95
|
+
"""Register or replace a local App's OpenTool callbacks for a thread.
|
|
96
|
+
|
|
97
|
+
``registration`` contains the callback ``endpoint``, callback ``token``
|
|
98
|
+
and OpenTool ``specification``. The callback token is separate from the
|
|
99
|
+
AppKit bearer token. Returns the registered ``toolId``.
|
|
100
|
+
"""
|
|
101
|
+
return await self.request(
|
|
102
|
+
bearer_token,
|
|
103
|
+
f"{_thread_path(thread_id)}/private-tools",
|
|
104
|
+
method="PUT",
|
|
105
|
+
data=dict(registration),
|
|
106
|
+
)
|
|
107
|
+
|
|
91
108
|
async def start_run(
|
|
92
109
|
self, bearer_token: str, thread_id: str, request: Mapping[str, Any]
|
|
93
110
|
) -> HarnessKitRunAccepted:
|
|
@@ -237,6 +254,7 @@ class HarnessKitClient:
|
|
|
237
254
|
getThread = get_thread
|
|
238
255
|
renameThread = rename_thread
|
|
239
256
|
deleteThread = delete_thread
|
|
257
|
+
registerPrivateTools = register_private_tools
|
|
240
258
|
startRun = start_run
|
|
241
259
|
submitCommand = submit_command
|
|
242
260
|
openEvents = open_events
|
agentos_sdk/clients/modelkit.py
CHANGED
|
@@ -167,10 +167,17 @@ class ModelKitClient:
|
|
|
167
167
|
) -> dict[str, Any]:
|
|
168
168
|
"""Register (or replace) an app model (``POST /modelkit/app-models``).
|
|
169
169
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
The gateway generates the model id from the app's bundle ID and the
|
|
171
|
+
model ``name`` and returns it as ``id``; store it to maintain the model
|
|
172
|
+
and as the ``model`` of requests. Registering a ``name`` the app already
|
|
173
|
+
registered replaces that model and returns the same id (``updated`` is
|
|
174
|
+
true).
|
|
175
|
+
|
|
176
|
+
Raises ``ApiError`` with status 401 (missing/invalid token), 403
|
|
177
|
+
(``appBundleId`` mismatch), 409 (the id derived from ``name`` is still
|
|
178
|
+
held by a renamed model of the same app) or 400 (invalid body, missing
|
|
179
|
+
``name``, unknown ``task``, or a bundle ID outside ``[A-Za-z0-9._-]`` or
|
|
180
|
+
over 128 characters).
|
|
174
181
|
"""
|
|
175
182
|
return await self.api_client.request(
|
|
176
183
|
"/modelkit/app-models",
|
|
@@ -182,7 +189,13 @@ class ModelKitClient:
|
|
|
182
189
|
async def update_app_model(
|
|
183
190
|
self, bearer_token: str, model_id: str, request: Mapping[str, Any]
|
|
184
191
|
) -> dict[str, Any]:
|
|
185
|
-
"""Partially update an owned app model (``PUT /modelkit/app-models/<id>``).
|
|
192
|
+
"""Partially update an owned app model (``PUT /modelkit/app-models/<id>``).
|
|
193
|
+
|
|
194
|
+
``model_id`` is the id returned by ``register_app_model``, looked up only
|
|
195
|
+
among the calling app's models; an unknown id is a 404. Renaming the
|
|
196
|
+
model keeps its id; a ``name`` already used by another model of the app
|
|
197
|
+
is a 409.
|
|
198
|
+
"""
|
|
186
199
|
return await self.api_client.request(
|
|
187
200
|
_app_model_path(model_id),
|
|
188
201
|
method="PUT",
|
agentos_sdk/normalizers.py
CHANGED
|
@@ -96,6 +96,9 @@ def normalize_agent_event_name(event_type: str) -> str:
|
|
|
96
96
|
|
|
97
97
|
MODEL_TASKS = {"chat", "embedding", "asr", "tts", "decision"}
|
|
98
98
|
MODALITIES = {"text", "image", "audio", "video", "decisions"}
|
|
99
|
+
MODEL_SOURCES = {"local", "platform", "custom", "app"}
|
|
100
|
+
# Wire values of ``billingType``, keyed by their lower-case form so parsing is case-insensitive.
|
|
101
|
+
MODEL_BILLING_TYPES = {"free": "free", "plan": "plan", "payasyougo": "payAsYouGo"}
|
|
99
102
|
|
|
100
103
|
|
|
101
104
|
def _model_task(value: Any) -> str:
|
|
@@ -103,9 +106,33 @@ def _model_task(value: Any) -> str:
|
|
|
103
106
|
return task if task in MODEL_TASKS else "chat"
|
|
104
107
|
|
|
105
108
|
|
|
109
|
+
def _model_source(
|
|
110
|
+
value: Any, *, is_remote: bool, is_custom: bool, is_app_model: bool
|
|
111
|
+
) -> str:
|
|
112
|
+
"""Return the model's mutually exclusive origin.
|
|
113
|
+
|
|
114
|
+
The gateway's ``source`` wins. When it is missing or unknown (older
|
|
115
|
+
gateways), derive it from the legacy flags with the gateway's rules: an app
|
|
116
|
+
model is always ``app``; otherwise a non-remote model is ``local``, a remote
|
|
117
|
+
custom model is ``custom`` and any other remote model is ``platform``.
|
|
118
|
+
"""
|
|
119
|
+
if value is not None:
|
|
120
|
+
parsed = str(value).strip().lower()
|
|
121
|
+
if parsed in MODEL_SOURCES:
|
|
122
|
+
return parsed
|
|
123
|
+
if is_app_model:
|
|
124
|
+
return "app"
|
|
125
|
+
if not is_remote:
|
|
126
|
+
return "local"
|
|
127
|
+
return "custom" if is_custom else "platform"
|
|
128
|
+
|
|
129
|
+
|
|
106
130
|
def normalize_model_info(item: Mapping[str, Any]) -> dict[str, Any]:
|
|
107
131
|
task = _model_task(item.get("task", item.get("type", "")))
|
|
108
132
|
raw_caps = item.get("capabilities") if isinstance(item.get("capabilities"), dict) else {}
|
|
133
|
+
is_remote = bool(item.get("isRemote", False))
|
|
134
|
+
is_custom = bool(item.get("isCustom", False))
|
|
135
|
+
is_app_model = bool(item.get("isAppModel", False))
|
|
109
136
|
result: dict[str, Any] = {
|
|
110
137
|
"id": str(item.get("id", "")),
|
|
111
138
|
"name": str(item.get("name", "")),
|
|
@@ -121,12 +148,37 @@ def normalize_model_info(item: Mapping[str, Any]) -> dict[str, Any]:
|
|
|
121
148
|
"stream": bool(raw_caps.get("stream", True)),
|
|
122
149
|
"reasoning": bool(raw_caps.get("reasoning", False)),
|
|
123
150
|
},
|
|
124
|
-
"isRemote":
|
|
125
|
-
"isCustom":
|
|
126
|
-
"
|
|
151
|
+
"isRemote": is_remote,
|
|
152
|
+
"isCustom": is_custom,
|
|
153
|
+
"source": _model_source(
|
|
154
|
+
item.get("source"),
|
|
155
|
+
is_remote=is_remote,
|
|
156
|
+
is_custom=is_custom,
|
|
157
|
+
is_app_model=is_app_model,
|
|
158
|
+
),
|
|
159
|
+
"isAppModel": is_app_model,
|
|
127
160
|
}
|
|
161
|
+
if item.get("maxOutputTokens") is not None:
|
|
162
|
+
result["maxOutputTokens"] = item["maxOutputTokens"]
|
|
128
163
|
if item.get("appBundleId") is not None:
|
|
129
164
|
result["appBundleId"] = str(item["appBundleId"])
|
|
165
|
+
# 网关没有给出(或为空白)的 appName 不臆造,调用方可回退到 appBundleId。
|
|
166
|
+
app_name = str(item["appName"]).strip() if item.get("appName") is not None else ""
|
|
167
|
+
if app_name:
|
|
168
|
+
result["appName"] = app_name
|
|
169
|
+
# Benefit card models keep source "platform" and are flagged by isBenefitCard;
|
|
170
|
+
# the card fields are only present when set, blank values are dropped.
|
|
171
|
+
if item.get("isBenefitCard") is True:
|
|
172
|
+
result["isBenefitCard"] = True
|
|
173
|
+
for key in ("benefitCardId", "benefitCardName"):
|
|
174
|
+
value = str(item[key]).strip() if item.get(key) is not None else ""
|
|
175
|
+
if value:
|
|
176
|
+
result[key] = value
|
|
177
|
+
# Only system models that are not benefit card models carry a billing type; missing,
|
|
178
|
+
# blank and unknown values are dropped.
|
|
179
|
+
billing_type = MODEL_BILLING_TYPES.get(str(item.get("billingType") or "").strip().lower())
|
|
180
|
+
if billing_type:
|
|
181
|
+
result["billingType"] = billing_type
|
|
130
182
|
return result
|
|
131
183
|
|
|
132
184
|
|
|
@@ -155,6 +207,8 @@ def normalize_app_model(item: Mapping[str, Any]) -> dict[str, Any]:
|
|
|
155
207
|
result["baseUrl"] = str(item["baseUrl"])
|
|
156
208
|
if item.get("contextWindowSize") is not None:
|
|
157
209
|
result["contextWindowSize"] = item["contextWindowSize"]
|
|
210
|
+
if item.get("maxOutputTokens") is not None:
|
|
211
|
+
result["maxOutputTokens"] = item["maxOutputTokens"]
|
|
158
212
|
return result
|
|
159
213
|
|
|
160
214
|
|
agentos_sdk/protocol.py
CHANGED
|
@@ -8,6 +8,10 @@ JsonMap = dict[str, Any]
|
|
|
8
8
|
ContentType = Literal["text", "imageUrl"]
|
|
9
9
|
ModelTask = Literal["chat", "embedding", "asr", "tts", "decision"]
|
|
10
10
|
Modality = Literal["text", "image", "audio", "video", "decisions"]
|
|
11
|
+
# 模型互斥的来源,对应网关 ``/modelkit/models`` 的 ``source`` 字段。
|
|
12
|
+
ModelSource = Literal["local", "platform", "custom", "app"]
|
|
13
|
+
# 系统模型的计费类型,对应网关 ``/modelkit/models`` 的 ``billingType`` 字段。
|
|
14
|
+
ModelBillingType = Literal["free", "plan", "payAsYouGo"]
|
|
11
15
|
ToolContentState = Literal["unknown", "current", "updatePending", "broken"]
|
|
12
16
|
OpenToolRegistrationStatusValue = Literal["running", "starting", "notFound"]
|
|
13
17
|
HistoryTurnStatusValue = Literal["running", "done", "error", "stopped"]
|
|
@@ -304,6 +308,12 @@ class AppModel(TypedDict):
|
|
|
304
308
|
"""A model registered by a third-party app (``GET /modelkit/app-models``).
|
|
305
309
|
|
|
306
310
|
The API key is never returned; ``hasApiKey`` only tells whether one is stored.
|
|
311
|
+
|
|
312
|
+
``id`` is the model ID: a 12-character hashid the gateway generated from
|
|
313
|
+
``appBundleId + name`` when the app registered the model. It is identical to
|
|
314
|
+
the model's ``id`` in ``list_models()``. Use it for ``update_app_model`` /
|
|
315
|
+
``unregister_app_model`` / ``toggle_app_model`` and as the ``model`` of
|
|
316
|
+
requests to route to exactly this model.
|
|
307
317
|
"""
|
|
308
318
|
|
|
309
319
|
id: str
|
|
@@ -318,6 +328,8 @@ class AppModel(TypedDict):
|
|
|
318
328
|
baseUrl: NotRequired[str]
|
|
319
329
|
hasApiKey: bool
|
|
320
330
|
contextWindowSize: NotRequired[int]
|
|
331
|
+
# Maximum number of tokens the model can generate in one response.
|
|
332
|
+
maxOutputTokens: NotRequired[int]
|
|
321
333
|
isDisabled: bool
|
|
322
334
|
appBundleId: str
|
|
323
335
|
appName: str
|
|
@@ -326,11 +338,15 @@ class AppModel(TypedDict):
|
|
|
326
338
|
class AppModelRegistration(TypedDict):
|
|
327
339
|
"""Request body of ``register_app_model``.
|
|
328
340
|
|
|
329
|
-
Only ``
|
|
330
|
-
|
|
341
|
+
Only ``name`` is required; unset fields are omitted so the server applies
|
|
342
|
+
its own defaults. The model id is not part of the request: the gateway
|
|
343
|
+
generates it and returns it in ``AppModelWriteResult.id``.
|
|
344
|
+
|
|
345
|
+
``name`` is unique among the models of this app. The gateway derives the
|
|
346
|
+
model id from ``appBundleId + name``, so registering the same name again
|
|
347
|
+
replaces the model and returns the same id.
|
|
331
348
|
"""
|
|
332
349
|
|
|
333
|
-
id: str
|
|
334
350
|
name: str
|
|
335
351
|
alias: NotRequired[str]
|
|
336
352
|
description: NotRequired[str]
|
|
@@ -342,6 +358,8 @@ class AppModelRegistration(TypedDict):
|
|
|
342
358
|
baseUrl: NotRequired[str]
|
|
343
359
|
apiKey: NotRequired[str]
|
|
344
360
|
contextWindowSize: NotRequired[int]
|
|
361
|
+
# Maximum number of tokens the model can generate in one response.
|
|
362
|
+
maxOutputTokens: NotRequired[int]
|
|
345
363
|
appBundleId: NotRequired[str]
|
|
346
364
|
appName: NotRequired[str]
|
|
347
365
|
|
|
@@ -366,6 +384,7 @@ class AppModelUpdate(TypedDict, total=False):
|
|
|
366
384
|
baseUrl: str
|
|
367
385
|
apiKey: str
|
|
368
386
|
contextWindowSize: int
|
|
387
|
+
maxOutputTokens: int
|
|
369
388
|
appName: str
|
|
370
389
|
|
|
371
390
|
|
|
@@ -373,6 +392,10 @@ class AppModelWriteResult(TypedDict):
|
|
|
373
392
|
"""Result of an app-model write call (register / update / unregister / toggle)."""
|
|
374
393
|
|
|
375
394
|
success: bool
|
|
395
|
+
# The model id generated by the gateway; returned by register only. Store
|
|
396
|
+
# it: it maintains the model (``update_app_model`` / ``unregister_app_model``
|
|
397
|
+
# / ``toggle_app_model``) and is the ``model`` of requests that route to
|
|
398
|
+
# exactly this model.
|
|
376
399
|
id: NotRequired[str]
|
|
377
400
|
updated: NotRequired[bool]
|
|
378
401
|
|
|
@@ -391,8 +414,7 @@ class HarnessKitHealth(TypedDict):
|
|
|
391
414
|
class HarnessKitRuntimeInfo(TypedDict):
|
|
392
415
|
"""Response of ``GET /harnesskit/v1/runtime/harness-engine``.
|
|
393
416
|
|
|
394
|
-
``status`` is ``starting``, ``ready`` or ``switching``.
|
|
395
|
-
Harness App may read or change the runtime engine.
|
|
417
|
+
``status`` is ``starting``, ``ready`` or ``switching``.
|
|
396
418
|
"""
|
|
397
419
|
|
|
398
420
|
status: str
|
|
@@ -451,6 +473,22 @@ class HarnessKitThreadDeleteResult(TypedDict):
|
|
|
451
473
|
threadId: str
|
|
452
474
|
|
|
453
475
|
|
|
476
|
+
class HarnessKitPrivateToolsRegistration(TypedDict):
|
|
477
|
+
"""Local callback and OpenTool specification to register for a thread.
|
|
478
|
+
|
|
479
|
+
``token`` authenticates requests to the callback service and is separate
|
|
480
|
+
from the AppKit token used to call HarnessKit.
|
|
481
|
+
"""
|
|
482
|
+
|
|
483
|
+
endpoint: str
|
|
484
|
+
token: str
|
|
485
|
+
specification: dict[str, Any]
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
class HarnessKitPrivateToolsRegistrationResult(TypedDict):
|
|
489
|
+
toolId: str
|
|
490
|
+
|
|
491
|
+
|
|
454
492
|
class HarnessKitLlmConfig(TypedDict):
|
|
455
493
|
"""Model configuration of a run. Only ``model`` is required.
|
|
456
494
|
|
|
@@ -473,17 +511,31 @@ class HarnessKitLlmConfig(TypedDict):
|
|
|
473
511
|
supportsReasoning: NotRequired[bool]
|
|
474
512
|
|
|
475
513
|
|
|
514
|
+
class HarnessKitToolPolicy(TypedDict):
|
|
515
|
+
"""Tool visibility and approval rules for a run or turn.
|
|
516
|
+
|
|
517
|
+
A null or absent ``allowedToolIds`` leaves tools unrestricted; an empty
|
|
518
|
+
list allows no tools. Denied tools take precedence over allowed tools.
|
|
519
|
+
"""
|
|
520
|
+
|
|
521
|
+
allowedToolIds: NotRequired[list[str] | None]
|
|
522
|
+
deniedToolIds: NotRequired[list[str]]
|
|
523
|
+
approvalMode: NotRequired[str]
|
|
524
|
+
requireApprovalForSideEffects: NotRequired[bool]
|
|
525
|
+
|
|
526
|
+
|
|
476
527
|
class HarnessKitRunRequest(TypedDict):
|
|
477
528
|
"""Request body of ``start_run``.
|
|
478
529
|
|
|
479
530
|
The minimum useful fields are ``requestId``, ``goal`` and ``llmConfig.model``.
|
|
480
|
-
Newer Harness fields (``
|
|
531
|
+
Newer Harness fields (``limits``, ``plan``, ...) are passed
|
|
481
532
|
through at runtime even though they are not declared here.
|
|
482
533
|
"""
|
|
483
534
|
|
|
484
535
|
requestId: str
|
|
485
536
|
goal: str
|
|
486
537
|
llmConfig: HarnessKitLlmConfig
|
|
538
|
+
toolPolicy: NotRequired[HarnessKitToolPolicy | None]
|
|
487
539
|
actorId: NotRequired[str]
|
|
488
540
|
messages: NotRequired[list[HarnessKitThreadMessage]]
|
|
489
541
|
context: NotRequired[dict[str, Any]]
|
|
@@ -509,6 +561,7 @@ class HarnessKitCommand(TypedDict):
|
|
|
509
561
|
type: str
|
|
510
562
|
commandId: str
|
|
511
563
|
threadId: NotRequired[str]
|
|
564
|
+
toolPolicy: NotRequired[HarnessKitToolPolicy | None]
|
|
512
565
|
|
|
513
566
|
|
|
514
567
|
class HarnessKitCommandReceipt(TypedDict):
|
agentos_sdk/sdk.py
CHANGED
|
@@ -39,6 +39,7 @@ from agentos_sdk.protocol import (
|
|
|
39
39
|
HarnessKitEvent,
|
|
40
40
|
HarnessKitHealth,
|
|
41
41
|
HarnessKitOperationalSnapshot,
|
|
42
|
+
HarnessKitPrivateToolsRegistrationResult,
|
|
42
43
|
HarnessKitRunAccepted,
|
|
43
44
|
HarnessKitRunResult,
|
|
44
45
|
HarnessKitRuntimeInfo,
|
|
@@ -186,6 +187,13 @@ class AgentOSSDK:
|
|
|
186
187
|
return info["token"]
|
|
187
188
|
|
|
188
189
|
def _should_recover_app_auth(self, error: Exception) -> bool:
|
|
190
|
+
if isinstance(error, ApiError) and error.status == 403 and isinstance(error.data, Mapping):
|
|
191
|
+
details = error.data.get("error")
|
|
192
|
+
if (
|
|
193
|
+
isinstance(details, Mapping)
|
|
194
|
+
and details.get("code") == "harness_host_access_forbidden"
|
|
195
|
+
):
|
|
196
|
+
return False
|
|
189
197
|
if isinstance(error, ApiError) and error.status in {401, 403}:
|
|
190
198
|
return True
|
|
191
199
|
text = _collect_error_text(error).lower()
|
|
@@ -950,10 +958,10 @@ class HarnessKitModule:
|
|
|
950
958
|
|
|
951
959
|
Call ``agentos.register_bundle()`` first. Every method uses the active app
|
|
952
960
|
token and, after an authentication failure, re-registers the bundle once and
|
|
953
|
-
retries.
|
|
954
|
-
|
|
955
|
-
``get_operational_snapshot`` are reserved for the built-in Harness App;
|
|
956
|
-
Apps get an ``ApiError`` with status 403.
|
|
961
|
+
retries. The Gateway normally routes Apps to a shared Harness runtime and
|
|
962
|
+
scopes their data by bundle ID. ``switch_engine`` and
|
|
963
|
+
``get_operational_snapshot`` are reserved for the built-in Harness App;
|
|
964
|
+
other Apps get an ``ApiError`` with status 403.
|
|
957
965
|
"""
|
|
958
966
|
|
|
959
967
|
def __init__(self, sdk: AgentOSSDK) -> None:
|
|
@@ -1003,6 +1011,20 @@ class HarnessKitModule:
|
|
|
1003
1011
|
lambda token: self._sdk.harnessKit.delete_thread(token, thread_id)
|
|
1004
1012
|
)
|
|
1005
1013
|
|
|
1014
|
+
async def register_private_tools(
|
|
1015
|
+
self, *, thread_id: str, registration: Mapping[str, Any]
|
|
1016
|
+
) -> HarnessKitPrivateToolsRegistrationResult:
|
|
1017
|
+
"""Register or replace a local App's OpenTool callbacks for a thread.
|
|
1018
|
+
|
|
1019
|
+
The callback token in ``registration`` is separate from the AppKit token.
|
|
1020
|
+
The Gateway requires a direct local connection from an external App.
|
|
1021
|
+
"""
|
|
1022
|
+
return await self._sdk._with_app_auth_retry(
|
|
1023
|
+
lambda token: self._sdk.harnessKit.register_private_tools(
|
|
1024
|
+
token, thread_id, registration
|
|
1025
|
+
)
|
|
1026
|
+
)
|
|
1027
|
+
|
|
1006
1028
|
async def start_run(
|
|
1007
1029
|
self, *, thread_id: str, request: Mapping[str, Any]
|
|
1008
1030
|
) -> HarnessKitRunAccepted:
|
|
@@ -1099,6 +1121,7 @@ class HarnessKitModule:
|
|
|
1099
1121
|
getThread = get_thread
|
|
1100
1122
|
renameThread = rename_thread
|
|
1101
1123
|
deleteThread = delete_thread
|
|
1124
|
+
registerPrivateTools = register_private_tools
|
|
1102
1125
|
startRun = start_run
|
|
1103
1126
|
submitCommand = submit_command
|
|
1104
1127
|
getRunResult = get_run_result
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: agentos-sdk-python
|
|
3
|
-
Version: 1.1.
|
|
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 `
|
|
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 "
|
|
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=
|
|
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=
|
|
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["
|
|
412
|
+
print(model["id"], model["isDisabled"])
|
|
349
413
|
|
|
350
|
-
await sdk.modelkit.unregister_app_model(model_id=
|
|
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
|
-
|
|
356
|
-
|
|
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
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
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
|
-
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
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
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
agentos_sdk/__init__.py,sha256
|
|
1
|
+
agentos_sdk/__init__.py,sha256=MDJAptD0tCknYk1HYeHKLtrrw3MnI8EVEp2qQoShlUo,3741
|
|
2
2
|
agentos_sdk/handlers.py,sha256=0LVT-IQlu-bNbRRxMp4Ei3nMwT1OuQcuvsF4cDQKYTM,3435
|
|
3
|
-
agentos_sdk/normalizers.py,sha256=
|
|
4
|
-
agentos_sdk/protocol.py,sha256=
|
|
3
|
+
agentos_sdk/normalizers.py,sha256=I5um-rNUyFVuzO-Sg1L90-SvWClDY4c2pQ7zCI4Del8,8466
|
|
4
|
+
agentos_sdk/protocol.py,sha256=fg0dX9MiBVLu9WUSMKYMZsyXBFY7t7OoZpV43Bn6cbE,18229
|
|
5
5
|
agentos_sdk/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
6
|
-
agentos_sdk/sdk.py,sha256=
|
|
6
|
+
agentos_sdk/sdk.py,sha256=YTefFarYmH1059HfMLoz411SvKGGKSzrdogzAXJMfZM,43701
|
|
7
7
|
agentos_sdk/transport.py,sha256=MHUOdejTmTzJuS1TXYK4J5wd-LORyg54Q4FAfF3bm3w,6995
|
|
8
8
|
agentos_sdk/clients/__init__.py,sha256=rhutJ_h6C8omVjul-Z-JVS1xjf-Utfq295HGk2_SV2s,682
|
|
9
9
|
agentos_sdk/clients/agentkit.py,sha256=D83yaccY2W1ZgHb-XDTlAoqzSlx5Y47x2iVoFgdOZog,5991
|
|
@@ -11,13 +11,13 @@ agentos_sdk/clients/appkit.py,sha256=4j5VRuxiX88y7y2rlVQoJCRUxj2pKox9Tvt9zhBoCls
|
|
|
11
11
|
agentos_sdk/clients/authkit.py,sha256=9TYDwQUxO9HDS7qrTUMnSerlP2p-LCda3zmcLaA5UDg,1849
|
|
12
12
|
agentos_sdk/clients/cronkit.py,sha256=DiprjNhV3VEXXY5i15Ghgj5WgjHeoVfIEqs2zhuTRcY,4858
|
|
13
13
|
agentos_sdk/clients/discoverykit.py,sha256=e_VZdGeRboP4rCegEiAnHPtw7lbbRJAwcdwN-RnoVt8,1846
|
|
14
|
-
agentos_sdk/clients/harnesskit.py,sha256=
|
|
15
|
-
agentos_sdk/clients/modelkit.py,sha256=
|
|
14
|
+
agentos_sdk/clients/harnesskit.py,sha256=Mp01B9ifyj9E4AE5DcugkDS6apM8xj9Cx5X2vOQTux8,15265
|
|
15
|
+
agentos_sdk/clients/modelkit.py,sha256=ELy3-4_vS5RrKiMvE9sfOum6eNIPU49lafwP1s1Rv5Y,8838
|
|
16
16
|
agentos_sdk/clients/notifykit.py,sha256=YClS7r4TsndTLceAXD_EG-ZPr2E3_xd5r5pSzseTvGI,1795
|
|
17
17
|
agentos_sdk/clients/systemkit.py,sha256=1afOdJ_SUuMLP6b28FG2E2POf9OZisNHHBcm8YW0b6s,641
|
|
18
18
|
agentos_sdk/clients/toolkit.py,sha256=wWv4AJYlJfOrC9eVqxSAAYm-xYNca-lvT49SwxWp8VY,5277
|
|
19
19
|
agentos_sdk/clients/transferkit.py,sha256=8jGCZdwgJmz0hJ4Ox5sT1zIqbpzyA-GbzUrpNtwvT3M,4636
|
|
20
|
-
agentos_sdk_python-1.1.
|
|
21
|
-
agentos_sdk_python-1.1.
|
|
22
|
-
agentos_sdk_python-1.1.
|
|
23
|
-
agentos_sdk_python-1.1.
|
|
20
|
+
agentos_sdk_python-1.1.1.dist-info/METADATA,sha256=ryIx4ltZJBdg4mVjWfvuI9uaKn3AGNhX0GOtjxIkMuo,31649
|
|
21
|
+
agentos_sdk_python-1.1.1.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
22
|
+
agentos_sdk_python-1.1.1.dist-info/licenses/LICENSE,sha256=oarEto4UtUv6Y2Yeph34qL9zLBJEp0ZjuXrrwQ9uVdg,1064
|
|
23
|
+
agentos_sdk_python-1.1.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|