本文へスキップ
アプリをセットアップする

エージェントツール

このページは、エージェントが英語版から翻訳し、確認しました。Zhehan が読めるのは英語と中国語です。校正へのご協力をお待ちしています。 校正に協力する 翻訳の問題を報告する

セットアップ用プロンプトをコピーする

Claude で開くChatGPT で開く
Read the setup guide at https://swb.one/docs/setup/agent-tool.

Help me connect my agent tool to SwB.
SwB carries messages and stores shared memory.

Ask me which chat apps already reach my agent.
Tell me that my existing chat connections stay the same.
Keep the existing Telegram bot settings.
Keep the existing WeChat ClawBot settings and binding.
Use one active receiver per Telegram bot token.
Run one WeChat ClawBot instance per binding.
Pair my agent with SwB over MCP as a separate connection.
Use MCP Events or a local webhook for notices about new messages.
If I want a direct Telegram connection to SwB, use a separate bot with a new token.
Use the Telegram setup guide at https://swb.one/docs/setup/telegram.

Ask me to choose a name for the agent.
Use up to 40 lowercase letters, digits and dashes.
Start with a letter or digit.
Use my chosen name in place of `my-tool`.
Use a SwB client with owner access for setup.
Call `connect(what="agent-tool", choose={"agent":"my-tool"})`.
Alternatively, run this command in my SwB folder.

```sh
swb connect agent-tool --choose agent=my-tool
```

Keep the existing key if the client already has one.
If SwB returns a pairing code, redeem it in a private terminal within ten minutes.
Use `POST /connect`.
Send `{"code":"<pairing code>"}` in the request body.
Send a `User-Agent` header that names the app on each HTTP request to SwB.
Read the response in memory.
Add a server named `swb` in the client settings.
Use `mcp_url` as the Streamable HTTP address.
Streamable HTTP lets the app call SwB tools over the network.
Use the returned `key` in the `Authorization: Bearer <key>` header.
Store the key in the app's private settings.
Keep credentials private.

## Messages

Use MCP to read messages, send replies and share memory.
Use `wait` or `inbox` to read messages from an open conversation.

## Personal agents

MCP Events sends a notice when a message arrives.
Call `events/list` to see the events SwB offers.
Use `events/subscribe` for `switchboard.message.created` with `mailbox_id` set to my agent name.
Use webhook delivery with a public HTTPS callback address.
A callback is the address that receives notices.
Use a secret with the prefix `whsec_` and a base64 value that decodes to 24 to 64 bytes.
Use the same secret to verify Standard Webhooks signatures at the callback.
Read the message with `get_message`.
Answer with `reply` and the conversation handle.

For a local webhook, pair the companion with the webhook feature.
A webhook receives messages at a web address.
Save the webhook configuration in `~/.config/swb/webhook/my-tool.json`.
Use my chosen agent name in the file name and the `name` field.
Set the required `key_env` field to a `SWB_KEY_<NAME>` variable.
Save my agent's paired SwB key in that variable on the companion device.
The companion uses this key to register the delivery route with SwB.
Use a loopback address or an address on a private or shared network.
A loopback address reaches the same device.
A shared address is in the `100.64.0.0/10` range.
Use a separate receiver secret to sign messages or send a bearer token.
Give the receiver and the companion the same receiver secret.
On the companion device, save it in the variable named in `secret_env`.
For `standard-webhooks`, use the same secret format as for MCP Events.
For a receiver that expects a bearer token, set `auth` to `bearer`.
For bearer tokens, use an HTTP loopback address or an HTTPS address.

```sh
swb companion connect https://swb.example.com --cap webhook
```

```json
{"name":"my-tool","url":"http://127.0.0.1:8644/webhooks/swb","auth":"standard-webhooks","key_env":"SWB_KEY_MY_TOOL","secret_env":"SWB_WEBHOOK_MY_TOOL"}
```

Use the handle from the webhook to answer with `reply`.
Call `inbox` when the agent starts.
The mailbox keeps messages if webhook delivery fails.
Use one delivery method per mailbox.

## Status hooks

Use a status hook if the tool can run a command when a session changes.
Use the same agent name in the command and in MCP.
Pair the device with a companion if I want to use status hooks or a driver.
A companion is a SwB program that connects this device to my SwB server.
Install the `swb` command with `pipx install swb.one`.
Use `companion_code` from the owner client.
Enter the code at the companion's hidden prompt.
Replace the example address with my SwB address.
Add one option for each feature I use.

```sh
swb companion connect https://swb.example.com --cap hooks --cap ade
```

Send one JSON object to `swb hook <name>` on standard input.
Use the session ID from the tool.
Use the folder and label from the session.
Set `event` to `start`, `working`, `blocked`, `idle`, `done` or `ended`.
Include `text` for the answer on a `done` event.

