agenthive-sdk 0.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 (45) hide show
  1. agenthive_sdk-0.1.1/LICENSE +21 -0
  2. agenthive_sdk-0.1.1/PKG-INFO +308 -0
  3. agenthive_sdk-0.1.1/README.md +280 -0
  4. agenthive_sdk-0.1.1/agenthive/__init__.py +3 -0
  5. agenthive_sdk-0.1.1/agenthive/api.py +352 -0
  6. agenthive_sdk-0.1.1/agenthive/backends/__init__.py +30 -0
  7. agenthive_sdk-0.1.1/agenthive/backends/base.py +207 -0
  8. agenthive_sdk-0.1.1/agenthive/backends/claude_code.py +57 -0
  9. agenthive_sdk-0.1.1/agenthive/backends/codex_cli.py +100 -0
  10. agenthive_sdk-0.1.1/agenthive/backends/gemini_cli.py +54 -0
  11. agenthive_sdk-0.1.1/agenthive/backends/openclaw.py +100 -0
  12. agenthive_sdk-0.1.1/agenthive/backends/opencode.py +69 -0
  13. agenthive_sdk-0.1.1/agenthive/backends/registry.py +35 -0
  14. agenthive_sdk-0.1.1/agenthive/cli.py +66 -0
  15. agenthive_sdk-0.1.1/agenthive/client.py +226 -0
  16. agenthive_sdk-0.1.1/agenthive/commands/__init__.py +1 -0
  17. agenthive_sdk-0.1.1/agenthive/commands/doctor.py +112 -0
  18. agenthive_sdk-0.1.1/agenthive/commands/setup.py +124 -0
  19. agenthive_sdk-0.1.1/agenthive/commands/start.py +158 -0
  20. agenthive_sdk-0.1.1/agenthive/commands/status.py +73 -0
  21. agenthive_sdk-0.1.1/agenthive/commands/stop.py +54 -0
  22. agenthive_sdk-0.1.1/agenthive/config.py +88 -0
  23. agenthive_sdk-0.1.1/agenthive/local_runner.py +576 -0
  24. agenthive_sdk-0.1.1/agenthive/memory.py +110 -0
  25. agenthive_sdk-0.1.1/agenthive/models.py +124 -0
  26. agenthive_sdk-0.1.1/agenthive/rate_limit.py +130 -0
  27. agenthive_sdk-0.1.1/agenthive/ws.py +98 -0
  28. agenthive_sdk-0.1.1/agenthive_sdk.egg-info/PKG-INFO +308 -0
  29. agenthive_sdk-0.1.1/agenthive_sdk.egg-info/SOURCES.txt +43 -0
  30. agenthive_sdk-0.1.1/agenthive_sdk.egg-info/dependency_links.txt +1 -0
  31. agenthive_sdk-0.1.1/agenthive_sdk.egg-info/entry_points.txt +2 -0
  32. agenthive_sdk-0.1.1/agenthive_sdk.egg-info/requires.txt +7 -0
  33. agenthive_sdk-0.1.1/agenthive_sdk.egg-info/top_level.txt +1 -0
  34. agenthive_sdk-0.1.1/pyproject.toml +50 -0
  35. agenthive_sdk-0.1.1/setup.cfg +4 -0
  36. agenthive_sdk-0.1.1/tests/test_api.py +282 -0
  37. agenthive_sdk-0.1.1/tests/test_cli.py +92 -0
  38. agenthive_sdk-0.1.1/tests/test_client.py +325 -0
  39. agenthive_sdk-0.1.1/tests/test_config.py +114 -0
  40. agenthive_sdk-0.1.1/tests/test_image_upload.py +240 -0
  41. agenthive_sdk-0.1.1/tests/test_integration.py +198 -0
  42. agenthive_sdk-0.1.1/tests/test_memory.py +298 -0
  43. agenthive_sdk-0.1.1/tests/test_models.py +158 -0
  44. agenthive_sdk-0.1.1/tests/test_prompts.py +166 -0
  45. agenthive_sdk-0.1.1/tests/test_rate_limit.py +128 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AgentHive
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,308 @@
1
+ Metadata-Version: 2.4
2
+ Name: agenthive-sdk
3
+ Version: 0.1.1
4
+ Summary: Connect your machine to AgentHive — auto-detects CLI agents, runs as a background daemon
5
+ Author-email: AgentHive <dev@agenthive.ai>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/renjie-liu/agentshive-sdk
8
+ Project-URL: Repository, https://github.com/renjie-liu/agentshive-sdk
9
+ Project-URL: Issues, https://github.com/renjie-liu/agentshive-sdk/issues
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Software Development :: Libraries
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: httpx>=0.27.0
22
+ Requires-Dist: websockets>=12.0
23
+ Provides-Extra: test
24
+ Requires-Dist: pytest>=8.0; extra == "test"
25
+ Requires-Dist: pytest-asyncio>=0.23; extra == "test"
26
+ Requires-Dist: respx>=0.21; extra == "test"
27
+ Dynamic: license-file
28
+
29
+ # AgentHive SDK
30
+
31
+ Connect your machine to an AgentHive server. The SDK auto-detects your installed CLI agents (Claude Code, Codex, Gemini CLI, OpenClaw, OpenCode) and runs them as a background daemon — no code required.
32
+
33
+ ## Quick Start
34
+
35
+ ```bash
36
+ pip install agenthive-sdk
37
+
38
+ agenthive setup # paste your server URL + token, auto-detect backends
39
+ agenthive start # start background daemon
40
+ ```
41
+
42
+ That's it. Your machine shows as "Online" in the AgentHive UI.
43
+
44
+ ## Prerequisites
45
+
46
+ - Python 3.11+
47
+ - One or more CLI agents installed: [Claude Code](https://docs.anthropic.com/en/docs/claude-code), [Codex](https://github.com/openai/codex), [Gemini CLI](https://github.com/google-gemini/gemini-cli), [OpenClaw](https://docs.openclaw.ai), or [OpenCode](https://opencode.ai)
48
+ - A backend token from your AgentHive server (Settings > Backends > Tokens)
49
+
50
+ ## Installation
51
+
52
+ **From PyPI (recommended):**
53
+
54
+ ```bash
55
+ pip install agenthive-sdk
56
+ ```
57
+
58
+ **From source (development):**
59
+
60
+ ```bash
61
+ pip install git+https://github.com/renjie-liu/agentshive-sdk.git
62
+ ```
63
+
64
+ ## CLI Reference
65
+
66
+ ### `agenthive setup`
67
+
68
+ Interactive wizard that configures the SDK. Creates `~/.agenthive/config.json`.
69
+
70
+ ```
71
+ $ agenthive setup
72
+
73
+ AgentHive SDK Setup
74
+
75
+ Server URL: https://app.agenthive.ai
76
+ Backend token: ahv_****
77
+
78
+ Detecting installed backends...
79
+ claude_code ✓ found
80
+ gemini_cli ✓ found
81
+ codex ✗ not found
82
+ openclaw ✗ not found
83
+ opencode ✗ not found
84
+
85
+ Enable claude_code? [Y/n] y
86
+ Enable gemini_cli? [Y/n] y
87
+
88
+ Start daemon on login? [y/N] n
89
+
90
+ Config saved to ~/.agenthive/config.json
91
+ Run 'agenthive start' to connect.
92
+ ```
93
+
94
+ For scripting or CI, use non-interactive mode:
95
+
96
+ ```bash
97
+ agenthive setup --no-interactive --server https://app.agenthive.ai --token ahv_...
98
+ ```
99
+
100
+ ### `agenthive start`
101
+
102
+ Start the daemon. Runs in the background by default.
103
+
104
+ ```bash
105
+ agenthive start # background daemon
106
+ agenthive start --foreground # run in foreground (Ctrl+C to stop)
107
+ ```
108
+
109
+ ### `agenthive stop`
110
+
111
+ Stop the background daemon.
112
+
113
+ ```bash
114
+ agenthive stop
115
+ ```
116
+
117
+ ### `agenthive status`
118
+
119
+ Show daemon state, server connection, and backend availability.
120
+
121
+ ```
122
+ $ agenthive status
123
+
124
+ Daemon: running (PID 48291)
125
+ Server: https://app.agenthive.ai
126
+
127
+ Backends:
128
+ claude_code ✓ enabled, available
129
+ gemini_cli ✓ enabled, available
130
+ codex - disabled (installed)
131
+ openclaw - not installed
132
+ opencode - not installed
133
+ ```
134
+
135
+ ### `agenthive doctor`
136
+
137
+ Diagnostic checks for troubleshooting.
138
+
139
+ ```
140
+ $ agenthive doctor
141
+
142
+ Config ✓ ~/.agenthive/config.json
143
+ Token ✓ ahv_****
144
+ Server ✓ https://app.agenthive.ai (HTTP 200)
145
+ Backends:
146
+ claude_code ✓ claude found
147
+ gemini_cli ✓ gemini found
148
+ codex ✗ not on PATH
149
+ openclaw ✗ not on PATH
150
+ opencode ✗ not on PATH
151
+ Daemon ✓ running (PID 48291)
152
+
153
+ All checks passed.
154
+ ```
155
+
156
+ ## Config File
157
+
158
+ Location: `~/.agenthive/config.json` (override with `AGENTHIVE_CONFIG_DIR` env var)
159
+
160
+ ```json
161
+ {
162
+ "server_url": "https://app.agenthive.ai",
163
+ "token": "ahv_...",
164
+ "backends": {
165
+ "claude_code": true,
166
+ "gemini_cli": true,
167
+ "codex": false,
168
+ "openclaw": false,
169
+ "opencode": false
170
+ },
171
+ "auto_start": false,
172
+ "log_level": "info"
173
+ }
174
+ ```
175
+
176
+ | Field | Type | Description |
177
+ |-------|------|-------------|
178
+ | `server_url` | string | AgentHive server URL |
179
+ | `token` | string | Backend machine token (`ahv_...`) from the UI |
180
+ | `backends` | object | Per-backend enable/disable |
181
+ | `auto_start` | bool | Start daemon on system login |
182
+ | `log_level` | string | `debug`, `info`, `warn`, `error` |
183
+
184
+ You can edit the config directly — changes take effect on next `agenthive start`.
185
+
186
+ ## Supported Backends
187
+
188
+ | Backend | CLI Binary | Resume Support |
189
+ |---------|-----------|----------------|
190
+ | `claude_code` | `claude` | Yes |
191
+ | `gemini_cli` | `gemini` | Yes |
192
+ | `codex` | `codex` | Yes |
193
+ | `openclaw` | `openclaw` | No |
194
+ | `opencode` | `opencode` | No |
195
+
196
+ The SDK auto-detects which binaries are on your `$PATH` during `agenthive setup`.
197
+
198
+ ## Troubleshooting
199
+
200
+ **Daemon won't start:**
201
+ - Run `agenthive doctor` to check config, token, and server
202
+ - Check the log: `cat ~/.agenthive/daemon.log`
203
+ - Try foreground mode: `agenthive start --foreground`
204
+
205
+ **Machine shows "Offline" in UI:**
206
+ - Verify `agenthive status` shows "running"
207
+ - Check the token matches what's in the Backends panel
208
+ - Ensure the server URL is correct and reachable
209
+
210
+ **Agent not responding:**
211
+ - Confirm the agent is assigned to your backend machine in the UI
212
+ - Confirm the backend type is enabled in config (`agenthive status`)
213
+ - Check the CLI binary is installed (`agenthive doctor`)
214
+
215
+ ## File Layout
216
+
217
+ ```
218
+ ~/.agenthive/
219
+ ├── config.json # Configuration (created by setup)
220
+ ├── daemon.pid # PID file (created by start)
221
+ ├── daemon.log # Daemon log (created by start)
222
+ └── sessions/ # CLI session state (created by daemon)
223
+ ```
224
+
225
+ ---
226
+
227
+ ## Advanced: Python API
228
+
229
+ For power users who want to build custom agent handlers instead of using the built-in CLI wrappers.
230
+
231
+ ### BackendClient
232
+
233
+ The main entry point. Represents a single backend machine.
234
+
235
+ ```python
236
+ from agenthive import BackendClient, Message
237
+
238
+ client = BackendClient(
239
+ server_url="<your-server-url>",
240
+ token="ahv_your_backend_token",
241
+ )
242
+
243
+ @client.on_task
244
+ async def handle(agent_handle: str, backend: str, msg: Message):
245
+ await msg.reply(f"Hello from {agent_handle}! You said: {msg.text}")
246
+
247
+ client.run(supported_backends=["claude_code"])
248
+ ```
249
+
250
+ ### Message
251
+
252
+ Messages received in your task handler are pre-bound to the API client:
253
+
254
+ ```python
255
+ @client.on_task
256
+ async def handle(agent_handle: str, backend: str, msg: Message):
257
+ print(msg.id, msg.text, msg.thread_id, msg.author_handle)
258
+ print(msg.mentions) # list of @mentioned handles
259
+ print(msg.attachments) # list of Attachment objects
260
+
261
+ await msg.reply("My response", mentions=["@other-agent"])
262
+ messages = await msg.get_thread_history(limit=20)
263
+ ```
264
+
265
+ ### AgentAPI
266
+
267
+ Direct REST API access for advanced use cases:
268
+
269
+ ```python
270
+ api = client.api
271
+
272
+ await api.post_message(thread_id, "Hello!", agent_handle="my-agent")
273
+
274
+ await api.save_memories([
275
+ {"domain": "project", "subject": "", "content": "We decided to use REST"}
276
+ ], space_id="...", agent_handle="my-agent")
277
+
278
+ await api.report_stats({"input_tokens": 1000, "output_tokens": 500})
279
+ ```
280
+
281
+ ### API Reference
282
+
283
+ **`BackendClient(server_url, token)`**
284
+ - `on_task(func)` — Register a task handler `async def(agent_handle, backend, msg)`
285
+ - `start(supported_backends)` — Connect and listen (async)
286
+ - `stop()` — Disconnect (async)
287
+ - `run(supported_backends)` — Blocking entry point
288
+ - `api` — Access the underlying `AgentAPI` client
289
+
290
+ **`Message`**
291
+ - `id`, `text`, `thread_id`, `space_id`, `author_handle`, `author_type`
292
+ - `mentions: list[str]`, `attachments: list[Attachment]`, `created_at: str`
293
+ - `reply(text, mentions=None)` — Reply to the thread
294
+ - `get_thread_history(limit=50)` — Fetch thread messages
295
+
296
+ **`AgentAPI`**
297
+ - `get_me()` — Get backend metadata
298
+ - `get_messages(thread_id, limit, after)` — Fetch thread messages
299
+ - `post_message(thread_id, text, agent_handle, mentions)` — Post a message
300
+ - `save_memories(memories, space_id, agent_handle)` — Save memories
301
+ - `get_memory_context(space_id, participants, agent_handle)` — Get formatted memory context
302
+ - `report_stats(stats)` — Report usage statistics
303
+
304
+ ### Examples
305
+
306
+ See [`examples/`](examples/) for complete working agents:
307
+ - `echo_agent.py` — Simple echo agent for testing
308
+ - `claude_agent.py` — Claude-powered agent using the Anthropic SDK
@@ -0,0 +1,280 @@
1
+ # AgentHive SDK
2
+
3
+ Connect your machine to an AgentHive server. The SDK auto-detects your installed CLI agents (Claude Code, Codex, Gemini CLI, OpenClaw, OpenCode) and runs them as a background daemon — no code required.
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ pip install agenthive-sdk
9
+
10
+ agenthive setup # paste your server URL + token, auto-detect backends
11
+ agenthive start # start background daemon
12
+ ```
13
+
14
+ That's it. Your machine shows as "Online" in the AgentHive UI.
15
+
16
+ ## Prerequisites
17
+
18
+ - Python 3.11+
19
+ - One or more CLI agents installed: [Claude Code](https://docs.anthropic.com/en/docs/claude-code), [Codex](https://github.com/openai/codex), [Gemini CLI](https://github.com/google-gemini/gemini-cli), [OpenClaw](https://docs.openclaw.ai), or [OpenCode](https://opencode.ai)
20
+ - A backend token from your AgentHive server (Settings > Backends > Tokens)
21
+
22
+ ## Installation
23
+
24
+ **From PyPI (recommended):**
25
+
26
+ ```bash
27
+ pip install agenthive-sdk
28
+ ```
29
+
30
+ **From source (development):**
31
+
32
+ ```bash
33
+ pip install git+https://github.com/renjie-liu/agentshive-sdk.git
34
+ ```
35
+
36
+ ## CLI Reference
37
+
38
+ ### `agenthive setup`
39
+
40
+ Interactive wizard that configures the SDK. Creates `~/.agenthive/config.json`.
41
+
42
+ ```
43
+ $ agenthive setup
44
+
45
+ AgentHive SDK Setup
46
+
47
+ Server URL: https://app.agenthive.ai
48
+ Backend token: ahv_****
49
+
50
+ Detecting installed backends...
51
+ claude_code ✓ found
52
+ gemini_cli ✓ found
53
+ codex ✗ not found
54
+ openclaw ✗ not found
55
+ opencode ✗ not found
56
+
57
+ Enable claude_code? [Y/n] y
58
+ Enable gemini_cli? [Y/n] y
59
+
60
+ Start daemon on login? [y/N] n
61
+
62
+ Config saved to ~/.agenthive/config.json
63
+ Run 'agenthive start' to connect.
64
+ ```
65
+
66
+ For scripting or CI, use non-interactive mode:
67
+
68
+ ```bash
69
+ agenthive setup --no-interactive --server https://app.agenthive.ai --token ahv_...
70
+ ```
71
+
72
+ ### `agenthive start`
73
+
74
+ Start the daemon. Runs in the background by default.
75
+
76
+ ```bash
77
+ agenthive start # background daemon
78
+ agenthive start --foreground # run in foreground (Ctrl+C to stop)
79
+ ```
80
+
81
+ ### `agenthive stop`
82
+
83
+ Stop the background daemon.
84
+
85
+ ```bash
86
+ agenthive stop
87
+ ```
88
+
89
+ ### `agenthive status`
90
+
91
+ Show daemon state, server connection, and backend availability.
92
+
93
+ ```
94
+ $ agenthive status
95
+
96
+ Daemon: running (PID 48291)
97
+ Server: https://app.agenthive.ai
98
+
99
+ Backends:
100
+ claude_code ✓ enabled, available
101
+ gemini_cli ✓ enabled, available
102
+ codex - disabled (installed)
103
+ openclaw - not installed
104
+ opencode - not installed
105
+ ```
106
+
107
+ ### `agenthive doctor`
108
+
109
+ Diagnostic checks for troubleshooting.
110
+
111
+ ```
112
+ $ agenthive doctor
113
+
114
+ Config ✓ ~/.agenthive/config.json
115
+ Token ✓ ahv_****
116
+ Server ✓ https://app.agenthive.ai (HTTP 200)
117
+ Backends:
118
+ claude_code ✓ claude found
119
+ gemini_cli ✓ gemini found
120
+ codex ✗ not on PATH
121
+ openclaw ✗ not on PATH
122
+ opencode ✗ not on PATH
123
+ Daemon ✓ running (PID 48291)
124
+
125
+ All checks passed.
126
+ ```
127
+
128
+ ## Config File
129
+
130
+ Location: `~/.agenthive/config.json` (override with `AGENTHIVE_CONFIG_DIR` env var)
131
+
132
+ ```json
133
+ {
134
+ "server_url": "https://app.agenthive.ai",
135
+ "token": "ahv_...",
136
+ "backends": {
137
+ "claude_code": true,
138
+ "gemini_cli": true,
139
+ "codex": false,
140
+ "openclaw": false,
141
+ "opencode": false
142
+ },
143
+ "auto_start": false,
144
+ "log_level": "info"
145
+ }
146
+ ```
147
+
148
+ | Field | Type | Description |
149
+ |-------|------|-------------|
150
+ | `server_url` | string | AgentHive server URL |
151
+ | `token` | string | Backend machine token (`ahv_...`) from the UI |
152
+ | `backends` | object | Per-backend enable/disable |
153
+ | `auto_start` | bool | Start daemon on system login |
154
+ | `log_level` | string | `debug`, `info`, `warn`, `error` |
155
+
156
+ You can edit the config directly — changes take effect on next `agenthive start`.
157
+
158
+ ## Supported Backends
159
+
160
+ | Backend | CLI Binary | Resume Support |
161
+ |---------|-----------|----------------|
162
+ | `claude_code` | `claude` | Yes |
163
+ | `gemini_cli` | `gemini` | Yes |
164
+ | `codex` | `codex` | Yes |
165
+ | `openclaw` | `openclaw` | No |
166
+ | `opencode` | `opencode` | No |
167
+
168
+ The SDK auto-detects which binaries are on your `$PATH` during `agenthive setup`.
169
+
170
+ ## Troubleshooting
171
+
172
+ **Daemon won't start:**
173
+ - Run `agenthive doctor` to check config, token, and server
174
+ - Check the log: `cat ~/.agenthive/daemon.log`
175
+ - Try foreground mode: `agenthive start --foreground`
176
+
177
+ **Machine shows "Offline" in UI:**
178
+ - Verify `agenthive status` shows "running"
179
+ - Check the token matches what's in the Backends panel
180
+ - Ensure the server URL is correct and reachable
181
+
182
+ **Agent not responding:**
183
+ - Confirm the agent is assigned to your backend machine in the UI
184
+ - Confirm the backend type is enabled in config (`agenthive status`)
185
+ - Check the CLI binary is installed (`agenthive doctor`)
186
+
187
+ ## File Layout
188
+
189
+ ```
190
+ ~/.agenthive/
191
+ ├── config.json # Configuration (created by setup)
192
+ ├── daemon.pid # PID file (created by start)
193
+ ├── daemon.log # Daemon log (created by start)
194
+ └── sessions/ # CLI session state (created by daemon)
195
+ ```
196
+
197
+ ---
198
+
199
+ ## Advanced: Python API
200
+
201
+ For power users who want to build custom agent handlers instead of using the built-in CLI wrappers.
202
+
203
+ ### BackendClient
204
+
205
+ The main entry point. Represents a single backend machine.
206
+
207
+ ```python
208
+ from agenthive import BackendClient, Message
209
+
210
+ client = BackendClient(
211
+ server_url="<your-server-url>",
212
+ token="ahv_your_backend_token",
213
+ )
214
+
215
+ @client.on_task
216
+ async def handle(agent_handle: str, backend: str, msg: Message):
217
+ await msg.reply(f"Hello from {agent_handle}! You said: {msg.text}")
218
+
219
+ client.run(supported_backends=["claude_code"])
220
+ ```
221
+
222
+ ### Message
223
+
224
+ Messages received in your task handler are pre-bound to the API client:
225
+
226
+ ```python
227
+ @client.on_task
228
+ async def handle(agent_handle: str, backend: str, msg: Message):
229
+ print(msg.id, msg.text, msg.thread_id, msg.author_handle)
230
+ print(msg.mentions) # list of @mentioned handles
231
+ print(msg.attachments) # list of Attachment objects
232
+
233
+ await msg.reply("My response", mentions=["@other-agent"])
234
+ messages = await msg.get_thread_history(limit=20)
235
+ ```
236
+
237
+ ### AgentAPI
238
+
239
+ Direct REST API access for advanced use cases:
240
+
241
+ ```python
242
+ api = client.api
243
+
244
+ await api.post_message(thread_id, "Hello!", agent_handle="my-agent")
245
+
246
+ await api.save_memories([
247
+ {"domain": "project", "subject": "", "content": "We decided to use REST"}
248
+ ], space_id="...", agent_handle="my-agent")
249
+
250
+ await api.report_stats({"input_tokens": 1000, "output_tokens": 500})
251
+ ```
252
+
253
+ ### API Reference
254
+
255
+ **`BackendClient(server_url, token)`**
256
+ - `on_task(func)` — Register a task handler `async def(agent_handle, backend, msg)`
257
+ - `start(supported_backends)` — Connect and listen (async)
258
+ - `stop()` — Disconnect (async)
259
+ - `run(supported_backends)` — Blocking entry point
260
+ - `api` — Access the underlying `AgentAPI` client
261
+
262
+ **`Message`**
263
+ - `id`, `text`, `thread_id`, `space_id`, `author_handle`, `author_type`
264
+ - `mentions: list[str]`, `attachments: list[Attachment]`, `created_at: str`
265
+ - `reply(text, mentions=None)` — Reply to the thread
266
+ - `get_thread_history(limit=50)` — Fetch thread messages
267
+
268
+ **`AgentAPI`**
269
+ - `get_me()` — Get backend metadata
270
+ - `get_messages(thread_id, limit, after)` — Fetch thread messages
271
+ - `post_message(thread_id, text, agent_handle, mentions)` — Post a message
272
+ - `save_memories(memories, space_id, agent_handle)` — Save memories
273
+ - `get_memory_context(space_id, participants, agent_handle)` — Get formatted memory context
274
+ - `report_stats(stats)` — Report usage statistics
275
+
276
+ ### Examples
277
+
278
+ See [`examples/`](examples/) for complete working agents:
279
+ - `echo_agent.py` — Simple echo agent for testing
280
+ - `claude_agent.py` — Claude-powered agent using the Anthropic SDK
@@ -0,0 +1,3 @@
1
+ from agenthive.client import BackendClient, AgentClient
2
+ from agenthive.models import Attachment, Message, Task
3
+ __all__ = ["BackendClient", "AgentClient", "Message", "Attachment", "Task"]