agentos-sdk-python 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. agentos_sdk_python-0.1.0/.gitignore +15 -0
  2. agentos_sdk_python-0.1.0/CHANGELOG.md +7 -0
  3. agentos_sdk_python-0.1.0/LICENSE +21 -0
  4. agentos_sdk_python-0.1.0/PKG-INFO +234 -0
  5. agentos_sdk_python-0.1.0/README-zh_CN.md +202 -0
  6. agentos_sdk_python-0.1.0/README.md +202 -0
  7. agentos_sdk_python-0.1.0/RELEASE.md +57 -0
  8. agentos_sdk_python-0.1.0/agentos_sdk/__init__.py +14 -0
  9. agentos_sdk_python-0.1.0/agentos_sdk/clients/__init__.py +15 -0
  10. agentos_sdk_python-0.1.0/agentos_sdk/clients/agentkit.py +152 -0
  11. agentos_sdk_python-0.1.0/agentos_sdk/clients/appkit.py +23 -0
  12. agentos_sdk_python-0.1.0/agentos_sdk/clients/cronkit.py +144 -0
  13. agentos_sdk_python-0.1.0/agentos_sdk/clients/modelkit.py +127 -0
  14. agentos_sdk_python-0.1.0/agentos_sdk/clients/systemkit.py +23 -0
  15. agentos_sdk_python-0.1.0/agentos_sdk/clients/toolkit.py +43 -0
  16. agentos_sdk_python-0.1.0/agentos_sdk/handlers.py +92 -0
  17. agentos_sdk_python-0.1.0/agentos_sdk/normalizers.py +134 -0
  18. agentos_sdk_python-0.1.0/agentos_sdk/protocol.py +51 -0
  19. agentos_sdk_python-0.1.0/agentos_sdk/py.typed +1 -0
  20. agentos_sdk_python-0.1.0/agentos_sdk/sdk.py +485 -0
  21. agentos_sdk_python-0.1.0/agentos_sdk/transport.py +197 -0
  22. agentos_sdk_python-0.1.0/pyproject.toml +69 -0
  23. agentos_sdk_python-0.1.0/tests/test_agentkit.py +116 -0
  24. agentos_sdk_python-0.1.0/tests/test_cronkit.py +84 -0
  25. agentos_sdk_python-0.1.0/tests/test_modelkit.py +79 -0
  26. agentos_sdk_python-0.1.0/tests/test_normalizers.py +72 -0
  27. agentos_sdk_python-0.1.0/tests/test_sdk_facade.py +76 -0
  28. agentos_sdk_python-0.1.0/tests/test_toolkit.py +46 -0
  29. agentos_sdk_python-0.1.0/tests/test_transport.py +66 -0