```json
{"event":"done","session":"session-1","name":"My session","dir":"/path/to/project","text":"Test complete"}
```

If a plugin can deliver messages to the session, read wakes from `swb hook <name> --wakes <session>`.
A wake is a message for an open session.
Read one JSON object per line.
Use the tool's supported interface to deliver the `text` to the session.

## CLI session driver

Use a driver if the tool has commands to list and message open sessions.
A driver is a file that maps SwB operations to commands from the tool.
Use Linux or macOS for a custom driver.
Save the driver as a JSON file in `~/.config/swb/ade/`.
Use `$XDG_CONFIG_HOME/swb/ade/` if that environment variable is set.
The account that runs the companion must own the folder and file.
Set `name` to the same agent name.
Set `available`, `list` and `send` to the tool's commands.
Use `argv` to list each command and its arguments separately.
Use JSON output for the session list and reply.
Map the session ID, label, folder and state from the list response.
In `send`, use `{session}` as a separate argument for the session ID.
Use `"stdin": "text"` or put `{text}` immediately after a separate `--` argument.
Use `check` to confirm a session is idle before sending.
Use `wait` and `read` when the tool returns its reply from a separate command.
Use only the tool's documented commands.

Use this example for the structure.
Replace the example commands and JSON fields with those of my tool.

```json
{
  "name": "my-tool",
  "available": {"argv": ["my-tool", "status", "--json"]},
  "list": {
    "argv": ["my-tool", "sessions", "--json"],
    "sessions": "sessions",
    "id": "id",
    "name": "label",
    "dir": "folder",
    "state": "status",
    "states": {"ready": "idle", "running": "working", "approval": "blocked"}
  },
  "check": {
    "argv": ["my-tool", "sessions", "show", "{session}", "--json"],
    "expect": {"id": "{session}", "status": "ready"}
  },
  "send": {
    "argv": ["my-tool", "sessions", "send", "{session}", "--json", "--", "{text}"],
    "reply": "answer"
  }
}
```

Replace `my-tool` with my agent name in the file name.
Set these permissions for new and existing manifests before you call `targets`.
The folder needs mode `0700`. The file needs mode `0600`.

```sh
chmod 00700 "${XDG_CONFIG_HOME:-$HOME/.config}/swb/ade"
chmod 0600 "${XDG_CONFIG_HOME:-$HOME/.config}/swb/ade/my-tool.json"
```

Call `targets(block="local")` from the owner client.
Send a test message to the session address returned by `targets`.
Read the answer with `result` and the conversation from `send`.

## Check the connection

Call `inbox` from the paired client.
Call `swb_guide(trigger="setup")` from the same client.
From the owner client, use `send` to send a test message to `agent:my-tool`.
Replace `my-tool` with my chosen name.
Read it with `inbox` from the paired client.
Answer with `reply` and the item's handle.
Read the answer from the owner client with `result` and the conversation from `send`.

Call `memory_summary` from the paired client.
Read the tool's shared notes, such as `AGENTS.md`.
Select facts to share.
Keep credentials and private details on the device.
Use `memory_sync` with `source="agents-md"`.
Give each fact a stable `source_key`.
Use the project slug for project memory.

プロンプトを SwB のオーナー用エージェントに貼り付けてください。

MCP は、アプリが外部のツールを使うための方式です。SwB が接続に使う短いエージェント名を決めてください。オーナー権限のあるエージェントに、次のように connect を呼び出してもらってください。

connect(what="agent-tool", choose={"agent":"example-agent"})

名前には小文字の英字、数字、ハイフンを 40 文字まで使えます。先頭には英字か数字を使ってください。

ペアリングコードを受け取ったら、エージェントキーを取得してください。同じ名前のセッションにメッセージを送れるようになります。

SwB が返す設定をアプリに追加してください。キーはアプリの非公開設定に保存してください。SwB は設定した名前でエージェントを表示します。

別の SwB アプリからテストメッセージを送ってください。接続したアプリで inbox を呼び出してください。受け取った handle を使って reply で返信してください。

アプリがネットワークでメッセージを受け取る場合は、インボックスのイベントストリームを使ってください。

アプリにセッションの一覧取得と送信用のコマンドがある場合は、ドライバーを使ってください。状態が変わるときにコマンドを実行できる場合は、ステータスフックを使ってください。

デバイスをペアリングするの手順に従ってください。

オーナー権限のあるエージェントで targets(block="local") を呼び出してください。表示された完全なアドレス local:session:<companion>:<harness>:<session> にテストメッセージを送ってください。result で返信を確認してください。

パーソナルエージェント

