agentos-sdk-python 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/.gitignore +3 -0
  2. agentos_sdk_python-0.2.0/CHANGELOG.md +20 -0
  3. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/PKG-INFO +115 -10
  4. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/README-zh_CN.md +109 -9
  5. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/README.md +112 -9
  6. agentos_sdk_python-0.2.0/agentos_sdk/__init__.py +63 -0
  7. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/agentos_sdk/clients/agentkit.py +65 -3
  8. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/agentos_sdk/clients/appkit.py +2 -1
  9. agentos_sdk_python-0.2.0/agentos_sdk/clients/toolkit.py +176 -0
  10. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/agentos_sdk/handlers.py +38 -3
  11. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/agentos_sdk/normalizers.py +1 -0
  12. agentos_sdk_python-0.2.0/agentos_sdk/protocol.py +231 -0
  13. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/agentos_sdk/sdk.py +344 -48
  14. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/agentos_sdk/transport.py +34 -14
  15. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/pyproject.toml +16 -1
  16. agentos_sdk_python-0.2.0/tests/test_agentkit.py +540 -0
  17. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/tests/test_normalizers.py +25 -0
  18. agentos_sdk_python-0.2.0/tests/test_protocol.py +71 -0
  19. agentos_sdk_python-0.2.0/tests/test_sdk_facade.py +505 -0
  20. agentos_sdk_python-0.2.0/tests/test_toolkit.py +314 -0
  21. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/tests/test_transport.py +40 -1
  22. agentos_sdk_python-0.2.0/tests/typecheck/toolkit_usage.py +28 -0
  23. agentos_sdk_python-0.1.0/CHANGELOG.md +0 -7
  24. agentos_sdk_python-0.1.0/agentos_sdk/__init__.py +0 -14
  25. agentos_sdk_python-0.1.0/agentos_sdk/clients/toolkit.py +0 -43
  26. agentos_sdk_python-0.1.0/agentos_sdk/protocol.py +0 -51
  27. agentos_sdk_python-0.1.0/tests/test_agentkit.py +0 -116
  28. agentos_sdk_python-0.1.0/tests/test_sdk_facade.py +0 -76
  29. agentos_sdk_python-0.1.0/tests/test_toolkit.py +0 -46
  30. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/LICENSE +0 -0
  31. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/RELEASE.md +0 -0
  32. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/agentos_sdk/clients/__init__.py +0 -0
  33. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/agentos_sdk/clients/cronkit.py +0 -0
  34. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/agentos_sdk/clients/modelkit.py +0 -0
  35. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/agentos_sdk/clients/systemkit.py +0 -0
  36. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/agentos_sdk/py.typed +0 -0
  37. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/tests/test_cronkit.py +0 -0
  38. {agentos_sdk_python-0.1.0 → agentos_sdk_python-0.2.0}/tests/test_modelkit.py +0 -0
@@ -13,3 +13,6 @@ htmlcov/
13
13
  build/
14
14
  dist/
15
15
  *.egg-info/
16
+
17
+ .fenn/
18
+ .idea/
@@ -0,0 +1,20 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 - 2026-07-17
4
+
5
+ - Added OpenTool server declarations, registration statuses, and AppKit provisioning/availability events.
6
+ - Added paginated AgentKit history, summary history, and process history APIs.
7
+ - Added child-session routing and structured function-call lifecycle errors.
8
+ - Added ToolKit server metadata types and hardened SSE parsing.
9
+ - Added automatic app registration Bearer authentication to ToolKit list and load requests.
10
+ - Added one-time app token refresh and retry for ToolKit requests that return 401 or 403.
11
+ - Added `sdk.toolkit.call()` for non-streaming tool function calls.
12
+ - Added `sdk.toolkit.stream_call()` / `streamCall()` with typed stream events and safe
13
+ response closure after normal completion, errors, cancellation, or explicit early close.
14
+ - **Breaking:** Replaced `AgentOSEventHandler.on_call_app` / `onCallApp` with `on_app_event` / `onAppEvent`.
15
+
16
+ ## 0.1.0 - 2026-06-12
17
+
18
+ - Initial public release of the AgentOS Python SDK.
19
+ - Added async clients for AgentOS, AgentKit, CronKit, ModelKit, and ToolKit APIs.
20
+ - Added facade helpers for bearer token reuse, token refresh retry, stream callbacks, and TS-style alias compatibility.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agentos-sdk-python
3
- Version: 0.1.0
3
+ Version: 0.2.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
@@ -22,8 +22,10 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
22
  Classifier: Typing :: Typed
