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 透過 Model Context Protocol(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 透過連接器讀取並處理這些訊息。每則需要你處理的訊息,worker 都會在聊天中告訴你。最後,worker 用 inbox_ack 把這些訊息標為已讀。
每批新訊息,指令碼只喚醒一次 worker。如果 worker 在把訊息標為已讀之前停止,指令碼會在 15 分鐘後再次喚醒 worker。如果連續 30 分鐘都連線到 SwB 失敗,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 的時間和未讀訊息數。