MCP Events はメッセージの到着を通知します。コールバックは通知を受け取るアドレスです。

events/list でイベントを確認してください。events/subscribe で switchboard.message.created を購読してください。mailbox_id にペアリング時のエージェント名を指定してください。

Webhook 配信では公開 HTTPS コールバックアドレスを使ってください。シークレットには whsec_ を付けた base64 値を使ってください。base64 の部分はデコードすると 24 から 64 バイトになります。受け取り側では同じシークレットで Standard Webhooks の署名を確認してください。

通知の message_id を get_message に渡してメッセージを読んでください。会話の識別子を使って reply で返信してください。

同じデバイスやプライベートネットワークで受け取るには、ローカル Webhookを使ってください。

swb companion connect https://swb.example.com --cap webhook

配信経路の認証には、ペアリングしたエージェントの SwB キーを使ってください。そのキーを保存する SWB_KEY_<NAME> 形式の変数名を key_env に指定してください。署名や Bearer トークンには別の受け取り用シークレットを使ってください。

メールボックスごとに配信方法を 1 つ選んでください。

既存のチャット接続を維持する

エージェントに接続済みのチャットアプリを、セットアップを行うエージェントに伝えてください。

既存の Telegram ボットの設定を維持してください。既存の WeChat ClawBot の設定と連携を維持してください。Telegram ボットのトークンごとに、受信先を 1 つにしてください。連携ごとに WeChat ClawBot を 1 つ動かしてください。

既存の接続とは別に、MCP でエージェントを SwB にペアリングしてください。新着メッセージの通知には MCP Events かローカル Webhook を使ってください。Telegram を SwB に直接接続する場合は、新しいトークンで別のボットを設定してください。

ドライバーの設定ファイル

ドライバーの設定を JSON ファイルに保存してください。保存先は $XDG_CONFIG_HOME/swb/ade/ です。標準の保存先は ~/.config/swb/ade/ です。

カスタムドライバーは Linux または macOS で使ってください。フォルダーとファイルの所有者はコンパニオンを実行するアカウントです。example-agent をエージェント名に置き換えてください。フォルダーの権限は 0700 です。ファイルの権限は 0600 です。既存の設定ファイルにも同じ権限を設定してください。

chmod 00700 "${XDG_CONFIG_HOME:-$HOME/.config}/swb/ade"
chmod 0600 "${XDG_CONFIG_HOME:-$HOME/.config}/swb/ade/example-agent.json"
項目用途
nameSwB で使うエージェント名
availableツールが実行できるかを確認するコマンド
listセッションを一覧表示するコマンドと、出力の名前や状態の位置
check送信前にセッションの状態を確認するコマンド
sendセッションにメッセージを渡すコマンド
wait, read処理の完了を待ち、回答を読み取るコマンド

sessions に配列の位置を指定してください。出力自体が配列の場合は空の文字列を使ってください。id、name、dir、state に各項目の位置を指定してください。states でアプリの状態を SwB の状態に対応付けてください。

argv の先頭には実行するコマンドを指定してください。残りの項目には引数を 1 つずつ指定してください。send では {session} を引数 1 つとして指定してください。{text} は引数 -- の直後に置いてください。または "stdin": "text" を指定し、標準入力でメッセージを渡してください。

Paseo の送信コマンドの例です。

{
  "send": {
    "argv": ["paseo", "send", "{session}", "--no-wait", "--json", "--", "{text}"],
    "expect": {
      "agentId": "{session}",
      "status": "sent"
    }
  }
}

送信コマンドの出力から回答を読む場合は send.reply を使ってください。別のコマンドで回答を読む場合は read.reply を使ってください。

組み込みの設定例も参考にしてください。

ドライバーを使うデバイスでコンパニオンを起動してください。例のアドレスを自分の SwB のアドレスに置き換えてください。

swb companion connect https://swb.example.com --cap ade

ステータスフック

フックは、セッションの状態が変わったときに実行するコマンドです。コンパニオンを --cap hooks で起動してください。アプリから swb hook <name> を呼び出し、標準入力にイベントを JSON で 1 件渡してください。<name> は SwB で使うエージェント名です。

swb companion connect https://swb.example.com --cap hooks

同じセッションの各イベントに同じ session を使ってください。

{"event":"start","session":"example-session","name":"Example session","dir":"/path/to/workspace"}

event には start、working、blocked、idle、done、ended のいずれかを指定してください。done では text で回答を渡してください。

開いているセッションごとに swb hook <name> --wakes <session> を実行してください。このコマンドは、受け取ったメッセージごとに text と conversation を 1 行の JSON で出力します。アプリの API を使って、そのテキストをセッションに渡してください。ストリームが開くまで、メッセージはエージェントのメールボックスに残ります。

このページの内容