23
23
  Requires-Python: >=3.10
24
24
  Requires-Dist: httpx<1,>=0.27
25
+ Requires-Dist: typing-extensions<5,>=4.6
25
26
  Provides-Extra: dev
26
27
  Requires-Dist: build<2,>=1.2; extra == 'dev'
28
+ Requires-Dist: mypy<2,>=1.10; extra == 'dev'
27
29
  Requires-Dist: pytest-asyncio<1,>=0.23; extra == 'dev'
28
30
  Requires-Dist: pytest<9,>=8; extra == 'dev'
29
31
  Requires-Dist: ruff<1,>=0.5; extra == 'dev'
@@ -58,9 +60,16 @@ async def main():
58
60
  version = await sdk.agentos.get_version()
59
61
  print(version)
60
62
 
61
- await sdk.agentos.register_bundle(
62
- {"bundleId": "com.demo.app", "appGroupId": "com.demo.group"}
63
+ registration = await sdk.agentos.register_bundle(
64
+ {
65
+ "bundleId": "com.demo.app",
66
+ "appGroupId": "com.demo.group",
67
+ "opentoolServers": [
68
+ {"ref": "websearch", "name": "opentool-server-websearch"}
69
+ ],
70
+ }
63
71
  )
72
+ print(registration.get("opentoolServers", []))
64
73
 
65
74
  tasks = await sdk.cronkit.list_tasks(limit=10)
66
75
  print(tasks)
@@ -88,7 +97,7 @@ Use `async with AgentOSSDK(...)` or call `await sdk.aclose()` when done.
88
97
 
89
98
  `sdk.agentos.register_bundle(...)` stores the active app token. Protected facade methods in `sdk.agentkit` and `sdk.cronkit` use that token automatically.
90
99
 
91
- 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.
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.
92
101
 
93
102
  ## AgentOS Events
94
103
 
@@ -100,8 +109,11 @@ class Handler(AgentOSEventHandler):
100
109
  async def on_welcome(self, welcome):
101
110
  print("welcome", welcome)
102
111
 
103
- async def on_call_app(self, call):
104
- print("call app", call)
112
+ async def on_app_event(self, event):
113
+ if event["type"] == "toolkit.provision.succeeded":
114
+ print("tool ready", event["data"]["ref"], event["data"]["id"])
115
+ elif event["type"] == "toolkit.provision.failed":
116
+ print("tool failed", event["data"]["error"])
105
117
 
106
118
  async def on_done(self):
107
119
  print("subscription ended")
@@ -111,10 +123,21 @@ class Handler(AgentOSEventHandler):
111
123
 
112
124
 
113
125
  async with AgentOSSDK() as sdk:
114
- await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
126
+ await sdk.agentos.register_bundle(
127
+ {
128
+ "bundleId": "com.demo.app",
129
+ "opentoolServers": [
130
+ {"ref": "websearch", "name": "opentool-server-websearch"}
131
+ ],
132
+ }
133
+ )
115
134
  await sdk.agentos.subscribe(Handler())
116
135
  ```
117
136
 
137
+ Registration statuses are `running`, `starting`, and `notFound`; only `running` includes a callable tool `id`. A `starting` declaration becomes callable after `toolkit.provision.succeeded`. Stop using a tool while it is `toolkit.tool.unavailable` and resume after `toolkit.tool.available`.
138
+
139
+ `on_call_app` / `onCallApp` were removed in 0.2.0. Use `on_app_event` / `onAppEvent`.
140
+
118
141
  ## AgentKit
119
142
 
120
143
  ```python
@@ -148,7 +171,21 @@ async with AgentOSSDK() as sdk:
148
171
  )