@@ -0,0 +1,15 @@
1
+ .DS_Store
2
+ .venv/
3
+
4
+ __pycache__/
5
+ *.py[cod]
6
+
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ .mypy_cache/
10
+ .coverage
11
+ htmlcov/
12
+
13
+ build/
14
+ dist/
15
+ *.egg-info/
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 - 2026-06-12
4
+
5
+ - Initial public release of the AgentOS Python SDK.
6
+ - Added async clients for AgentOS, AgentKit, CronKit, ModelKit, and ToolKit APIs.
7
+ - Added facade helpers for bearer token reuse, token refresh retry, stream callbacks, and TS-style alias compatibility.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 LiteVar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,234 @@
1
+ Metadata-Version: 2.4
2
+ Name: agentos-sdk-python
3
+ Version: 0.1.0
4
+ Summary: Async Python SDK for AgentOS APIs.
5
+ Project-URL: Repository, https://gitlab.litevar.com/litevar/agentos/agentos-sdk-python
6
+ Project-URL: Issues, https://gitlab.litevar.com/litevar/agentos/agentos-sdk-python/-/issues
7
+ Author: LiteVar
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: agentkit,agentos,async,modelkit,sdk,toolkit
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: httpx<1,>=0.27
25
+ Provides-Extra: dev
26
+ Requires-Dist: build<2,>=1.2; extra == 'dev'
27
+ Requires-Dist: pytest-asyncio<1,>=0.23; extra == 'dev'
28
+ Requires-Dist: pytest<9,>=8; extra == 'dev'
29
+ Requires-Dist: ruff<1,>=0.5; extra == 'dev'
30
+ Requires-Dist: twine<7,>=6; extra == 'dev'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # AgentOS SDK for Python
34
+
35
+ Async Python SDK for AgentOS APIs. The package is a thin client over AgentOS HTTP and SSE endpoints with small compatibility helpers for bearer tokens, stream callbacks, Pythonic method names, and request defaults.
36
+
37
+ ## Install
38
+
39
+ ```bash
40
+ pip install agentos-sdk-python
41
+ ```
42
+
43
+ For local development:
44
+
45
+ ```bash
46
+ python3 -m venv .venv
47
+ .venv/bin/python -m pip install -e ".[dev]"
48
+ ```
49
+
50
+ ## Quickstart
51
+
52
+ ```python
53
+ from agentos_sdk import AgentOSSDK
54
+
55
+
56
+ async def main():
57
+ async with AgentOSSDK(base_url="http://localhost:8888") as sdk:
58
+ version = await sdk.agentos.get_version()
59
+ print(version)
60
+
61
+ await sdk.agentos.register_bundle(
62
+ {"bundleId": "com.demo.app", "appGroupId": "com.demo.group"}
63
+ )
64
+
65
+ tasks = await sdk.cronkit.list_tasks(limit=10)
66
+ print(tasks)
67
+ ```
68
+
69
+ `AgentOSSDK` also exposes TS-style camelCase aliases for common migration paths, such as `registerBundle`, `listTasks`, `chatSimple`, `listModels`, and `loadTool`.
70
+
71
+ ## Transport
72
+
73
+ The SDK uses `httpx.AsyncClient` and defaults to `http://localhost:8888`.
74
+
75
+ ```python
76
+ from agentos_sdk import AgentOSSDK
77
+
78
+ sdk = AgentOSSDK(
79
+ base_url="http://localhost:8888",
80
+ connect_timeout=5.0,
81
+ receive_timeout=10.0,
82
+ )
83
+ ```
84
+
85
+ Use `async with AgentOSSDK(...)` or call `await sdk.aclose()` when done.
86
+
87
+ ## Token Handling
88
+
89
+ `sdk.agentos.register_bundle(...)` stores the active app token. Protected facade methods in `sdk.agentkit` and `sdk.cronkit` use that token automatically.
90
+
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.
92
+
93
+ ## AgentOS Events
94
+
95
+ ```python
96
+ from agentos_sdk import AgentOSEventHandler, AgentOSSDK
97
+
98
+
99
+ class Handler(AgentOSEventHandler):
100
+ async def on_welcome(self, welcome):
101
+ print("welcome", welcome)
102
+
103
+ async def on_call_app(self, call):
104
+ print("call app", call)
105
+
106
+ async def on_done(self):
107
+ print("subscription ended")
108
+
109
+ async def on_error(self, error):
110
+ raise error
111
+
112
+
113
+ async with AgentOSSDK() as sdk:
114
+ await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
115
+ await sdk.agentos.subscribe(Handler())
116
+ ```
117
+
118
+ ## AgentKit
119
+
120
+ ```python
121
+ from agentos_sdk import AgentMessageHandler, AgentOSSDK, ToolReturn
122
+
123
+
124
+ class ChatHandler(AgentMessageHandler):
125
+ async def on_message(self, session_id, message):
126
+ print("message", session_id, message)
127
+
128
+ async def on_chunk(self, session_id, chunk):
129
+ print("chunk", session_id, chunk)
130
+
131
+ async def on_function_call(self, session_id, function_call):
132
+ return ToolReturn(function_call["id"], {"ok": True})
133
+
134
+ async def on_done(self):
135
+ print("done")
136
+
137
+ async def on_error(self, error):
138
+ raise error
139
+
140
+
141
+ async with AgentOSSDK() as sdk:
142
+ await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
143
+ session = await sdk.agentkit.init_session()
144
+ await sdk.agentkit.chat(
145
+ session,
146
+ {"content": [{"type": "text", "message": "Hello"}]},
147
+ ChatHandler(),
148
+ )
149
+ ```
150
+
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`.
152
+
153
+ ## CronKit
154
+
155
+ ```python
156
+ async with AgentOSSDK() as sdk:
157
+ await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
158
+ task = await sdk.cronkit.create_task(
159
+ request={
160
+ "name": "Daily summary",
161
+ "schedule": "0 9 * * *",
162
+ "spec": {
163
+ "systemPrompt": "You are a scheduled agent.",
164
+ "content": [{"type": "text", "message": "Summarize today."}],
165
+ },
166
+ }
167
+ )
168
+ await sdk.cronkit.run_task_now(cron_id=task["cronId"])
169
+ ```
170
+
171
+ CronKit create requests default `concurrency` to `skipIfRunning`, `enabled` to `True`, and `spec.timeoutSeconds` to `3600`.
172
+
173
+ ## ModelKit
174
+
175
+ ```python
176
+ async with AgentOSSDK() as sdk:
177
+ models = await sdk.modelkit.list_models()
178
+ chat_models = await sdk.modelkit.list_models_by_task("chat")
179
+
180
+ completion = await sdk.modelkit.chat.create(
181
+ {
182
+ "model": "qwen3-1.7b",
183
+ "messages": [{"role": "user", "content": "Hello"}],
184
+ "maxTokens": 128,
185
+ }
186
+ )
187
+
188
+ async for chunk in sdk.modelkit.chat.create_stream(
189
+ {"model": "qwen3-1.7b", "messages": [{"role": "user", "content": "Stream"}]}
190
+ ):
191
+ print(chunk)
192
+ ```
193
+
194
+ ModelKit also supports:
195
+
196
+ - `sdk.modelkit.embedding.create(...)`
197
+ - `sdk.modelkit.asr.transcribe(...)`
198
+ - `sdk.modelkit.tts.synthesize(...)`
199
+ - `sdk.modelkit.tts.list_voices()`
200
+
201
+ ## ToolKit
202
+
203
+ ```python
204
+ async with AgentOSSDK() as sdk:
205
+ tools = await sdk.toolkit.list_tool()
206
+ definition = await sdk.toolkit.load_tool("tool-id")
207
+ raw_json = definition.to_json() if definition else None
208
+
209
+ async for event in sdk.toolkit.subscribe_tool_events("daemon-api-key"):
210
+ print(event)
211
+ ```
212
+
213
+ `load_tool()` returns an `OpenToolDefinition` wrapper that preserves the raw JSON definition. It does not execute tools or implement browser/daemon OpenTool bridging.
214
+
215
+ ## Direct Clients
216
+
217
+ The low-level clients are available for explicit-token or custom transport usage:
218
+
219
+ ```python
220
+ from agentos_sdk.clients import AgentKitClient, CronKitClient, ModelKitClient
221
+ from agentos_sdk.transport import ApiClient
222
+
223
+ api = ApiClient(base_url="http://localhost:8888")
224
+ agentkit = AgentKitClient(api)
225
+ agent = await agentkit.get_agent("bearer-token", "agent-id")
226
+ ```
227
+
228
+ ## Development
229
+
230
+ ```bash
231
+ .venv/bin/python -m compileall agentos_sdk
232
+ .venv/bin/python -m pytest -q
233
+ .venv/bin/ruff check .
234
+ ```
@@ -0,0 +1,202 @@
1
+ # AgentOS Python SDK
2
+
3
+ AgentOS API 的异步 Python SDK。这个包是 AgentOS HTTP 与 SSE 端点之上的薄客户端,只包含少量兼容层:Bearer Token 管理、流式回调分发、Pythonic 方法名、请求默认值和常用 TS 风格别名。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ pip install agentos-sdk-python
9
+ ```
10
+
11
+ 本地开发:
12
+
13
+ ```bash
14
+ python3 -m venv .venv
15
+ .venv/bin/python -m pip install -e ".[dev]"
16
+ ```
17
+
18
+ ## 快速开始
19
+
20
+ ```python
21
+ from agentos_sdk import AgentOSSDK
22
+
23
+
24
+ async def main():
25
+ async with AgentOSSDK(base_url="http://localhost:8888") as sdk:
26
+ version = await sdk.agentos.get_version()
27
+ print(version)
28
+
29
+ await sdk.agentos.register_bundle(
30
+ {"bundleId": "com.demo.app", "appGroupId": "com.demo.group"}
31
+ )
32
+
33
+ tasks = await sdk.cronkit.list_tasks(limit=10)
34
+ print(tasks)
35
+ ```
36
+
37
+ SDK 默认使用 snake_case 方法名,同时为常用迁移场景提供 camelCase 别名,例如 `registerBundle`、`listTasks`、`chatSimple`、`listModels` 和 `loadTool`。
38
+
39
+ ## 传输层
40
+
41
+ SDK 使用 `httpx.AsyncClient`,默认网关地址是 `http://localhost:8888`。
42
+
43
+ ```python
44
+ from agentos_sdk import AgentOSSDK
45
+
46
+ sdk = AgentOSSDK(
47
+ base_url="http://localhost:8888",
48
+ connect_timeout=5.0,
49
+ receive_timeout=10.0,
50
+ )
51
+ ```
52
+
53
+ 推荐使用 `async with AgentOSSDK(...)`,或在结束时调用 `await sdk.aclose()`。
54
+
55
+ ## Token 处理
56
+
57
+ `sdk.agentos.register_bundle(...)` 会保存当前 app token。`sdk.agentkit` 和 `sdk.cronkit` 下的受保护 facade 方法会自动使用该 token。
58
+
59
+ 如果请求遇到 HTTP `401`、HTTP `403`,或响应文本包含可识别的 token 失效信息,SDK 会使用同一个 bundle 重新注册一次,并重试当前请求一次。
60
+
61
+ ## AgentOS 事件
62
+
63
+ ```python
64
+ from agentos_sdk import AgentOSEventHandler, AgentOSSDK
65
+
66
+
67
+ class Handler(AgentOSEventHandler):
68
+ async def on_welcome(self, welcome):
69
+ print("welcome", welcome)
70
+
71
+ async def on_call_app(self, call):
72
+ print("call app", call)
73
+
74
+ async def on_done(self):
75
+ print("subscription ended")
76
+
77
+ async def on_error(self, error):
78
+ raise error
79
+
80
+
81
+ async with AgentOSSDK() as sdk:
82
+ await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
83
+ await sdk.agentos.subscribe(Handler())
84
+ ```
85
+
86
+ ## AgentKit
87
+
88
+ ```python
89
+ from agentos_sdk import AgentMessageHandler, AgentOSSDK, ToolReturn
90
+
91
+
92
+ class ChatHandler(AgentMessageHandler):
93
+ async def on_message(self, session_id, message):
94
+ print("message", session_id, message)
95
+
96
+ async def on_chunk(self, session_id, chunk):
97
+ print("chunk", session_id, chunk)
98
+
99
+ async def on_function_call(self, session_id, function_call):
100
+ return ToolReturn(function_call["id"], {"ok": True})
101
+
102
+ async def on_done(self):
103
+ print("done")
104
+
105
+ async def on_error(self, error):
106
+ raise error
107
+
108
+
109
+ async with AgentOSSDK() as sdk:
110
+ await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
111
+ session = await sdk.agentkit.init_session()
112
+ await sdk.agentkit.chat(
113
+ session,
114
+ {"content": [{"type": "text", "message": "Hello"}]},
115
+ ChatHandler(),
116
+ )
117
+ ```
118
+
119
+ AgentKit facade 包含 `get_agent`、`create_agent`、`update_agent`、`delete_agent`、`init_session`、`init_simple`、`chat`、`chat_simple`、`history`、`stop`、`clear`、`callback` 和 `stream_callback`。
120
+
121
+ ## CronKit
122
+
123
+ ```python
124
+ async with AgentOSSDK() as sdk:
125
+ await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
126
+ task = await sdk.cronkit.create_task(
127
+ request={
128
+ "name": "Daily summary",
129
+ "schedule": "0 9 * * *",
130
+ "spec": {
131
+ "systemPrompt": "You are a scheduled agent.",
132
+ "content": [{"type": "text", "message": "Summarize today."}],
133
+ },
134
+ }
135
+ )
136
+ await sdk.cronkit.run_task_now(cron_id=task["cronId"])
137
+ ```
138
+
139
+ CronKit 创建任务时会默认设置 `concurrency="skipIfRunning"`、`enabled=True` 和 `spec.timeoutSeconds=3600`。
140
+
141
+ ## ModelKit
142
+
143
+ ```python
144
+ async with AgentOSSDK() as sdk:
145
+ models = await sdk.modelkit.list_models()
146
+ chat_models = await sdk.modelkit.list_models_by_task("chat")
147
+
148
+ completion = await sdk.modelkit.chat.create(
149
+ {
150
+ "model": "qwen3-1.7b",
151
+ "messages": [{"role": "user", "content": "Hello"}],
152
+ "maxTokens": 128,
153
+ }
154
+ )
155
+
156
+ async for chunk in sdk.modelkit.chat.create_stream(
157
+ {"model": "qwen3-1.7b", "messages": [{"role": "user", "content": "Stream"}]}
158
+ ):
159
+ print(chunk)
160
+ ```
161
+
162
+ ModelKit 还支持:
163
+
164
+ - `sdk.modelkit.embedding.create(...)`
165
+ - `sdk.modelkit.asr.transcribe(...)`
166
+ - `sdk.modelkit.tts.synthesize(...)`
167
+ - `sdk.modelkit.tts.list_voices()`
168
+
169
+ ## ToolKit
170
+
171
+ ```python
172
+ async with AgentOSSDK() as sdk:
173
+ tools = await sdk.toolkit.list_tool()
174
+ definition = await sdk.toolkit.load_tool("tool-id")
175
+ raw_json = definition.to_json() if definition else None
176
+
177
+ async for event in sdk.toolkit.subscribe_tool_events("daemon-api-key"):
178
+ print(event)
179
+ ```
180
+
181
+ `load_tool()` 返回 `OpenToolDefinition` 包装对象,用于保留原始 JSON 定义。它不会执行工具,也不会实现浏览器或 daemon 的 OpenTool bridge。
182
+
183
+ ## 直接使用低层 Client
184
+
185
+ 低层 client 可用于显式 token 或自定义传输层场景:
186
+
187
+ ```python
188
+ from agentos_sdk.clients import AgentKitClient, CronKitClient, ModelKitClient
189
+ from agentos_sdk.transport import ApiClient
190
+
191
+ api = ApiClient(base_url="http://localhost:8888")
192
+ agentkit = AgentKitClient(api)
193
+ agent = await agentkit.get_agent("bearer-token", "agent-id")
194
+ ```
195
+
196
+ ## 开发验证
197
+
198
+ ```bash
199
+ .venv/bin/python -m compileall agentos_sdk
200
+ .venv/bin/python -m pytest -q
201
+ .venv/bin/ruff check .
202
+ ```
@@ -0,0 +1,202 @@
1
+ # AgentOS SDK for Python
2
+
3
+ Async Python SDK for AgentOS APIs. The package is a thin client over AgentOS HTTP and SSE endpoints with small compatibility helpers for bearer tokens, stream callbacks, Pythonic method names, and request defaults.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install agentos-sdk-python
9
+ ```
10
+
11
+ For local development:
12
+
13
+ ```bash
14
+ python3 -m venv .venv
15
+ .venv/bin/python -m pip install -e ".[dev]"
16
+ ```
17
+
18
+ ## Quickstart
19
+
20
+ ```python
21
+ from agentos_sdk import AgentOSSDK
22
+
23
+
24
+ async def main():
25
+ async with AgentOSSDK(base_url="http://localhost:8888") as sdk:
26
+ version = await sdk.agentos.get_version()
27
+ print(version)
28
+
29
+ await sdk.agentos.register_bundle(
30
+ {"bundleId": "com.demo.app", "appGroupId": "com.demo.group"}
31
+ )
32
+
33
+ tasks = await sdk.cronkit.list_tasks(limit=10)
34
+ print(tasks)
35
+ ```
36
+
37
+ `AgentOSSDK` also exposes TS-style camelCase aliases for common migration paths, such as `registerBundle`, `listTasks`, `chatSimple`, `listModels`, and `loadTool`.
38
+
39
+ ## Transport
40
+
41
+ The SDK uses `httpx.AsyncClient` and defaults to `http://localhost:8888`.
42
+
43
+ ```python
44
+ from agentos_sdk import AgentOSSDK
45
+
46
+ sdk = AgentOSSDK(
47
+ base_url="http://localhost:8888",
48
+ connect_timeout=5.0,
49
+ receive_timeout=10.0,
50
+ )
51
+ ```
52
+
53
+ Use `async with AgentOSSDK(...)` or call `await sdk.aclose()` when done.
54
+
55
+ ## Token Handling
56
+
57
+ `sdk.agentos.register_bundle(...)` stores the active app token. Protected facade methods in `sdk.agentkit` and `sdk.cronkit` use that token automatically.
58
+
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.
60
+
61
+ ## AgentOS Events
62
+
63
+ ```python
64
+ from agentos_sdk import AgentOSEventHandler, AgentOSSDK
65
+
66
+
67
+ class Handler(AgentOSEventHandler):
68
+ async def on_welcome(self, welcome):
69
+ print("welcome", welcome)
70
+
71
+ async def on_call_app(self, call):
72
+ print("call app", call)
73
+
74
+ async def on_done(self):
75
+ print("subscription ended")
76
+
77
+ async def on_error(self, error):
78
+ raise error
79
+
80
+
81
+ async with AgentOSSDK() as sdk:
82
+ await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
83
+ await sdk.agentos.subscribe(Handler())
84
+ ```
85
+
86
+ ## AgentKit
87
+
88
+ ```python
89
+ from agentos_sdk import AgentMessageHandler, AgentOSSDK, ToolReturn
90
+
91
+
92
+ class ChatHandler(AgentMessageHandler):
93
+ async def on_message(self, session_id, message):
94
+ print("message", session_id, message)
95
+
96
+ async def on_chunk(self, session_id, chunk):
97
+ print("chunk", session_id, chunk)
98
+
99
+ async def on_function_call(self, session_id, function_call):
100
+ return ToolReturn(function_call["id"], {"ok": True})
101
+
102
+ async def on_done(self):
103
+ print("done")
104
+
105
+ async def on_error(self, error):
106
+ raise error
107
+
108
+
109
+ async with AgentOSSDK() as sdk:
110
+ await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
111
+ session = await sdk.agentkit.init_session()
112
+ await sdk.agentkit.chat(
113
+ session,
114
+ {"content": [{"type": "text", "message": "Hello"}]},
115
+ ChatHandler(),
116
+ )
117
+ ```
118
+
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`.
120
+
121
+ ## CronKit
122
+
123
+ ```python
124
+ async with AgentOSSDK() as sdk:
125
+ await sdk.agentos.register_bundle({"bundleId": "com.demo.app"})
126
+ task = await sdk.cronkit.create_task(
127
+ request={
128
+ "name": "Daily summary",
129
+ "schedule": "0 9 * * *",
130
+ "spec": {
131
+ "systemPrompt": "You are a scheduled agent.",
132
+ "content": [{"type": "text", "message": "Summarize today."}],
133
+ },
134
+ }
135
+ )
136
+ await sdk.cronkit.run_task_now(cron_id=task["cronId"])
137
+ ```
138
+
139
+ CronKit create requests default `concurrency` to `skipIfRunning`, `enabled` to `True`, and `spec.timeoutSeconds` to `3600`.
140
+
141
+ ## ModelKit
142
+
143
+ ```python
144
+ async with AgentOSSDK() as sdk:
145
+ models = await sdk.modelkit.list_models()
146
+ chat_models = await sdk.modelkit.list_models_by_task("chat")
147
+
148
+ completion = await sdk.modelkit.chat.create(
149
+ {
150
+ "model": "qwen3-1.7b",
151
+ "messages": [{"role": "user", "content": "Hello"}],
152
+ "maxTokens": 128,
153
+ }
154
+ )
155
+
156
+ async for chunk in sdk.modelkit.chat.create_stream(
157
+ {"model": "qwen3-1.7b", "messages": [{"role": "user", "content": "Stream"}]}
158
+ ):
159
+ print(chunk)
160
+ ```
161
+
162
+ ModelKit also supports:
163
+
164
+ - `sdk.modelkit.embedding.create(...)`
165
+ - `sdk.modelkit.asr.transcribe(...)`
166
+ - `sdk.modelkit.tts.synthesize(...)`
167
+ - `sdk.modelkit.tts.list_voices()`
168
+
169
+ ## ToolKit
170
+
171
+ ```python
172
+ async with AgentOSSDK() as sdk:
173
+ tools = await sdk.toolkit.list_tool()
174
+ definition = await sdk.toolkit.load_tool("tool-id")
175
+ raw_json = definition.to_json() if definition else None
176
+
177
+ async for event in sdk.toolkit.subscribe_tool_events("daemon-api-key"):
178
+ print(event)
179
+ ```
180
+
181
+ `load_tool()` returns an `OpenToolDefinition` wrapper that preserves the raw JSON definition. It does not execute tools or implement browser/daemon OpenTool bridging.
182
+
183
+ ## Direct Clients
184
+
185
+ The low-level clients are available for explicit-token or custom transport usage:
186
+
187
+ ```python
188
+ from agentos_sdk.clients import AgentKitClient, CronKitClient, ModelKitClient
189
+ from agentos_sdk.transport import ApiClient
190
+
191
+ api = ApiClient(base_url="http://localhost:8888")
192
+ agentkit = AgentKitClient(api)
193
+ agent = await agentkit.get_agent("bearer-token", "agent-id")
194
+ ```
195
+
196
+ ## Development
197
+
198
+ ```bash
199
+ .venv/bin/python -m compileall agentos_sdk
200
+ .venv/bin/python -m pytest -q
201
+ .venv/bin/ruff check .
202
+ ```