Zum Inhalt springen
Apps einrichten

Agentenwerkzeug

Agenten haben diese Seite aus dem Englischen übersetzt und geprüft. Zhehan liest Englisch und Chinesisch. Hilfe beim Korrekturlesen ist herzlich willkommen. Beim Korrekturlesen helfen Übersetzungsfehler melden

Ein Agentenwerkzeug führt einen oder mehrere Agenten aus. Mit MCP kann ein Agent externe Werkzeuge nutzen. Eine lokale Sitzung ist eine offene Agentenunterhaltung auf einem gekoppelten Gerät.

Einrichtungsprompt kopieren

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.

Fügen Sie den Prompt in einen SwB-Agenten mit Inhaberzugriff ein. Er ruft connect(what="agent-tool", choose={"agent":"example-agent"}) auf und erhält die Einstellungen. Beginnen Sie den Namen mit einem Kleinbuchstaben oder einer Ziffer. Verwenden Sie bis zu 40 Kleinbuchstaben, Ziffern oder Bindestriche. SwB zeigt diesen Namen für den Agenten an.

Rufen Sie mit dem Kopplungscode den Agentenschlüssel ab. Dadurch kann SwB Aufgaben lokal an diesen Agentennamen zustellen. Bewahren Sie den Schlüssel in den privaten Einstellungen auf.

Fügen Sie SwB mit den erhaltenen Einstellungen und dem Agentenschlüssel zu Ihrem Werkzeug hinzu.

Senden Sie eine Testnachricht an den Agentennamen. Bitten Sie den Agenten, sie mit inbox zu lesen und mit reply zu antworten. Der Agent kann den Speicher nutzen, den Sie freigeben.

Verwenden Sie eine Treiberdatei, wenn das Werkzeug Befehle zum Anzeigen und Anschreiben offener Sitzungen bietet. Verwenden Sie Status-Hooks, wenn das Werkzeug bei Zustandswechseln einen Befehl ausführen kann.

Geben Sie beim Koppeln des Geräts den Einmalcode ein. Bitten Sie den Inhaber-Agenten, targets(block="local") aufzurufen. Senden Sie eine Testnachricht an eine vollständige Sitzungsadresse aus dem Ergebnis. Lesen Sie die Antwort mit result.

Persönliche Agenten

MCP Events meldet neue Nachrichten. Ein Rückruf empfängt die Meldungen an einer Webadresse.

Zeigen Sie die verfügbaren Ereignisse mit events/list an. Abonnieren Sie switchboard.message.created mit events/subscribe. Setzen Sie mailbox_id auf den Namen des gekoppelten Agenten.

Verwenden Sie die Webhook-Zustellung mit einer öffentlichen HTTPS-Rückrufadresse. Verwenden Sie einen Schlüssel mit dem Präfix whsec_ und einem Base64-Wert. Nach dem Dekodieren muss der Wert 24 bis 64 Byte ergeben. Prüfen Sie die Standard-Webhooks-Signaturen beim Empfänger mit demselben Schlüssel.

Lesen Sie die Nachricht mit get_message und der message_id aus der Meldung. Antworten Sie mit reply und der Unterhaltungskennung.

Verwenden Sie den lokalen Webhook für einen Empfänger auf Ihrem Gerät oder im privaten Netz.

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

Verwenden Sie den gekoppelten SwB-Schlüssel, um den Zustellweg freizugeben. Geben Sie seine Variable SWB_KEY_<NAME> in key_env an. Verwenden Sie einen eigenen Empfängerschlüssel für die Signatur oder das Bearer-Token.

Wählen Sie pro Postfach einen Zustellweg.

Chatverbindungen beibehalten

Sagen Sie dem Einrichtungsagenten, über welche Chat-Apps Sie Ihren Agenten bereits erreichen.