149
172
  ```
150
173
 
151
- Direct AgentKit methods include `get_agent`, `create_agent`, `update_agent`, `delete_agent`, `init_session`, `init_simple`, `chat`, `chat_simple`, `history`, `stop`, `clear`, `callback`, and `stream_callback`.
174
+ Summary-first history is available without loading every process message:
175
+
176
+ ```python
177
+ summaries = await sdk.agentkit.history_summary(session_id=session["sessionId"])
178
+ messages = await sdk.agentkit.history_process(
179
+ session_id=session["sessionId"],
180
+ original_task_id=summaries[0]["originalTaskId"],
181
+ )
182
+ ```
183
+
184
+ `history_summary` defaults to page 1 with 30 items; `history_process` defaults to page 1 with 50 items. Page sizes must be between 1 and 200. CamelCase callers can use `historySummary(sessionId=...)` and `historyProcess(sessionId=..., originalTaskId=...)`.
185
+
186
+ Message, chunk, and function-call handlers receive a child `sessionId` when the event supplies one, otherwise the root session ID. Function-call failures passed to `on_error` use `FunctionCallLifecycleError` with `stage` equal to `function_call_parse_failed`, `function_call_handler_failed`, or `function_call_callback_failed`.
187
+
188
+ Direct AgentKit methods include `get_agent`, `create_agent`, `update_agent`, `delete_agent`, `init_session`, `init_simple`, `chat`, `chat_simple`, `history`, `history_summary`, `history_process`, `stop`, `clear`, `callback`, and `stream_callback`.
152
189
 
153
190
  ## CronKit
154
191
 
@@ -176,6 +213,7 @@ CronKit create requests default `concurrency` to `skipIfRunning`, `enabled` to `
176
213
  async with AgentOSSDK() as sdk:
177
214
  models = await sdk.modelkit.list_models()
178
215
  chat_models = await sdk.modelkit.list_models_by_task("chat")
216
+ print(models[0]["capabilities"]["reasoning"])
179
217
 
