# Bring your own agent

> Any agent or tool that can make an HTTP request can have a duckling in the creek, and have Waddle walk over when it needs you.

Your agent tells Waddle two kinds of thing: what its session is doing (the duckling), and news worth walking over for (Waddle). Both go to `localhost:4404`, from programs on this Mac.

## 1. A session starts

```sh
curl localhost:4404/session -H 'content-type: application/json' \
  -d '{"session":"my-agent-7f3a","event":"start","cwd":"/Users/you/code/limen"}'
```

```json
{ "ok": true }
```

A duckling named after the folder (limen) swims into the creek. Use one session id for the whole session: 8 to 64 letters, digits and dashes.

## 2. It works, then it's your turn

Send `prompt` when someone asks it something, `tool` for each step it takes, and `turn` when it's done or waiting on you. The duckling dabbles while it works, and hops onto the bank on `turn`.

```sh
curl localhost:4404/session -H 'content-type: application/json' \
  -d '{"session":"my-agent-7f3a","event":"turn","cwd":"/Users/you/code/limen"}'
```

```json
{ "ok": true }
```

## 3. Waddle walks over

The duckling shows it quietly. To have Waddle come and say so, send one of Waddle's own lines, with the project's name:

```sh
curl localhost:4404/quack -H 'content-type: application/json' \
  -d '{"phrase":"agent-done","project":"limen"}'
```

```json
{ "ok": true, "mood": "quack" }
```

The reply's `text` is the line Waddle picked. The phrases: `agent-done`, `agent-waiting`, `agent-decision`, `deploy-live`, `deploy-failed`. News about one project replaces that project's last, so a busy agent never stacks up letters in the mailbox.

## 4. The session ends

```sh
curl localhost:4404/session -H 'content-type: application/json' \
  -d '{"session":"my-agent-7f3a","event":"end","cwd":"/Users/you/code/limen"}'
```

## Be a good guest

- Never wait on Waddle: give each request a short timeout (Waddle's own hooks use 1 second) and carry on if it fails. Waddle may not be running.
- Send what happened, not what was said: no prompts, no output.
- Send `term` if you can, so a click on the duckling jumps to the right terminal. See [Sessions](https://docs.waddle.sh/sessions.md).
- If your agent runs the `waddle` command, set `WADDLE_AGENT` to its name in the agent's environment, so Waddle knows an agent ran it.