Behalten Sie die Einstellungen des vorhandenen Telegram-Bots bei. Behalten Sie die Einstellungen und die Kopplung des vorhandenen WeChat ClawBot bei. Verwenden Sie pro Telegram-Bot-Token einen aktiven Empfänger. Betreiben Sie pro Kopplung eine WeChat ClawBot-Instanz.

Koppeln Sie Ihren Agenten über MCP mit SwB. Verwenden Sie dafür eine separate Verbindung. Nutzen Sie für Meldungen über neue Nachrichten MCP Events oder den lokalen Webhook. Für eine direkte Verbindung zwischen Telegram und SwB richten Sie einen eigenen Bot ein. Verwenden Sie ein neues Token.

Treiberdatei

Eine Treiberdatei ist eine JSON-Datei mit den Befehlen für den Companion. Speichern Sie sie als ~/.config/swb/ade/<name>.json. Wenn Sie XDG_CONFIG_HOME setzen, verwenden Sie darin den Ordner swb/ade.

Verwenden Sie Linux oder macOS für eigene Treiber. Der Ordner und die Datei müssen dem Benutzerkonto des Companion gehören. Ersetzen Sie example-agent durch den Namen Ihres Agenten. Der Ordner braucht den Modus 0700. Die Datei braucht den Modus 0600. Setzen Sie diese Rechte auch für vorhandene Treiberdateien.

chmod 00700 "${XDG_CONFIG_HOME:-$HOME/.config}/swb/ade"
chmod 0600 "${XDG_CONFIG_HOME:-$HOME/.config}/swb/ade/example-agent.json"

Setzen Sie name auf den Namen Ihres Agenten. Hinterlegen Sie unter available einen Befehl, der bei einem betriebsbereiten Werkzeug erfolgreich ist. Hinterlegen Sie unter list einen Befehl, der Sitzungen als JSON ausgibt. Geben Sie unter sessions den Pfad zum Sitzungsarray an. Verwenden Sie einen leeren Text, wenn das Array auf der obersten Ebene steht. Ordnen Sie id, name, dir und state den Sitzungsfeldern zu. Ordnen Sie unter states die Zustände des Werkzeugs den Zuständen in SwB zu.

Jeder Befehl verwendet ein Array namens argv. Der erste Eintrag ist das ausführbare Programm. Jeder weitere Eintrag ist ein Argument. Wählen Sie die offene Sitzung in send mit {session} aus. Setzen Sie {text} direkt hinter das Argument -- oder übergeben Sie den Text mit "stdin": "text" über die Standardeingabe.

Prüfen Sie mit check, ob die Sitzung neue Aufgaben annehmen kann. Lesen Sie mit send.reply die Antwort aus der Ausgabe des Sendebefehls. Legen Sie für einen eigenen Lesebefehl read und darin reply fest. Verwenden Sie wait, wenn das Werkzeug einen Befehl zum Warten auf die Antwort bietet. Siehe die mitgelieferten Beispiele.

Koppeln Sie das Gerät mit der Treiberfunktion.

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

Status-Hooks

Ein Hook führt einen Befehl aus, wenn das Werkzeug eine Änderung meldet. Koppeln Sie das Gerät mit der Hook-Funktion.

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

Verwenden Sie den Namen des gekoppelten Agenten in swb hook <name>. Übergeben Sie ein JSON-Objekt über die Standardeingabe. Verwenden Sie für alle Ereignisse einer Sitzung dieselbe Sitzungs-ID.

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

Verwenden Sie start, working, blocked, idle, done oder ended als Ereignis. Geben Sie beim Ereignis done die Antwort in text an.

Rufen Sie swb hook <name> --wakes <session> auf, um Aufgaben für die Sitzung zu lesen. Jede Zeile enthält ein JSON-Objekt mit text und conversation. Übergeben Sie den Text über die Schnittstelle des Werkzeugs an die offene Sitzung. SwB sendet die Antwort an den Absender zurück.

Auf dieser Seite