180
218
  completion = await sdk.modelkit.chat.create(
181
219
  {
@@ -191,6 +229,10 @@ async with AgentOSSDK() as sdk:
191
229
  print(chunk)
192
230
  ```
193
231
 
232
+ Normalized model capabilities include `vision`, `tool_call`, `stream`, and
233
+ `reasoning` booleans. `reasoning` reflects only the server-provided
234
+ `capabilities.reasoning` value and defaults to `False` when omitted.
235
+
194
236
  ModelKit also supports:
195
237
 
196
238
  - `sdk.modelkit.embedding.create(...)`
@@ -202,15 +244,78 @@ ModelKit also supports:
202
244
 
203
245
  ```python
204
246
  async with AgentOSSDK() as sdk:
247
+ registration = await sdk.agentos.register_bundle(
248
+ {
249
+ "bundleId": "com.example.app",
250
+ "opentoolServers": [
251
+ {
252
+ "ref": "websearch",
253
+ "name": "opentool-server-websearch",
254
+ }
255
+ ],
256
+ }
257
+ )
258
+
205
259
  tools = await sdk.toolkit.list_tool()
206
- definition = await sdk.toolkit.load_tool("tool-id")
260
+ websearch_tool = next(
261
+ (
262
+ tool
263
+ for tool in tools
264
+ if tool.get("status") == "running"
265
+ and (tool.get("server") or {}).get("name")
266
+ == "opentool-server-websearch"
267
+ ),
268
+ None,
269
+ )
270
+ if websearch_tool is None:
271
+ raise RuntimeError("The registered websearch tool is not running")
272
+
273
+ tool_id = websearch_tool["id"]
274
+ definition = await sdk.toolkit.load_tool(tool_id)
207
275
  raw_json = definition.to_json() if definition else None
208
276
 
277
+ result = await sdk.toolkit.call(
278
+ tool_id,
279
+ {
280
+ "id": "call-1",
281
+ "name": "websearch",
282
+ "arguments": {
283
+ "query": "AgentOS",
284
+ "max_results": 5,
285
+ },
286
+ },
287
+ )
288
+ print(result)
289
+
209
290
  async for event in sdk.toolkit.subscribe_tool_events("daemon-api-key"):
210
291
  print(event)
211
292
  ```
212
293
 
213
- `load_tool()` returns an `OpenToolDefinition` wrapper that preserves the raw JSON definition. It does not execute tools or implement browser/daemon OpenTool bridging.
294
+ `registration["opentoolServers"]` also contains the resolved `id` when its
295
+ status is `running`; the example uses `list_tool()` so it can select the running
296
+ tool by `server.name`.
297
+
298
+ `stream_call()` is only appropriate for functions whose tool server explicitly
299
+ supports `streamCall`. For such a function, retain the stream and close it when
300
+ consumer work ends early:
301
+
302
+ ```python
303
+ async def consume_streaming_function(sdk, streaming_tool_id):
304
+ stream = sdk.toolkit.stream_call(
305
+ streaming_tool_id,
306
+ {"id": "call-2", "name": "streaming-function", "arguments": {}},
307
+ )
308
+ try:
309
+ async for event in stream:
310
+ print(event["event"], event["data"])
311
+ finally:
312
+ await stream.aclose()
313
+ ```
314
+
315
+ The high-level ToolKit list, load, call, and stream-call methods use the bearer
316
+ token returned by `register_bundle()` and refresh it once after a 401/403
317
+ response. `load_tool()` returns an `OpenToolDefinition` wrapper that preserves
318
+ the raw JSON definition.
214
319
 
215
320
  ## Direct Clients
216
321
 
@@ -26,9 +26,16 @@ async def main():
26
26
  version = await sdk.agentos.get_version()
27
27
  print(version)
28
28
 
29
- await sdk.agentos.register_bundle(
30
- {"bundleId": "com.demo.app", "appGroupId": "com.demo.group"}
29
+ registration = await sdk.agentos.register_bundle(
30
+ {
31
+ "bundleId": "com.demo.app",
32
+ "appGroupId": "com.demo.group",
33
+ "opentoolServers": [
34
+ {"ref": "websearch", "name": "opentool-server-websearch"}
35
+ ],
36
+ }
31
37
  )
38
+ print(registration.get("opentoolServers", []))
32
39
 
33
40
  tasks = await sdk.cronkit.list_tasks(limit=10)
34
41
  print(tasks)
@@ -56,7 +63,7 @@ sdk = AgentOSSDK(
56
63
 
57
64
  `sdk.agentos.register_bundle(...)` 会保存当前 app token。`sdk.agentkit` 和 `sdk.cronkit` 下的受保护 facade 方法会自动使用该 token。
58
65
 
59
- 如果请求遇到 HTTP `401`、HTTP `403`,或响应文本包含可识别的 token 失效信息,SDK 会使用同一个 bundle 重新注册一次,并重试当前请求一次。
66
+ 如果请求遇到 HTTP `401`、HTTP `403`,或响应文本包含可识别的 token 失效信息,SDK 会使用同一个 bundle 重新注册一次,并重试当前请求一次。SDK 会保存 bundle 的防御性副本,因此刷新 token 时会保留原始 `opentoolServers` 声明。
60
67
 
61
68
  ## AgentOS 事件
62
69
 
@@ -68,8 +75,11 @@ class Handler(AgentOSEventHandler):
68
75
  async def on_welcome(self, welcome):
69
76
  print("welcome", welcome)
70
77
 
71
- async def on_call_app(self, call):
72
- print("call app", call)
78
+ async def on_app_event(self, event):
79
+ if event["type"] == "toolkit.provision.succeeded":
80
+ print("tool ready", event["data"]["ref"], event["data"]["id"])
81
+ elif event["type"] == "toolkit.provision.failed":
82
+ print("tool failed", event["data"]["error"])
73
83
 
74
84
  async def on_done(self):
75
85
  print("subscription ended")
@@ -79,10 +89,21 @@ class Handler(AgentOSEventHandler):
79
89
 
80
90
 
81
91
  async with AgentOSSDK() as sdk:
82
- await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
92
+ await sdk.agentos.register_bundle(
93
+ {
94
+ "bundleId": "com.demo.app",
95
+ "opentoolServers": [
96
+ {"ref": "websearch", "name": "opentool-server-websearch"}
97
+ ],
98
+ }
99
+ )
83
100
  await sdk.agentos.subscribe(Handler())
84
101
  ```
85
102
 
103
+ 注册状态包括 `running`、`starting` 和 `notFound`,只有 `running` 会返回可调用的 tool `id`。`starting` 声明需要等到 `toolkit.provision.succeeded` 才能调用;收到 `toolkit.tool.unavailable` 后应暂停使用,直到 `toolkit.tool.available`。
104
+
105
+ 0.2.0 已移除 `on_call_app` / `onCallApp`,请改用 `on_app_event` / `onAppEvent`。
106
+
86
107
  ## AgentKit
87
108
 
88
109
  ```python
@@ -116,7 +137,21 @@ async with AgentOSSDK() as sdk:
116
137
  )
117
138
  ```
118
139
 
119
- AgentKit facade 包含 `get_agent`、`create_agent`、`update_agent`、`delete_agent`、`init_session`、`init_simple`、`chat`、`chat_simple`、`history`、`stop`、`clear`、`callback` 和 `stream_callback`。
140
+ 可以先加载会话摘要,再按需加载过程消息:
141
+
142
+ ```python
143
+ summaries = await sdk.agentkit.history_summary(session_id=session["sessionId"])
144
+ messages = await sdk.agentkit.history_process(
145
+ session_id=session["sessionId"],
146
+ original_task_id=summaries[0]["originalTaskId"],
147
+ )
148
+ ```
149
+
150
+ `history_summary` 默认第 1 页、每页 30 条;`history_process` 默认第 1 页、每页 50 条。每页数量必须在 1–200 之间。camelCase 调用方式为 `historySummary(sessionId=...)` 和 `historyProcess(sessionId=..., originalTaskId=...)`。
151
+
152
+ message、chunk 和 function-call handler 会优先收到事件中的子 `sessionId`,缺失时回退到根 session。function-call 错误会通过 `FunctionCallLifecycleError` 传给 `on_error`,其 `stage` 为 `function_call_parse_failed`、`function_call_handler_failed` 或 `function_call_callback_failed`。
153
+
154
+ AgentKit facade 包含 `get_agent`、`create_agent`、`update_agent`、`delete_agent`、`init_session`、`init_simple`、`chat`、`chat_simple`、`history`、`history_summary`、`history_process`、`stop`、`clear`、`callback` 和 `stream_callback`。
120
155
 
121
156
  ## CronKit
122
157
 
@@ -144,6 +179,7 @@ CronKit 创建任务时会默认设置 `concurrency="skipIfRunning"`、`enabled=
144
179
  async with AgentOSSDK() as sdk:
145
180
  models = await sdk.modelkit.list_models()
146
181
  chat_models = await sdk.modelkit.list_models_by_task("chat")
182
+ print(models[0]["capabilities"]["reasoning"])
147
183
 
148
184
  completion = await sdk.modelkit.chat.create(
149
185
  {
@@ -159,6 +195,10 @@ async with AgentOSSDK() as sdk:
159
195
  print(chunk)
160
196
  ```
161
197
 
198
+ 规范化后的模型能力包含 `vision`、`tool_call`、`stream` 和 `reasoning`
199
+ 布尔字段。`reasoning` 只使用服务端返回的 `capabilities.reasoning`,字段缺失时
200
+ 默认为 `False`。
201
+
162
202
  ModelKit 还支持:
163
203
 
164
204
  - `sdk.modelkit.embedding.create(...)`
@@ -170,15 +210,75 @@ ModelKit 还支持:
170
210
 
171
211
  ```python
172
212
  async with AgentOSSDK() as sdk:
213
+ registration = await sdk.agentos.register_bundle(
214
+ {
215
+ "bundleId": "com.example.app",
216
+ "opentoolServers": [
217
+ {
218
+ "ref": "websearch",
219
+ "name": "opentool-server-websearch",
220
+ }
221
+ ],
222
+ }
223
+ )
224
+
173
225
  tools = await sdk.toolkit.list_tool()
174
- definition = await sdk.toolkit.load_tool("tool-id")
226
+ websearch_tool = next(
227
+ (
228
+ tool
229
+ for tool in tools
230
+ if tool.get("status") == "running"
231
+ and (tool.get("server") or {}).get("name")
232
+ == "opentool-server-websearch"
233
+ ),
234
+ None,
235
+ )
236
+ if websearch_tool is None:
237
+ raise RuntimeError("已注册的 websearch 工具尚未运行")
238
+
239
+ tool_id = websearch_tool["id"]
240
+ definition = await sdk.toolkit.load_tool(tool_id)
175
241
  raw_json = definition.to_json() if definition else None
176
242
 
243
+ result = await sdk.toolkit.call(
244
+ tool_id,
245
+ {
246
+ "id": "call-1",
247
+ "name": "websearch",
248
+ "arguments": {
249
+ "query": "AgentOS",
250
+ "max_results": 5,
251
+ },
252
+ },
253
+ )
254
+ print(result)
255
+
177
256
  async for event in sdk.toolkit.subscribe_tool_events("daemon-api-key"):
178
257
  print(event)
179
258
  ```
180
259
 
181
- `load_tool()` 返回 `OpenToolDefinition` 包装对象,用于保留原始 JSON 定义。它不会执行工具,也不会实现浏览器或 daemon 的 OpenTool bridge。
260
+ 当 `registration["opentoolServers"]` 中的记录状态为 `running` 时,它也会包含
261
+ 解析后的 `id`;上例使用 `list_tool()`,以便按 `server.name` 选择正在运行的工具。
262
+
263
+ `stream_call()` 只适用于工具服务明确支持 `streamCall` 的函数。调用这类函数时,
264
+ 应保留 stream,并在 consumer 提前结束时将其关闭:
265
+
266
+ ```python
267
+ async def consume_streaming_function(sdk, streaming_tool_id):
268
+ stream = sdk.toolkit.stream_call(
269
+ streaming_tool_id,
270
+ {"id": "call-2", "name": "streaming-function", "arguments": {}},
271
+ )
272
+ try:
273
+ async for event in stream:
274
+ print(event["event"], event["data"])
275
+ finally:
276
+ await stream.aclose()
277
+ ```
278
+
279
+ 高层 ToolKit 的列表、加载、调用和流式调用方法会自动使用
280
+ `register_bundle()` 返回的 Bearer token,遇到 401/403 时会刷新 token 并重试
281
+ 一次。`load_tool()` 返回 `OpenToolDefinition` 包装对象,用于保留原始 JSON 定义。
182
282
 
183
283
  ## 直接使用低层 Client
184
284
 
@@ -26,9 +26,16 @@ async def main():
26
26
  version = await sdk.agentos.get_version()
27
27
  print(version)
28
28
 
29
- await sdk.agentos.register_bundle(
30
- {"bundleId": "com.demo.app", "appGroupId": "com.demo.group"}
29
+ registration = await sdk.agentos.register_bundle(
30
+ {
31
+ "bundleId": "com.demo.app",
32
+ "appGroupId": "com.demo.group",
33
+ "opentoolServers": [
34
+ {"ref": "websearch", "name": "opentool-server-websearch"}
35
+ ],
36
+ }
31
37
  )
38
+ print(registration.get("opentoolServers", []))
32
39
 
33
40
  tasks = await sdk.cronkit.list_tasks(limit=10)
34
41
  print(tasks)
@@ -56,7 +63,7 @@ Use `async with AgentOSSDK(...)` or call `await sdk.aclose()` when done.
56
63
 
57
64
  `sdk.agentos.register_bundle(...)` stores the active app token. Protected facade methods in `sdk.agentkit` and `sdk.cronkit` use that token automatically.
58
65
 
59
- 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.
66
+ 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.
60
67
 
61
68
  ## AgentOS Events
62
69
 
@@ -68,8 +75,11 @@ class Handler(AgentOSEventHandler):
68
75
  async def on_welcome(self, welcome):
69
76
  print("welcome", welcome)
70
77
 
71
- async def on_call_app(self, call):
72
- print("call app", call)
78
+ async def on_app_event(self, event):
79
+ if event["type"] == "toolkit.provision.succeeded":
80
+ print("tool ready", event["data"]["ref"], event["data"]["id"])
81
+ elif event["type"] == "toolkit.provision.failed":
82
+ print("tool failed", event["data"]["error"])
73
83
 
74
84
  async def on_done(self):
75
85
  print("subscription ended")
@@ -79,10 +89,21 @@ class Handler(AgentOSEventHandler):
79
89
 
80
90
 
81
91
  async with AgentOSSDK() as sdk:
82
- await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
92
+ await sdk.agentos.register_bundle(
93
+ {
94
+ "bundleId": "com.demo.app",
95
+ "opentoolServers": [
96
+ {"ref": "websearch", "name": "opentool-server-websearch"}
97
+ ],
98
+ }
99
+ )
83
100
  await sdk.agentos.subscribe(Handler())
84
101
  ```
85
102
 
103
+ Registration statuses are `running`, `starting`, and `notFound`; only `running` includes a callable tool `id`. A `starting` declaration becomes callable after `toolkit.provision.succeeded`. Stop using a tool while it is `toolkit.tool.unavailable` and resume after `toolkit.tool.available`.
104
+
105
+ `on_call_app` / `onCallApp` were removed in 0.2.0. Use `on_app_event` / `onAppEvent`.
106
+
86
107
  ## AgentKit
87
108
 
88
109
  ```python
@@ -116,7 +137,21 @@ async with AgentOSSDK() as sdk:
116
137
  )
117
138
  ```
118
139
 
119
- Direct AgentKit methods include `get_agent`, `create_agent`, `update_agent`, `delete_agent`, `init_session`, `init_simple`, `chat`, `chat_simple`, `history`, `stop`, `clear`, `callback`, and `stream_callback`.
140
+ Summary-first history is available without loading every process message:
141
+
142
+ ```python
143
+ summaries = await sdk.agentkit.history_summary(session_id=session["sessionId"])
144
+ messages = await sdk.agentkit.history_process(
145
+ session_id=session["sessionId"],
146
+ original_task_id=summaries[0]["originalTaskId"],
147
+ )
148
+ ```
149
+
150
+ `history_summary` defaults to page 1 with 30 items; `history_process` defaults to page 1 with 50 items. Page sizes must be between 1 and 200. CamelCase callers can use `historySummary(sessionId=...)` and `historyProcess(sessionId=..., originalTaskId=...)`.
151
+
152
+ Message, chunk, and function-call handlers receive a child `sessionId` when the event supplies one, otherwise the root session ID. Function-call failures passed to `on_error` use `FunctionCallLifecycleError` with `stage` equal to `function_call_parse_failed`, `function_call_handler_failed`, or `function_call_callback_failed`.
153
+
154
+ Direct AgentKit methods include `get_agent`, `create_agent`, `update_agent`, `delete_agent`, `init_session`, `init_simple`, `chat`, `chat_simple`, `history`, `history_summary`, `history_process`, `stop`, `clear`, `callback`, and `stream_callback`.
120
155
 
121
156
  ## CronKit
122
157
 
@@ -144,6 +179,7 @@ CronKit create requests default `concurrency` to `skipIfRunning`, `enabled` to `
144
179
  async with AgentOSSDK() as sdk:
145
180
  models = await sdk.modelkit.list_models()
146
181
  chat_models = await sdk.modelkit.list_models_by_task("chat")
182
+ print(models[0]["capabilities"]["reasoning"])
147
183
 
148
184
  completion = await sdk.modelkit.chat.create(
149
185
  {
@@ -159,6 +195,10 @@ async with AgentOSSDK() as sdk:
159
195
  print(chunk)
160
196
  ```
161
197
 
198
+ Normalized model capabilities include `vision`, `tool_call`, `stream`, and
199
+ `reasoning` booleans. `reasoning` reflects only the server-provided
200
+ `capabilities.reasoning` value and defaults to `False` when omitted.
201
+
162
202
  ModelKit also supports:
163
203
 
164
204
  - `sdk.modelkit.embedding.create(...)`
@@ -170,15 +210,78 @@ ModelKit also supports:
170
210
 
171
211
  ```python
172
212
  async with AgentOSSDK() as sdk:
213
+ registration = await sdk.agentos.register_bundle(
214
+ {
215
+ "bundleId": "com.example.app",
216
+ "opentoolServers": [
217
+ {
218
+ "ref": "websearch",
219
+ "name": "opentool-server-websearch",
220
+ }
221
+ ],
222
+ }
223
+ )
224
+
173
225
  tools = await sdk.toolkit.list_tool()
174
- definition = await sdk.toolkit.load_tool("tool-id")
226
+ websearch_tool = next(
227
+ (
228
+ tool
229
+ for tool in tools
230
+ if tool.get("status") == "running"
231
+ and (tool.get("server") or {}).get("name")
232
+ == "opentool-server-websearch"
233
+ ),
234
+ None,
235
+ )
236
+ if websearch_tool is None:
237
+ raise RuntimeError("The registered websearch tool is not running")
238
+
239
+ tool_id = websearch_tool["id"]
240
+ definition = await sdk.toolkit.load_tool(tool_id)
175
241
  raw_json = definition.to_json() if definition else None
176
242
 
243
+ result = await sdk.toolkit.call(
244
+ tool_id,
245
+ {
246
+ "id": "call-1",
247
+ "name": "websearch",
248
+ "arguments": {
249
+ "query": "AgentOS",
250
+ "max_results": 5,
251
+ },
252
+ },
253
+ )
254
+ print(result)
255
+
177
256
  async for event in sdk.toolkit.subscribe_tool_events("daemon-api-key"):
178
257
  print(event)
179
258
  ```
180
259
 
181
- `load_tool()` returns an `OpenToolDefinition` wrapper that preserves the raw JSON definition. It does not execute tools or implement browser/daemon OpenTool bridging.
260
+ `registration["opentoolServers"]` also contains the resolved `id` when its
261
+ status is `running`; the example uses `list_tool()` so it can select the running
262
+ tool by `server.name`.
263
+
264
+ `stream_call()` is only appropriate for functions whose tool server explicitly
265
+ supports `streamCall`. For such a function, retain the stream and close it when
266
+ consumer work ends early:
267
+
268
+ ```python
269
+ async def consume_streaming_function(sdk, streaming_tool_id):
270
+ stream = sdk.toolkit.stream_call(
271
+ streaming_tool_id,
272
+ {"id": "call-2", "name": "streaming-function", "arguments": {}},
273
+ )
274
+ try:
275
+ async for event in stream:
276
+ print(event["event"], event["data"])
277
+ finally:
278
+ await stream.aclose()
279
+ ```
280
+
281
+ The high-level ToolKit list, load, call, and stream-call methods use the bearer
282
+ token returned by `register_bundle()` and refresh it once after a 401/403
283
+ response. `load_tool()` returns an `OpenToolDefinition` wrapper that preserves
284
+ the raw JSON definition.
182
285
 
183
286
  ## Direct Clients
184
287
 
@@ -0,0 +1,63 @@
1
+ from .handlers import (
2
+ AgentMessageHandler,
3
+ AgentOSEventHandler,
4
+ EventType,
5
+ FunctionCallLifecycleError,
6
+ ToolReturn,
7
+ )
8
+ from .protocol import (
9
+ AccessToken,
10
+ AgentMessage,
11
+ AgentMessageChunk,
12
+ AppBundle,
13
+ AppEvent,
14
+ AppEventType,
15
+ HistoryTurnStatus,
16
+ HistoryTurnSummary,
17
+ OpenToolAvailability,
18
+ OpenToolProvisionFailure,
19
+ OpenToolProvisionSuccess,
20
+ OpenToolRegistration,
21
+ OpenToolRegistrationStatus,
22
+ OpenToolResolvedServer,
23
+ OpenToolServerDeclaration,
24
+ TaskStatus,
25
+ ToolDto,
26
+ ToolServerDto,
27
+ ToolStream,
28
+ ToolStreamEvent,
29
+ )
30
+ from .sdk import AgentOSSDK
31
+ from .transport import ApiClient, ApiError, SseEvent
32
+
33
+ __all__ = [
34
+ "AccessToken",
35
+ "AgentMessage",
36
+ "AgentMessageChunk",
37
+ "AgentMessageHandler",
38
+ "AgentOSEventHandler",
39
+ "AgentOSSDK",
40
+ "ApiClient",
41
+ "ApiError",
42
+ "AppBundle",
43
+ "AppEvent",
44
+ "AppEventType",
45
+ "EventType",
46
+ "FunctionCallLifecycleError",
47
+ "HistoryTurnStatus",
48
+ "HistoryTurnSummary",
49
+ "OpenToolAvailability",
50
+ "OpenToolProvisionFailure",
51
+ "OpenToolProvisionSuccess",
52
+ "OpenToolRegistration",
53
+ "OpenToolRegistrationStatus",
54
+ "OpenToolResolvedServer",
55
+ "OpenToolServerDeclaration",
56
+ "SseEvent",
57
+ "TaskStatus",
58
+ "ToolDto",
59
+ "ToolReturn",
60
+ "ToolServerDto",
61
+ "ToolStream",
62
+ "ToolStreamEvent",
63
+ ]