When a CI pipeline should alert an OpenClaw agent about a failed build, when do you call `/hooks/wake` and when `/hooks/agent`?
answer
- a nudge versus a full turn
- system event in the main session
- isolated hook:<uuid> run by default
- 200 means admitted, not finished
- channel and to go together
basics
~20 sUse /hooks/wake for a short trusted notice that the main session should handle, now or at the next heartbeat. Use /hooks/agent to start a separate agent turn on a message, isolated by default, that can deliver its own result to a chat channel.
solid answer
~50 sBoth are POST endpoints under `hooks.path` (default `/hooks`), off until `hooks.enabled` is set and authenticated with `hooks.token`. `/hooks/wake` takes a required `text` and an optional `mode`, `now` by default or `next-heartbeat`: it enqueues a system event in the selected agent's main session, so the agent reads "build 412 failed on main" alongside the owner's conversation. Wake text is not safety-wrapped, so send only short text you control. `/hooks/agent` takes a required `message` and starts its own turn, `sessionMode` `isolated` by default with a fresh `hook:<uuid>` key; its content is safety-wrapped, and with both `channel` and `to` it announces to that destination. For CI, wake suits a one-line nudge; agent suits "read this failure summary and post a diagnosis to the builds channel". Either way, HTTP 200 means admitted, not finished; add `waitForCompletion: true` to `/hooks/agent` when the caller needs the outcome.
code
bash · 5 linescurl -X POST http://127.0.0.1:18789/hooks/agent \
-H 'Authorization: Bearer <long-random-hook-token>' \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: ci-build-412' \
--data '{"message":"Build 412 failed: 3 tests in payments. Diagnose and summarize.","name":"CI failure","agentId":"ci-reader","channel":"slack","to":"channel:C1234567890"}'go deeper
Remember the two endpoints: wake takes text for the main session, agent takes a message and runs its own turn.
Explain wake modes, the isolated default for agent runs, why channel and to must come together, and that 200 means admission only.
Show how you would wire CI safely: wake only for trusted short text, agent with a restricted agentId for logs, idempotency keys and waitForCompletion for retries.
Decide which outside systems may start agent work at all, and whether their events belong in the owner's conversation or in separate isolated runs.
## Inbound HTTP triggers in OpenClaw Besides its own schedules, OpenClaw lets outside services start work over HTTP. The Gateway exposes **hook endpoints** under `hooks.path` (default `/hooks`). They are **disabled by default**; turning them on needs `hooks.enabled: true` and a dedicated `hooks.token`. They are separate from *internal* event hooks (`HOOK.md` handlers configured under `hooks.internal`) and from *outbound* job webhooks, where OpenClaw calls someone else. Two endpoints are built in. Custom paths (`/hooks/<name>`) can be added with `hooks.mappings`, which turn a payload into one of the same two actions. ## `/hooks/wake`: a nudge to the main session - Body: a required nonempty `text`, plus optional `mode`, `agentId` and `sessionKey`. - `mode` is `now` by default, which requests an immediate heartbeat, or `next-heartbeat`, which lets the event wait for the next scheduled one. - The text becomes a **system event in the selected agent's main session**, so it is handled with that conversation's context. - The response is `200` with `eventOutcome` `queued`, or `coalesced` when the same wake is already the most recent pending event. It does not mean a heartbeat ran. - Wake text is **not** safety-wrapped like agent-hook content. Send a short notification you wrote, never raw logs or email. ## `/hooks/agent`: a separate agent turn - Body: a required `message`, plus optional `name`, `agentId`, `sessionMode`, `model`, `thinking`, `timeoutSeconds`, delivery fields and an idempotency key. - `sessionMode` defaults to `isolated`: each request gets a fresh run session under a generated `hook:<uuid>` key. `persistent` reuses context but needs an explicit `sessionKey`, `hooks.allowRequestSessionKey: true` and a nonempty `hooks.allowedSessionKeyPrefixes`. - External content in `message` is **safety-wrapped** by default. Wrapping does not remove tools, so a reader agent for untrusted input still needs restricted tools. - Delivery: `deliver` defaults to `true`. For a direct chat post, give **both** `channel` and `to`; a partial destination, an invalid account or `channel: "last"` returns `400` before dispatch. With no destination, success can surface as a completion event in the agent's main session. ## Side by side | | `/hooks/wake` | `/hooks/agent` | |---|---|---| | Required field | `text` | `message` | | Runs in | main session | fresh isolated run by default | | Model call | at the next or immediate heartbeat | its own turn | | Content handling | trusted system event | safety-wrapped external content | | Direct chat delivery | via the main session's route | `channel` plus `to` | ## The CI case 1. **A short alert the owner should hear about in context.** Call `/hooks/wake` with `{"text": "CI: build 412 failed on main", "mode": "now"}`. The assistant raises it in the ongoing conversation. 2. **A diagnosis posted to the team.** Call `/hooks/agent` with a message summarising the failure, a restricted `agentId`, and `channel` plus `to` for the builds channel. The run is isolated, so each failure is judged on its own. 3. **Raw logs or test output.** Use `/hooks/agent`, not wake, so the content is wrapped as external data, and point it at an agent whose tools are narrowed. ## Mapped hooks for services you do not control Many CI and SaaS systems send their own JSON shape and cannot be told to post `{"message": ...}`. For those, add an entry to `hooks.mappings` and give the service a custom path such as `/hooks/ci`: - Mappings run in order and the first match wins, ahead of presets such as the built-in `gmail` one. - A mapping produces a `wake` or `agent` action (`action` defaults to `agent`), using templates such as `{{payload.build.status}}` or a trusted JS/TS transform under `hooks.transformsDir`. - A transform that returns `null` answers `204` and starts no run, which is how you drop green builds. - Transforms execute as trusted Gateway code, not in an agent sandbox, so they belong to the operator, not to whoever sends events. ## What a 200 does and does not prove For `/hooks/agent`, `200 {"ok": true, "runId": ...}` means the run acquired admission, after waiting up to 15 seconds. The model may still be starting, and nothing has been delivered yet. Add `"waitForCompletion": true` to keep the request open until the run settles; the response then includes a `completion` object with `status`, `replyDisposition` and delivery facts, but never the model's text. Send an `Idempotency-Key` header so a retry after a lost response replays the same run instead of starting a second one. In `openclaw logs --follow`, search for `hook agent run completed` and the `runId`.
- Why can an OpenClaw `/hooks/agent` request return 503 even though the token was right?A single agent request waits up to 15 seconds for session and global placement admission. If admission does not happen in that window, the queued work is cancelled and the caller gets 503; a Gateway restart or suspension can also return 503. A common cause is a fixed `hooks.defaultSessionKey`, which serializes requests sharing that key, so a burst of hooks queues behind a still-running earlier run.
- What does `deliver: false` on an OpenClaw `/hooks/agent` request change, and what does it not?It suppresses the successful announcement and ignores destination fields; completion is logged instead, and non-ok outcomes still produce a failure event. It is not a tool restriction: the agent can still use messaging tools during the run. If a hook-triggered agent must not send messages, restrict that agent's tools separately.
- A 200 from /hooks/agent means the agent finished and the reply was delivered.
- /hooks/wake starts a fresh isolated agent turn on the posted text.
- Raw CI logs are fine to send as /hooks/wake text.
- Setting channel to last on /hooks/agent reuses the main chat's recipient.
- deliver: false stops a hook-triggered agent from using messaging tools.