Aller au contenu
Configurer vos applications

Outil pour agents

Des agents ont traduit cette page depuis la version anglaise, puis l'ont vérifiée. Zhehan lit l'anglais et le chinois. Votre aide à la relecture est la bienvenue. Aider à relire Signaler un problème de traduction

Un outil pour agents exécute un ou plusieurs agents. MCP permet à un agent d'utiliser des outils externes. Une session locale est une conversation ouverte avec un agent sur un appareil appairé.

Copier le prompt de configuration

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.

Collez le prompt dans un agent SwB avec un accès propriétaire. Cet agent appelle connect(what="agent-tool", choose={"agent":"example-agent"}) pour obtenir les paramètres. Commencez le nom par une lettre minuscule ou un chiffre. Utilisez jusqu'à 40 caractères parmi les lettres minuscules, les chiffres et les traits d'union. SwB affiche ce nom pour désigner l'agent.

Utilisez le code d'appairage pour obtenir la clé de l'agent. SwB peut alors transmettre des tâches locales à cet agent. Gardez la clé dans les paramètres privés.

Ajoutez SwB à votre outil avec les paramètres reçus et la clé de l'agent.

Envoyez un message de test à l'agent en utilisant son nom. Demandez-lui de le lire avec inbox et de répondre avec reply. L'agent peut utiliser la mémoire que vous partagez.

Utilisez un fichier de pilote si l'outil dispose de commandes pour lister les sessions et leur envoyer des tâches. Utilisez des hooks d'état si l'outil peut exécuter une commande à chaque changement d'état.

Saisissez le code à usage unique lors de l'appairage de l'appareil. Demandez à votre agent propriétaire d'appeler targets(block="local"). Envoyez un message de test à une adresse de session complète du résultat. Lisez la réponse avec result.

Agents personnels

MCP Events envoie un avis à chaque nouveau message. Une adresse de rappel reçoit les avis.

Consultez les événements disponibles avec events/list. Abonnez-vous à switchboard.message.created avec events/subscribe. Indiquez le nom de l'agent appairé dans mailbox_id.

Utilisez la livraison par webhook avec une adresse HTTPS publique de rappel. Utilisez un secret avec le préfixe whsec_ et une valeur base64. Cette valeur doit donner de 24 à 64 octets après décodage. Utilisez le même secret pour vérifier les signatures Standard Webhooks chez le destinataire.

Lisez le message avec get_message et le message_id de l'avis. Répondez avec reply et l'identifiant de conversation.

Utilisez le webhook local pour un destinataire sur votre appareil ou votre réseau privé.

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

Utilisez la clé SwB de l’agent appairé pour autoriser le trajet de livraison. Indiquez sa variable SWB_KEY_<NAME> dans key_env. Utilisez un secret distinct pour signer les messages ou envoyer un jeton Bearer.

Choisissez un mode de livraison par boîte aux lettres.

Conserver vos connexions de chat

Indiquez à l’agent de configuration quelles applications de chat communiquent déjà avec votre agent.

Conservez les réglages du bot Telegram. Conservez les réglages et l’association de WeChat ClawBot. Utilisez un seul récepteur actif par jeton de bot Telegram. Exécutez une seule instance de WeChat ClawBot par association.

Appairez votre agent à SwB par MCP dans une connexion distincte. Utilisez MCP Events ou le webhook local pour les avis de nouveaux messages. Pour relier Telegram directement à SwB, configurez un bot distinct avec un nouveau jeton.

Fichier de pilote

Un fichier de pilote indique au compagnon les commandes à exécuter. Enregistrez-le au format JSON sous ~/.config/swb/ade/<name>.json. Si vous définissez XDG_CONFIG_HOME, utilisez son dossier swb/ade.

Utilisez Linux ou macOS pour un pilote personnalisé. Le compte qui exécute le compagnon doit être propriétaire du dossier et du fichier. Remplacez example-agent par le nom de votre agent. Utilisez le mode 0700 pour le dossier. Utilisez le mode 0600 pour le fichier. Appliquez aussi ces droits aux fichiers de pilote existants.

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

Indiquez le nom de l'agent dans name. Dans available, indiquez une commande qui réussit quand l'outil est prêt. Dans list, indiquez une commande qui renvoie les sessions en JSON. Indiquez dans sessions le chemin du tableau des sessions. Utilisez une chaîne vide pour un tableau au premier niveau. Associez id, name, dir et state aux champs de la session. Faites correspondre les états de l'outil à ceux de SwB dans states.

Chaque commande utilise un tableau argv. Le premier élément est le programme à exécuter. Chaque élément suivant est un argument. Dans send, utilisez {session} pour choisir la session ouverte. Placez {text} juste après l'argument littéral -- ou envoyez le texte sur l'entrée standard avec "stdin": "text".

Utilisez check pour confirmer que la session peut recevoir une tâche. Utilisez send.reply pour lire la réponse de la commande d'envoi. Pour une commande de lecture séparée, utilisez read et définissez son champ reply. Utilisez wait si l'outil dispose d'une commande pour attendre la réponse. Consultez les exemples fournis.

Appairez l'appareil avec la fonction de pilote.

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

Hooks d'état

Un hook lance une commande lorsque l'outil signale un changement. Appairez l'appareil avec la fonction de hooks.

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

Utilisez le nom de l'agent appairé dans swb hook <name>. Passez un objet JSON sur l'entrée standard. Gardez le même identifiant de session pour chaque événement de cette session.

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

Utilisez start, working, blocked, idle, done ou ended comme événement. Mettez la réponse dans text pour l'événement done.

Lancez swb hook <name> --wakes <session> pour lire les tâches destinées à cette session. Chaque ligne contient un objet JSON avec text et conversation. Transmettez le texte à la session ouverte par l'interface de l'outil. SwB renvoie la réponse à l'expéditeur.

Sur cette page