agents-bus 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.
- agents_bus-0.2.0/LICENSE +21 -0
- agents_bus-0.2.0/PKG-INFO +232 -0
- agents_bus-0.2.0/README.md +216 -0
- agents_bus-0.2.0/pyproject.toml +30 -0
- agents_bus-0.2.0/setup.cfg +4 -0
- agents_bus-0.2.0/src/agent_bus/__init__.py +3 -0
- agents_bus-0.2.0/src/agent_bus/cli.py +570 -0
- agents_bus-0.2.0/src/agent_bus/gate.py +30 -0
- agents_bus-0.2.0/src/agent_bus/mcp_server.py +186 -0
- agents_bus-0.2.0/src/agent_bus/remote.py +86 -0
- agents_bus-0.2.0/src/agent_bus/sandbox.py +126 -0
- agents_bus-0.2.0/src/agent_bus/store.py +212 -0
- agents_bus-0.2.0/src/agents_bus.egg-info/PKG-INFO +232 -0
- agents_bus-0.2.0/src/agents_bus.egg-info/SOURCES.txt +20 -0
- agents_bus-0.2.0/src/agents_bus.egg-info/dependency_links.txt +1 -0
- agents_bus-0.2.0/src/agents_bus.egg-info/entry_points.txt +4 -0
- agents_bus-0.2.0/src/agents_bus.egg-info/top_level.txt +1 -0
- agents_bus-0.2.0/tests/test_remote.py +62 -0
- agents_bus-0.2.0/tests/test_runtime.py +21 -0
- agents_bus-0.2.0/tests/test_sandbox.py +93 -0
- agents_bus-0.2.0/tests/test_store.py +103 -0
- agents_bus-0.2.0/tests/test_workdir.py +33 -0
agents_bus-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SwooshXuan
|
|
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,232 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: agents-bus
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A tiny, SSH-native, human-readable task mailbox for cross-machine AI agents
|
|
5
|
+
Author: SwooshXuan
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/swooshxuan/agent-bus
|
|
8
|
+
Keywords: ai-agents,claude-code,mcp,orchestration,ssh,nat
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Topic :: System :: Distributed Computing
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
|
|
17
|
+
# agent-bus
|
|
18
|
+
|
|
19
|
+
[](https://github.com/swooshxuan/agent-bus/actions/workflows/ci.yml)
|
|
20
|
+
[](LICENSE)
|
|
21
|
+
[](pyproject.toml)
|
|
22
|
+
|
|
23
|
+
> 给多台机器上的 AI agent 用的任务信箱:**SSH 为传输,文件为存储,人类可读**。
|
|
24
|
+
>
|
|
25
|
+
> A tiny, SSH-native, human-readable task mailbox for cross-machine AI agents.
|
|
26
|
+
|
|
27
|
+
不用装 NATS、不用 Kubernetes、不用开公网端口。两台在内网/NAT 后面的机器,
|
|
28
|
+
各放一把受限 SSH 公钥,就能互相派任务、收结果。
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
┌────────────── 信箱(files + SSH)──────────────┐
|
|
32
|
+
laptop ──→│ tasks/laptop/ tasks/lab/ results/<id>.json │←── lab
|
|
33
|
+
agent └────────────────────────────────────────────────┘ agent
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 为什么
|
|
37
|
+
|
|
38
|
+
现有的多智能体编排方案大多假设:公网可达、有消息中间件、有容器编排。
|
|
39
|
+
但个人/实验室的常态是:笔记本在移动宽带 CGNAT 后面、服务器在校园网后面、
|
|
40
|
+
你想让它们上面的 Claude Code / Codex / 脚本协作一次。
|
|
41
|
+
|
|
42
|
+
agent-bus 做减法:
|
|
43
|
+
|
|
44
|
+
- **零依赖**:纯 Python 标准库,一个文件级队列
|
|
45
|
+
- **NAT 友好**:复用你已经有的 SSH(或 frp/ngrok 隧道)
|
|
46
|
+
- **人类可读**:任务是 JSON 文件,`ls` / `jq` / `git` 都能用
|
|
47
|
+
- **最小权限**:worker 的公钥被 `command=` 钉死,只能执行 `agent-bus`
|
|
48
|
+
- **agent 无关**:Claude Code、Codex、Aider、任意 CLI 都能当 worker
|
|
49
|
+
|
|
50
|
+
> 完整使用手册(配置、任务模板、多机协作、排错)见 **[docs/usage.md](docs/usage.md)**。
|
|
51
|
+
|
|
52
|
+
## 快速开始
|
|
53
|
+
|
|
54
|
+
### 1. 安装(在信箱主机和每台 worker 上)
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install agents-bus # 或 pip install -e .(命令仍是 agent-bus)
|
|
58
|
+
agent-bus --help
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 2. 信箱主机:准备目录和受限入口
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
export AGENT_BUS_DIR=/srv/agent-bus # 建议写进 ~/.bashrc
|
|
65
|
+
agent-bus list
|
|
66
|
+
|
|
67
|
+
# 把本机的 agent-bus-gate 写成受限命令(每台 worker 的公钥一行)
|
|
68
|
+
echo 'command="agent-bus-gate",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-ed25519 AAAA... lab-worker' \
|
|
69
|
+
>> ~/.ssh/authorized_keys
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
> 也可以用 `--base` 参数指定目录,等价于 `AGENT_BUS_DIR`。
|
|
73
|
+
|
|
74
|
+
### 3. Worker:起一个循环
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# 轮询本机任务,用 Claude Code headless 执行,结果自动回传
|
|
78
|
+
agent-bus work --me lab --dir ~/agent-work --poll 20 -- \
|
|
79
|
+
--dangerously-skip-permissions --max-turns 30
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
或交给 systemd(见 `examples/agent-worker.service`),开机自动挂。
|
|
83
|
+
|
|
84
|
+
### 4. 投递与查看
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# 从任何一台机器派活(经受限 SSH)
|
|
88
|
+
ssh -i ~/.ssh/agentbus bus-host "agent-bus send lab '汇总 CSV' --body '把 data/ 下的 CSV 汇总成 report.md'"
|
|
89
|
+
|
|
90
|
+
# 看任务 / 结果
|
|
91
|
+
ssh -i ~/.ssh/agentbus bus-host "agent-bus tasks lab"
|
|
92
|
+
ssh -i ~/.ssh/agentbus bus-host "agent-bus result <id>"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 远程模式(推荐:机器只出站)
|
|
96
|
+
|
|
97
|
+
worker 机器不需要同步信箱,直接通过受限 SSH 访问信箱主机:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
export AGENT_BUS_REMOTE=ubuntu@bus-host # 信箱主机
|
|
101
|
+
export AGENT_BUS_SSH_KEY=~/.ssh/agentbus # 受限密钥
|
|
102
|
+
agent-bus tasks lab # 等价于 ssh 过去执行
|
|
103
|
+
agent-bus work --me lab --dir ~/agent-work # worker 也走远程
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
MCP 同理:`AGENT_BUS_REMOTE=... claude mcp add agent-bus -- agent-bus-mcp`。
|
|
107
|
+
|
|
108
|
+
## 任务模板(推荐)
|
|
109
|
+
|
|
110
|
+
任务正文按统一结构写,任何 agent 都能读懂,能显著减少「自由发挥」:
|
|
111
|
+
|
|
112
|
+
```text
|
|
113
|
+
@workdir: /home/you/project # 可选;必须是第一行,worker 会 cd 到这里
|
|
114
|
+
# 任务
|
|
115
|
+
把 data/ 下的 CSV 汇总成 report.md
|
|
116
|
+
# 验收标准
|
|
117
|
+
- report.md 存在,包含所有 CSV 的汇总
|
|
118
|
+
- 用中文
|
|
119
|
+
# 背景 / 约束
|
|
120
|
+
- 不要修改原始数据
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- `@workdir` 只对用 `agent-bus work` 的 worker 生效;不写就用 worker 的 `--dir`
|
|
124
|
+
- 验收标准是写给执行任务的 agent 看的 —— 它会据此自检
|
|
125
|
+
- 示例见 `examples/task-template.md`
|
|
126
|
+
|
|
127
|
+
## 自检与后台运行
|
|
128
|
+
|
|
129
|
+
接入新机器时先跑一次自检,它会逐项检查:模式(本地/远程)、Python、SSH 客户端、密钥、信箱可达性、Claude、作业目录。
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
agent-bus --remote ubuntu@bus-host --remote-key ~/.ssh/agentbus \
|
|
133
|
+
doctor --me lab --dir ~/agent-work
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
每项输出 `PASS` / `WARN` / `FAIL`,最后一行是 `RESULT: OK` 或 `FAILED`(有 FAIL 时退出码非 0)。
|
|
137
|
+
|
|
138
|
+
后台运行(关闭终端也不停):
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
agent-bus --remote ubuntu@bus-host --remote-key ~/.ssh/agentbus \
|
|
142
|
+
work --me lab --detach
|
|
143
|
+
agent-bus status --me lab # RUNNING/STOPPED + 最近日志
|
|
144
|
+
agent-bus stop --me lab
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
日志默认写到 `~/.agent-bus/worker/<me>.log`(`--log` 可改)。
|
|
148
|
+
worker 启动时第一行会打印 `mode: REMOTE ...` 或 `mode: LOCAL ...` —— 本地模式会额外警告「任务不会发往远端」。
|
|
149
|
+
|
|
150
|
+
## 沙箱(v0.2)
|
|
151
|
+
|
|
152
|
+
`work` 默认 `--sandbox auto`:**git 仓库自动使用 worktree**(每个任务一个独立副本,结果里带 diff 统计),非 git 目录退回 `none` 并打印警告。
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
agent-bus work --me lab --dir ~/project # auto → worktree
|
|
156
|
+
agent-bus work --me lab --dir ~/project --sandbox docker # 容器隔离
|
|
157
|
+
agent-bus work --me lab --dir ~/project --sandbox none # 旧行为
|
|
158
|
+
agent-bus work --me lab --dir ~/project --keep-worktrees # 保留 worktree 供检查
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
docker 档位先构建镜像:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
docker build -t agent-bus-worker sandbox/
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
容器只挂载作业目录,凭证通过环境变量传入(`ANTHROPIC_API_KEY` 等),**不挂载 home**。
|
|
168
|
+
安全档位由 worker 决定,任务正文里的 `@sandbox:` 指令会被忽略。
|
|
169
|
+
|
|
170
|
+
## 可靠性
|
|
171
|
+
|
|
172
|
+
- worker 轮询遇网络错误会指数退避重试(5s → 120s),不会退出
|
|
173
|
+
- 结果超过 `AGENT_BUS_MAX_RESULT`(默认 100KB)会截断
|
|
174
|
+
- 执行中崩溃的任务会停留在 `running`:`agent-bus reap --me lab --older 60` 回收
|
|
175
|
+
|
|
176
|
+
安全模型和加固建议见 [SECURITY.md](SECURITY.md)。
|
|
177
|
+
|
|
178
|
+
## 命令参考
|
|
179
|
+
|
|
180
|
+
| 命令 | 说明 |
|
|
181
|
+
|---|---|
|
|
182
|
+
| `agent-bus send <target> <title> [--from N] [--body B]` | 投递任务(body 缺省从 stdin 读),打印任务 id |
|
|
183
|
+
| `agent-bus tasks <me> [--all]` | 列出待办 |
|
|
184
|
+
| `agent-bus claim <me> <id>` | 原子认领(并发安全) |
|
|
185
|
+
| `agent-bus done <me> <id> [--status ok\|fail]` | 提交结果(缺省从 stdin 读) |
|
|
186
|
+
| `agent-bus requeue <me> <id>` | 把卡住的任务重置为 pending |
|
|
187
|
+
| `agent-bus reap <me> [--older 60]` | 回收超时未完成的任务 |
|
|
188
|
+
| `agent-bus show <id>` / `result <id>` | 查看详情 / 结果 |
|
|
189
|
+
| `agent-bus list` | 总览 |
|
|
190
|
+
| `agent-bus doctor [--me N] [--dir D]` | 环境自检 |
|
|
191
|
+
| `agent-bus work --me N --dir D [--sandbox auto\|none\|worktree\|docker] [--detach] [--log F]` | worker 循环(可后台、可沙箱) |
|
|
192
|
+
| `agent-bus status --me N` / `stop --me N` | 后台 worker 状态 / 停止 |
|
|
193
|
+
|
|
194
|
+
## 接入 Claude Code(MCP)
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
claude mcp add agent-bus -- agent-bus-mcp
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
之后 Claude 就能直接调用 `send_task` / `list_tasks` / `complete_task` / `get_result`
|
|
201
|
+
等工具,不需要记命令行。
|
|
202
|
+
|
|
203
|
+
## 安全模型
|
|
204
|
+
|
|
205
|
+
- worker 公钥在信箱主机上被 `command="agent-bus-gate"` 约束,**不能开 shell、不能端口转发**。
|
|
206
|
+
- 信箱目录就是权限边界:能写 `tasks/<me>/` 等于能让 `<me>` 执行任务。
|
|
207
|
+
- `work --runner claude` 默认会把任务正文交给 Claude Code。如果你加了
|
|
208
|
+
`--dangerously-skip-permissions`,**投递方 = 代码执行权**,请只允许可信来源。
|
|
209
|
+
- 生产使用建议:容器 / git worktree 隔离(roadmap)、按 agent 分离系统用户。
|
|
210
|
+
|
|
211
|
+
## 与同类方案对比
|
|
212
|
+
|
|
213
|
+
| | agent-bus | multi-fleet | AgentChatBus | Google Scion |
|
|
214
|
+
|---|---|---|---|---|
|
|
215
|
+
| 依赖 | 无(SSH+文件) | NATS | MCP 服务进程 | Docker/K8s |
|
|
216
|
+
| NAT/内网 | 原生友好 | 部分 | 需可达端点 | 需集群 |
|
|
217
|
+
| 可审计 | 纯 JSON 文件 | 事件流 | SQLite | 平台日志 |
|
|
218
|
+
| 规模 | 个人/小团队 | 中 | 中 | 大 |
|
|
219
|
+
|
|
220
|
+
agent-bus 不打算赢过重型编排平台,它占的是「**几百行、五分钟、两台机器**」这个角落。
|
|
221
|
+
|
|
222
|
+
## Roadmap
|
|
223
|
+
|
|
224
|
+
- [ ] `--worktree`:每任务独立 git worktree / 容器隔离
|
|
225
|
+
- [ ] 任务签名与来源校验
|
|
226
|
+
- [ ] HTTP / Redis 传输后端(保持文件存储不变)
|
|
227
|
+
- [ ] `agent-bus watch` 实时日志
|
|
228
|
+
- [ ] Windows worker 一键脚本
|
|
229
|
+
|
|
230
|
+
## License
|
|
231
|
+
|
|
232
|
+
MIT
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# agent-bus
|
|
2
|
+
|
|
3
|
+
[](https://github.com/swooshxuan/agent-bus/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](pyproject.toml)
|
|
6
|
+
|
|
7
|
+
> 给多台机器上的 AI agent 用的任务信箱:**SSH 为传输,文件为存储,人类可读**。
|
|
8
|
+
>
|
|
9
|
+
> A tiny, SSH-native, human-readable task mailbox for cross-machine AI agents.
|
|
10
|
+
|
|
11
|
+
不用装 NATS、不用 Kubernetes、不用开公网端口。两台在内网/NAT 后面的机器,
|
|
12
|
+
各放一把受限 SSH 公钥,就能互相派任务、收结果。
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
┌────────────── 信箱(files + SSH)──────────────┐
|
|
16
|
+
laptop ──→│ tasks/laptop/ tasks/lab/ results/<id>.json │←── lab
|
|
17
|
+
agent └────────────────────────────────────────────────┘ agent
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## 为什么
|
|
21
|
+
|
|
22
|
+
现有的多智能体编排方案大多假设:公网可达、有消息中间件、有容器编排。
|
|
23
|
+
但个人/实验室的常态是:笔记本在移动宽带 CGNAT 后面、服务器在校园网后面、
|
|
24
|
+
你想让它们上面的 Claude Code / Codex / 脚本协作一次。
|
|
25
|
+
|
|
26
|
+
agent-bus 做减法:
|
|
27
|
+
|
|
28
|
+
- **零依赖**:纯 Python 标准库,一个文件级队列
|
|
29
|
+
- **NAT 友好**:复用你已经有的 SSH(或 frp/ngrok 隧道)
|
|
30
|
+
- **人类可读**:任务是 JSON 文件,`ls` / `jq` / `git` 都能用
|
|
31
|
+
- **最小权限**:worker 的公钥被 `command=` 钉死,只能执行 `agent-bus`
|
|
32
|
+
- **agent 无关**:Claude Code、Codex、Aider、任意 CLI 都能当 worker
|
|
33
|
+
|
|
34
|
+
> 完整使用手册(配置、任务模板、多机协作、排错)见 **[docs/usage.md](docs/usage.md)**。
|
|
35
|
+
|
|
36
|
+
## 快速开始
|
|
37
|
+
|
|
38
|
+
### 1. 安装(在信箱主机和每台 worker 上)
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install agents-bus # 或 pip install -e .(命令仍是 agent-bus)
|
|
42
|
+
agent-bus --help
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. 信箱主机:准备目录和受限入口
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
export AGENT_BUS_DIR=/srv/agent-bus # 建议写进 ~/.bashrc
|
|
49
|
+
agent-bus list
|
|
50
|
+
|
|
51
|
+
# 把本机的 agent-bus-gate 写成受限命令(每台 worker 的公钥一行)
|
|
52
|
+
echo 'command="agent-bus-gate",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-ed25519 AAAA... lab-worker' \
|
|
53
|
+
>> ~/.ssh/authorized_keys
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
> 也可以用 `--base` 参数指定目录,等价于 `AGENT_BUS_DIR`。
|
|
57
|
+
|
|
58
|
+
### 3. Worker:起一个循环
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# 轮询本机任务,用 Claude Code headless 执行,结果自动回传
|
|
62
|
+
agent-bus work --me lab --dir ~/agent-work --poll 20 -- \
|
|
63
|
+
--dangerously-skip-permissions --max-turns 30
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
或交给 systemd(见 `examples/agent-worker.service`),开机自动挂。
|
|
67
|
+
|
|
68
|
+
### 4. 投递与查看
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# 从任何一台机器派活(经受限 SSH)
|
|
72
|
+
ssh -i ~/.ssh/agentbus bus-host "agent-bus send lab '汇总 CSV' --body '把 data/ 下的 CSV 汇总成 report.md'"
|
|
73
|
+
|
|
74
|
+
# 看任务 / 结果
|
|
75
|
+
ssh -i ~/.ssh/agentbus bus-host "agent-bus tasks lab"
|
|
76
|
+
ssh -i ~/.ssh/agentbus bus-host "agent-bus result <id>"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 远程模式(推荐:机器只出站)
|
|
80
|
+
|
|
81
|
+
worker 机器不需要同步信箱,直接通过受限 SSH 访问信箱主机:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
export AGENT_BUS_REMOTE=ubuntu@bus-host # 信箱主机
|
|
85
|
+
export AGENT_BUS_SSH_KEY=~/.ssh/agentbus # 受限密钥
|
|
86
|
+
agent-bus tasks lab # 等价于 ssh 过去执行
|
|
87
|
+
agent-bus work --me lab --dir ~/agent-work # worker 也走远程
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
MCP 同理:`AGENT_BUS_REMOTE=... claude mcp add agent-bus -- agent-bus-mcp`。
|
|
91
|
+
|
|
92
|
+
## 任务模板(推荐)
|
|
93
|
+
|
|
94
|
+
任务正文按统一结构写,任何 agent 都能读懂,能显著减少「自由发挥」:
|
|
95
|
+
|
|
96
|
+
```text
|
|
97
|
+
@workdir: /home/you/project # 可选;必须是第一行,worker 会 cd 到这里
|
|
98
|
+
# 任务
|
|
99
|
+
把 data/ 下的 CSV 汇总成 report.md
|
|
100
|
+
# 验收标准
|
|
101
|
+
- report.md 存在,包含所有 CSV 的汇总
|
|
102
|
+
- 用中文
|
|
103
|
+
# 背景 / 约束
|
|
104
|
+
- 不要修改原始数据
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
- `@workdir` 只对用 `agent-bus work` 的 worker 生效;不写就用 worker 的 `--dir`
|
|
108
|
+
- 验收标准是写给执行任务的 agent 看的 —— 它会据此自检
|
|
109
|
+
- 示例见 `examples/task-template.md`
|
|
110
|
+
|
|
111
|
+
## 自检与后台运行
|
|
112
|
+
|
|
113
|
+
接入新机器时先跑一次自检,它会逐项检查:模式(本地/远程)、Python、SSH 客户端、密钥、信箱可达性、Claude、作业目录。
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
agent-bus --remote ubuntu@bus-host --remote-key ~/.ssh/agentbus \
|
|
117
|
+
doctor --me lab --dir ~/agent-work
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
每项输出 `PASS` / `WARN` / `FAIL`,最后一行是 `RESULT: OK` 或 `FAILED`(有 FAIL 时退出码非 0)。
|
|
121
|
+
|
|
122
|
+
后台运行(关闭终端也不停):
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
agent-bus --remote ubuntu@bus-host --remote-key ~/.ssh/agentbus \
|
|
126
|
+
work --me lab --detach
|
|
127
|
+
agent-bus status --me lab # RUNNING/STOPPED + 最近日志
|
|
128
|
+
agent-bus stop --me lab
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
日志默认写到 `~/.agent-bus/worker/<me>.log`(`--log` 可改)。
|
|
132
|
+
worker 启动时第一行会打印 `mode: REMOTE ...` 或 `mode: LOCAL ...` —— 本地模式会额外警告「任务不会发往远端」。
|
|
133
|
+
|
|
134
|
+
## 沙箱(v0.2)
|
|
135
|
+
|
|
136
|
+
`work` 默认 `--sandbox auto`:**git 仓库自动使用 worktree**(每个任务一个独立副本,结果里带 diff 统计),非 git 目录退回 `none` 并打印警告。
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
agent-bus work --me lab --dir ~/project # auto → worktree
|
|
140
|
+
agent-bus work --me lab --dir ~/project --sandbox docker # 容器隔离
|
|
141
|
+
agent-bus work --me lab --dir ~/project --sandbox none # 旧行为
|
|
142
|
+
agent-bus work --me lab --dir ~/project --keep-worktrees # 保留 worktree 供检查
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
docker 档位先构建镜像:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
docker build -t agent-bus-worker sandbox/
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
容器只挂载作业目录,凭证通过环境变量传入(`ANTHROPIC_API_KEY` 等),**不挂载 home**。
|
|
152
|
+
安全档位由 worker 决定,任务正文里的 `@sandbox:` 指令会被忽略。
|
|
153
|
+
|
|
154
|
+
## 可靠性
|
|
155
|
+
|
|
156
|
+
- worker 轮询遇网络错误会指数退避重试(5s → 120s),不会退出
|
|
157
|
+
- 结果超过 `AGENT_BUS_MAX_RESULT`(默认 100KB)会截断
|
|
158
|
+
- 执行中崩溃的任务会停留在 `running`:`agent-bus reap --me lab --older 60` 回收
|
|
159
|
+
|
|
160
|
+
安全模型和加固建议见 [SECURITY.md](SECURITY.md)。
|
|
161
|
+
|
|
162
|
+
## 命令参考
|
|
163
|
+
|
|
164
|
+
| 命令 | 说明 |
|
|
165
|
+
|---|---|
|
|
166
|
+
| `agent-bus send <target> <title> [--from N] [--body B]` | 投递任务(body 缺省从 stdin 读),打印任务 id |
|
|
167
|
+
| `agent-bus tasks <me> [--all]` | 列出待办 |
|
|
168
|
+
| `agent-bus claim <me> <id>` | 原子认领(并发安全) |
|
|
169
|
+
| `agent-bus done <me> <id> [--status ok\|fail]` | 提交结果(缺省从 stdin 读) |
|
|
170
|
+
| `agent-bus requeue <me> <id>` | 把卡住的任务重置为 pending |
|
|
171
|
+
| `agent-bus reap <me> [--older 60]` | 回收超时未完成的任务 |
|
|
172
|
+
| `agent-bus show <id>` / `result <id>` | 查看详情 / 结果 |
|
|
173
|
+
| `agent-bus list` | 总览 |
|
|
174
|
+
| `agent-bus doctor [--me N] [--dir D]` | 环境自检 |
|
|
175
|
+
| `agent-bus work --me N --dir D [--sandbox auto\|none\|worktree\|docker] [--detach] [--log F]` | worker 循环(可后台、可沙箱) |
|
|
176
|
+
| `agent-bus status --me N` / `stop --me N` | 后台 worker 状态 / 停止 |
|
|
177
|
+
|
|
178
|
+
## 接入 Claude Code(MCP)
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
claude mcp add agent-bus -- agent-bus-mcp
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
之后 Claude 就能直接调用 `send_task` / `list_tasks` / `complete_task` / `get_result`
|
|
185
|
+
等工具,不需要记命令行。
|
|
186
|
+
|
|
187
|
+
## 安全模型
|
|
188
|
+
|
|
189
|
+
- worker 公钥在信箱主机上被 `command="agent-bus-gate"` 约束,**不能开 shell、不能端口转发**。
|
|
190
|
+
- 信箱目录就是权限边界:能写 `tasks/<me>/` 等于能让 `<me>` 执行任务。
|
|
191
|
+
- `work --runner claude` 默认会把任务正文交给 Claude Code。如果你加了
|
|
192
|
+
`--dangerously-skip-permissions`,**投递方 = 代码执行权**,请只允许可信来源。
|
|
193
|
+
- 生产使用建议:容器 / git worktree 隔离(roadmap)、按 agent 分离系统用户。
|
|
194
|
+
|
|
195
|
+
## 与同类方案对比
|
|
196
|
+
|
|
197
|
+
| | agent-bus | multi-fleet | AgentChatBus | Google Scion |
|
|
198
|
+
|---|---|---|---|---|
|
|
199
|
+
| 依赖 | 无(SSH+文件) | NATS | MCP 服务进程 | Docker/K8s |
|
|
200
|
+
| NAT/内网 | 原生友好 | 部分 | 需可达端点 | 需集群 |
|
|
201
|
+
| 可审计 | 纯 JSON 文件 | 事件流 | SQLite | 平台日志 |
|
|
202
|
+
| 规模 | 个人/小团队 | 中 | 中 | 大 |
|
|
203
|
+
|
|
204
|
+
agent-bus 不打算赢过重型编排平台,它占的是「**几百行、五分钟、两台机器**」这个角落。
|
|
205
|
+
|
|
206
|
+
## Roadmap
|
|
207
|
+
|
|
208
|
+
- [ ] `--worktree`:每任务独立 git worktree / 容器隔离
|
|
209
|
+
- [ ] 任务签名与来源校验
|
|
210
|
+
- [ ] HTTP / Redis 传输后端(保持文件存储不变)
|
|
211
|
+
- [ ] `agent-bus watch` 实时日志
|
|
212
|
+
- [ ] Windows worker 一键脚本
|
|
213
|
+
|
|
214
|
+
## License
|
|
215
|
+
|
|
216
|
+
MIT
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "agents-bus"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "A tiny, SSH-native, human-readable task mailbox for cross-machine AI agents"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
authors = [{ name = "SwooshXuan" }]
|
|
13
|
+
keywords = ["ai-agents", "claude-code", "mcp", "orchestration", "ssh", "nat"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Topic :: System :: Distributed Computing",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://github.com/swooshxuan/agent-bus"
|
|
23
|
+
|
|
24
|
+
[project.scripts]
|
|
25
|
+
agent-bus = "agent_bus.cli:main"
|
|
26
|
+
agent-bus-mcp = "agent_bus.mcp_server:main"
|
|
27
|
+
agent-bus-gate = "agent_bus.gate:main"
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.packages.find]
|
|
30
|
+
where = ["src"]
|