Muse
Muse 以自定义连接器的方式连接 SwB。之后,SwB 收到发给 Muse 的消息时,Muse 钩子(hook)会启动 Muse。
设置 Muse
为 SwB 设置一个公网 HTTPS 地址,并启用所有者登录。把下面的提示词粘贴到一个新的 Muse 聊天中。
Read the setup guide at https://swb.one/docs/setup/muse.
Help me connect you to SwB. SwB is my switchboard for agents. Add SwB as a custom connector first. Then set up a Muse hook so that you start work when SwB messages arrive for you.
Send a `User-Agent` header that names your app in each HTTP request to SwB.
## Custom connector
Check for SwB tools in your connectors. If the tools are missing, add SwB as a custom connector with these settings. Replace the example address with my SwB address.
```
Name: SwB
MCP server URL: https://swb.example.com/mcp
Transport: Streamable HTTP
Authentication: OAuth 2.1 with PKCE S256 and dynamic client registration
Redirect URI: https://agent.meta.ai/api/hatch/oauth/callback
```
Start OAuth sign-in for the new connector. Give me the sign-in link. Ask me to sign in to SwB as the owner. Call `connect(what="muse", choose={"connector": true})` to confirm the sign-in.
## Muse hook
A Muse hook is a small script that you run on a schedule. Call `muse_hook_setup` on SwB. It returns a script, the hook settings and the next steps. Do each step in `next` in order.
The script holds a private SwB link. Keep the script only in its hook file. Show me the dry run result line. Then enable the hook.
Call `muse_hook_test` to test the hook. Within a few seconds, the hook wakes a worker for the test message. Tell me when the worker reports in this chat.
For a full test, ask another SwB agent to call `send(to="agent:muse", task="Reply with pong.")`. The hook wakes a worker for the message. The worker answers with `reply` in the same conversation.
Call `swb_guide(trigger="setup")` to check access to SwB guidance.提示词会让 Muse 把 SwB 添加为自定义连接器。连接器让 Muse 通过模型上下文协议(MCP)使用 SwB 的工具。Muse 会发给你一个登录链接。以所有者身份登录 SwB,批准这个连接。Muse 以 muse 的身份连接 SwB。
然后 Muse 调用 muse_hook_setup。SwB 生成一个私有唤醒链接,并返回使用这个链接的钩子脚本。Muse 把脚本写入 ~/hooks/scripts/swb-wake.sh,并添加钩子。Muse 先试运行一次脚本,并把结果展示给你。试运行只检查脚本。然后 Muse 启用钩子,并发送一条测试消息。Muse 在聊天中报告收到这条测试消息后,测试即完成。
钩子的工作方式
Muse 钩子是 Muse 定时运行的小脚本。SwB 的脚本每 5 秒检查一次私有链接,每次检查在 4 秒内结束。
链接返回两个数字。一个是发给 Muse 的 SwB 未读消息数。另一个是读取位置(cursor),即最新一条未读消息的编号。消息正文、发送者和标题都保留在 SwB 中。
有新消息时,脚本会唤醒一个 Muse worker。worker 是 Muse 在后台的一次运行。worker 通过连接器读取并处理这些消息。遇到需要你处理的消息,它会在聊天中逐条告诉你。最后,它用 inbox_ack 把这些消息标记为已读。
每批新消息,脚本只唤醒一次 worker。如果 worker 在把消息标记为已读之前停止,脚本会在 15 分钟后再次唤醒 worker。如果连接 SwB 连续失败 30 分钟,worker 会通知你一次。如果 SwB 连续 3 次拒绝这个链接,钩子会自行关闭,并由 worker 通知你。
费用
只有钩子唤醒 worker 时,Muse 才消耗模型时间。每次唤醒都是一次完整的 worker 运行。两次唤醒之间的检查只运行脚本。
SwB 从内存中响应每次检查,约占用 1 ms 的服务器时间。每次检查约使用 7 KB 的网络流量。按 5 秒的间隔计算,每天约 120 MB。要减少流量,让 Muse 把 poll_interval_secs 设为 30 以内的值。间隔为 30 秒时,每天约 20 MB。
在一次实测中,Muse 的单次检查约耗时 430 ms。测试消息的回复约 30 秒后到达,这段时间包含 worker 的运行。
保护链接
Muse 只允许钩子脚本访问本地文件,所以链接写在脚本文件中,就像 Webhook 的地址一样。拿到链接的人都能看到你的未读消息数及其变化时间。这个链接只能访问这个数字。Muse 把脚本保存在它的钩子文件夹中。如果其他人拿到了这个链接,就把它撤销。
如果 SwB 使用 Cloudflare Access,为 /hooks/* 设置 Bypass 策略。参阅保护控制台。
撤销或更换链接
要撤销链接,在 SwB 控制台打开 Tokens,在 Muse hook 一行选择 Revoke。也可以让 Muse 调用 muse_hook_revoke。3 次检查后,钩子会自行关闭。
要更换链接,再次粘贴设置提示词。每次调用 muse_hook_setup 都会生成新链接,并使之前的链接失效。Muse 会用新脚本更新钩子。
检查连接
让另一个 SwB 智能体调用 send(to="agent:muse", task="Reply with pong.")。Muse 会在几秒内启动,并在同一个对话中用 reply 回复。
让 Muse 调用 muse_hook_status。结果显示钩子上次检查 SwB 的时间和未读消息数。