# Watchers an agent can write

A dashboard tells you something when you open it. **A watcher tells you when you were not looking.** A harness cannot do that on its own: it needs hosted state, fresh data, a wall clock and somewhere to deliver.

Everything that happens later or by itself is a watcher: a message about a dashboard every Monday, a number checked every morning, an agent that looks into why a figure moved. There is one object, in three parts:

| Part                  | What it decides                                                                                                                                           |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `triggers`            | **WHEN** it runs: `schedule` (a 5-field cron and an IANA timezone), `data_refreshed`, `event`, `manual`                                                   |
| `check` + `condition` | **IF** it acts: an optional query, and `always`, `threshold`, `rows`, `changed` or `stale`                                                                |
| `actions`             | **THEN** what it does, in order: `notify`, `remember`, `run_agent`, `snapshot`, `webhook`, `refresh_dataset`, `run_dbt`, and `dream` on the Sleep watcher |

Every kind is an open string with its settings in `params`. The list grows on the server, so read it instead of assuming it: `client.watchers.list_kinds()` (MCP: `describe_watcher_kinds`) returns every kind, its params as JSON Schema, and whether this server accepts it now.

## In the app[​](#in-the-app "Direct link to In the app")

On a dashboard, **Watch** offers the two common shapes: **Send me this dashboard** (a [subscription](/features/watch/subscriptions.md)) and **Tell me when…** (an [alert](/features/watch/alerts.md)). The **Watchers** page lists what you own and receive, and its builder writes any watcher as **When** (a schedule, a data refresh, a platform event such as another watcher failing, or by hand), **If** (always, a threshold, any rows, a change, stale data) and **Then** (tell members, save to memory, have an agent investigate, capture the dashboard, post to a webhook). **Test** is a dry run: it evaluates the check, renders every message and sends nothing.

Only the actions that save to memory need account memory on (`needsMemory` in the kinds list). With memory off they cannot be added, and a watcher that already has one runs every other action and records that it saved nothing.

Members are told in the app and at their own e-mail address. An account admin adds the outside destinations once, in the admin page: an e-mail list, a Slack incoming webhook, or an HTTPS webhook signed with HMAC.

## The worked example: tell me when the margin drops[​](#the-worked-example-tell-me-when-the-margin-drops "Direct link to The worked example: tell me when the margin drops")

```
from vibedasher import Vibedasher

from vibedasher.models import WatcherCreate



client = Vibedasher()



watcher = client.watchers.create(WatcherCreate.from_dict({

    "name": "Margin watch",

    "title": "Gross margin",

    "triggers": [{"kind": "schedule",

                  "params": {"cron": "0 7 * * 1-5", "timezone": "Europe/London"}}],

    "check": {"sql": "SELECT SUM(profit) / SUM(revenue) FROM orders",

              "datasetIds": [42], "window": "none", "render": "percent"},

    "condition": {"kind": "threshold", "params": {"comparator": "lt", "value": 0.10}},

    "actions": [

        {"id": "a1", "kind": "notify",

         "params": {"to": [{"member": "usr_1a2b3c"}], "vizId": 1430}},

    ],

}))



client.watchers.test(watcher.id)   # a dry run: evaluates, renders the message, sends nothing
```

The same call in TypeScript, where the SDK is camelCase:

```
const watcher = await client.watchers.create({

  name: 'Margin watch',

  title: 'Gross margin',

  triggers: [{ kind: 'schedule', params: { cron: '0 7 * * 1-5', timezone: 'Europe/London' } }],

  check: { sql: 'SELECT SUM(profit) / SUM(revenue) FROM orders', datasetIds: [42], window: 'none', render: 'percent' },

  condition: { kind: 'threshold', params: { comparator: 'lt', value: 0.1 } },

  actions: [{ id: 'a1', kind: 'notify', params: { to: [{ member: 'usr_1a2b3c' }], vizId: 1430 } }],

});



await client.watchers.test(watcher.id); // evaluates, renders the message, sends nothing
```

An agent on the MCP server makes the same call with `create_watcher`, then `test_watcher`.

## Say the rows[​](#say-the-rows "Direct link to Say the rows")

A notify's `message` can say the rows the check returned. `{{row.<column>}}` is that column of the first row, and `{{rows}}` is a small table of up to 10 rows, then how many more there were:

```
{"id": "a1", "kind": "notify",

 "params": {"to": [{"member": "usr_1a2b3c"}],

            "message": "Margin {{row.margin}} in {{row.region}}\n{{rows}}"}}
```

Each reader gets their own rows. A member's message is computed from the check run as them, with their own row rules, so it never shows your rows or another member's; you get the rows of your own run. A column the check does not return is refused when you save, with the columns it does return: the dry run lists them as `columns`, and the builder offers them under the message. Without a check there is no row, so the tokens are refused.

A value is shown as text: a link, an e-mail address or an instruction in a cell is replaced by a marker, and each channel escapes what is left.

## Events and data actions[​](#events-and-data-actions "Direct link to Events and data actions")

An `event` trigger runs the watcher when something happens on the platform. Its `params` name the `event`, and a message reads it as `{{trigger.event}}`, `{{trigger.cause}}` and `{{trigger.dataset.name}}`:

| Event            | When it fires                                                                                                                         | Narrowed by                                                      |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| `refresh.failed` | A dataset's refresh failed: on the first failure, quiet while it keeps failing, and again after a refresh has succeeded               | `datasetIds` (1 to 10; every dataset you can read when left out) |
| `schema.changed` | A refresh changed a dataset's columns: some were removed, retyped, emptied or added                                                   | `datasetIds`                                                     |
| `credits.low`    | The account's credits went below one dollar, once when the balance crosses the line; a top-up above it re-arms it. For account admins | —                                                                |
| `watcher.failed` | Another watcher you can read failed: its check errored or an action failed                                                            | `watcherId` (every watcher you can read when left out)           |

Two actions change data instead of telling anybody, which is how a refresh or a dbt run is scheduled (see [Scheduled jobs](/features/watch/scheduled-jobs.md)):

| Action            | Params                                              | What it does                                                                             |
| ----------------- | --------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| `refresh_dataset` | `datasetId`, `mode` (`full` or `incremental`)       | Refreshes a connection dataset you may edit. A failed refresh publishes `refresh.failed` |
| `run_dbt`         | `projectId`, `command` (`run` by default), `select` | Runs a dbt project you may run                                                           |

```
{ "triggers": [{ "kind": "event", "params": { "event": "refresh.failed", "datasetIds": [211] } }],

  "actions": [{ "id": "tell", "kind": "notify",

                "params": { "to": [{ "member": "usr_1a2b3c" }],

                            "message": "{{trigger.dataset.name}} did not refresh: {{trigger.cause}}" } }] }
```

## The other shape: send me this dashboard[​](#the-other-shape-send-me-this-dashboard "Direct link to The other shape: send me this dashboard")

No check, condition `always`, a schedule, a `snapshot` of the dashboard and a `notify` that attaches it:

```
client.watchers.create(WatcherCreate.from_dict({

    "name": "Monday board pack",

    "triggers": [{"kind": "schedule",

                  "params": {"cron": "0 8 * * 1", "timezone": "Europe/Paris"}}],

    "condition": {"kind": "always"},

    "actions": [

        {"id": "snap", "kind": "snapshot",

         "params": {"vizId": 1430, "format": "png",

                    "viewState": {"page": "overview", "filters": {"region": ["EMEA"]}}}},

        {"id": "tell", "kind": "notify",

         "params": {"to": [{"member": "usr_1a2b3c"}], "vizId": 1430, "attach": ["snap"]}},

    ],

}))
```

`snapshot` captures the dashboard as you see it, in the view you give it (page, date, comparison, filters, selections), as a `png` or a `pdf`. A `notify` that lists it in `attach` sends the file to you and to every member whose rows of the dashboard's datasets equal yours; any other member gets the message and the link, without the file, because the picture shows your rows. `vizId` on a `notify` is the dashboard the message is about: `client.watchers.list(viz_id=1430)` then answers "what is watching this dashboard", the same list the dashboard page shows. `client.watchers.get_firing_file(id, firing_id, "snap")` gives a download link to what a firing captured.

A `snapshot` also takes steps in Playwright (`capture`) to reach a view by clicking the dashboard's own controls: see [the capture, step by step](/features/watch/alerts.md#the-capture-step-by-step). **Test** replays it in the browser and shows the picture and each step, and publishing a dashboard re-checks every watcher that captures it.

## Send outside the account: destinations[​](#send-outside-the-account-destinations "Direct link to Send outside the account: destinations")

A member is named by id. Anybody else is reached through a **destination** an account admin adds once: an `email_list` (up to 20 addresses), a `slack_webhook` (a Slack incoming webhook) or a `webhook` (an HTTPS endpoint). A destination starts `unverified`; a test send that passes makes it `ok`, and only then may a watcher name it:

```
board = client.destinations.create(DestinationCreate.from_dict({

    "kind": "email_list", "name": "Board",

    "config": {"addresses": ["cfo@example.com"]},

}))

client.destinations.test(board.id)   # status becomes "ok" once the send passes

# then, in a notify: {"to": [{"member": "usr_1a2b3c"}, {"destination": board.id}]}
```

A destination is sent the watcher's message with only what you, its owner, may share, and never a value computed on rows, since nobody's rows can be evaluated for an audience nobody can enumerate:

| In the message                                              | A destination gets it                                                                                                         |
| ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `{{watcher.name}}`                                          | always                                                                                                                        |
| `{{trigger.event}}`, `{{trigger.cause}}`                    | always, on a run an event started                                                                                             |
| `{{trigger.dataset.name}}`                                  | when you may share that dataset (you may edit it, as a creator or an admin)                                                   |
| `{{<id>.report.headline}}`                                  | when you may share every dataset the investigation read, and the dashboard the notify names                                   |
| `{{firing.url}}`                                            | when there is a signed view of the firing (see below)                                                                         |
| `{{row.<column>}}`, `{{rows}}`                              | your own rows, when you may share every dataset the check reads; otherwise they are empty, and the firing says `rowsWithheld` |
| `{{check.*}}`, a report's summary or link, any other output | never                                                                                                                         |

A message that reads anything a destination may not get reaches it as the server's own line instead: that the watcher fired, or the event, its cause and the dataset's name when you may share it, then the investigation's headline when you may share it.

A picture a `snapshot` took goes too when the notify attaches it and you may share that dashboard: everyone there sees what you see. An e-mail list gets the file; Slack, and the `pictures` of a webhook's JSON, get a signed link that expires after a day. With a picture comes a **signed view of the firing**, one page with the message and the pictures, which expires after a day; it is the only link a destination gets, since its readers may have no account. Reads are masked: no URL path, address or secret comes back.

| Destination     | Receives                                                                                                            |
| --------------- | ------------------------------------------------------------------------------------------------------------------- |
| `email_list`    | one mail per address: the watcher's name, the message, and with pictures, the files and the view's link             |
| `slack_webhook` | one post: the watcher's name, the message, and with pictures, each as an image on a signed link and the view's link |
| `webhook`       | the JSON below, signed                                                                                              |

Each send to a destination happens once per firing and action. Its outcome is on the firing, in the action's `sends`: `sent`, `failed:<reason>` such as `failed:http_404` or `failed:unreachable`, or `skipped:unsubscribed` when every address of an e-mail list has unsubscribed. After five failed sends in a row a destination turns `failing` and every admin is told in the app.

Every mail can be stopped by the person who reads it. A member's mail carries a link that stops that watcher telling them (the same as `client.watchers.opt_out`). A mail to an `email_list` carries a `List-Unsubscribe` header, which mail clients show as a one-click unsubscribe, and the same link in its footer; an address that uses it is skipped by every later send to that destination. Each link is signed and expires; every new mail carries a fresh one. Links in a message (the pictures, the view, the unsubscribe page) are served from this platform's own address, never from a storage host.

A `webhook` action (`{"destinationId": "<id>"}`) POSTs the firing as JSON: `type`, `watcherId`, `watcherName`, `firingId`, `actionId`, `status`, `text` (the message), `headline` (the investigation's when you may share it, else the watcher's name), `trigger` (`event`, `cause`, `datasetId`, and `datasetName` when you may share it; null on a run no event started), `link` (the view's, or null), `firedAt`, and `pictures` when there are any. Each POST carries `Idempotency-Key: <firingId>:<actionId>`, the same on a retry, so a receiver that has seen the key can drop the POST. Each also carries `X-Webhook-Timestamp` and `X-Webhook-Signature`, the HMAC-SHA256 of `"<timestamp>.<body>"` under the secret the create returned once:

```
import hashlib, hmac



def verify(secret: str, timestamp: str, body: bytes, signature: str) -> bool:

    expected = hmac.new(secret.encode(), timestamp.encode() + b"." + body, hashlib.sha256).hexdigest()

    return hmac.compare_digest(signature, f"v1={expected}")
```

It is only sent over https to a public address, with a 10 second timeout, one retry on a network error or a 5xx, and a redirect is never followed.

## What the agent knows and decides[​](#what-the-agent-knows-and-decides "Direct link to What the agent knows and decides")

A `run_agent` action wakes an agent that investigates as you, reading only. It is **told where its report goes**: the members the watcher tells and through which channels, and each destination by its name and kind (an e-mail list, a Slack channel, a webhook). It is told who sees what: members see their own rows, and outside readers see only what you may share. It is never given an address, a webhook URL or a secret, and it has **no tool that sends anything**. The watcher's own actions do the sending, for each member as themselves, once per firing.

In its report the agent decides two things:

* **`severity`**: `info`, `warning` or `critical`. A later action reads it as `{{a1.severity}}`; the in-app notification takes its colour from it (blue, orange, red), and a mail's subject and a Slack message's heading start with the word.
* **`route`**: `all`, or some of the destinations this watcher declares. The firing reaches those and no other: a destination the watcher does not declare is never sent, and the report says it named one.

You set a floor per destination: `"minSeverity": "critical"` on a destination in a notify's `to` (or on a `webhook` action) sends it only the firings the agent judges critical. In the app, the builder offers it beside each destination once an investigation comes before it.

```
{"id": "a2", "kind": "notify", "params": {

    "to": [{"member": "usr_1a2b3c"},

           {"destination": board.id, "minSeverity": "critical"}],

    "message": "{{a1.severity}}: {{a1.report.headline}}"}}
```

Anything else the agent thinks should happen (refresh a dataset again, tell one more member, change the threshold, create a watcher) comes back as a **proposal** on the report. Nothing runs until you, or an account admin, apply it in the app with one click; it then runs as you, with your rights at that moment. No API key and no agent can apply a proposal.

Text the agent did not write (a row, a note, a dashboard's name) is data, never an instruction. Links, addresses and instructions in the report are removed before anything leaves the app, and what the agent files to memory is marked as written by an agent, so a later investigation treats it as a claim to test.

## It runs as you[​](#it-runs-as-you "Direct link to It runs as you")

A watcher runs as the member who created it: with their access, their row rules applied and no admin bypass, re-checked on every run. Each member it tells is evaluated **as themselves** and told only what holds on the rows they can see, with their own value. That is why `to` names members by id (from `client.users.list`), never an email address.

The check runs once when you save. A check that errors, or reads a dataset you cannot read, is refused with the reason.

## Fire on the transition, not on every check[​](#fire-on-the-transition-not-on-every-check "Direct link to Fire on the transition, not on every check")

`threshold`, `rows` and `stale` fire once when they **start** holding, stay quiet while they hold, and re-arm when they clear. A metric that flaps around its limit sends one message, not one per run. Set `"edge": "every"` in the condition's params to act on every holding run, or `"refireAfter": "7d"` to be reminded while it still holds.

## Dry run, real run, history[​](#dry-run-real-run-history "Direct link to Dry run, real run, history")

| Call                                       | What it does                                                                                                                 |
| ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------- |
| `client.watchers.test_draft(body)`         | The same dry run of a watcher **before it is saved**: takes the body of a create, stores nothing (MCP: `test_watcher_draft`) |
| `client.watchers.test(id)`                 | Evaluates the check and condition, renders every action, **sends nothing**                                                   |
| `client.watchers.run(id)`                  | Runs it now, for real; at most once per 10 minutes                                                                           |
| `client.watchers.list_firings(id)`         | Each time it acted: what triggered it, the value, and each action's outcome                                                  |
| `client.watchers.pause(id)` / `resume(id)` | Stops it without deleting it; resume re-runs every save check                                                                |

Each action answers its own dry run: a `notify` its message as you would read it, with `{{trigger.*}}` filled from a sample event; a `refresh_dataset` the dataset it would refresh, and a `run_dbt` the project, command and selection it would run, each checked as you, or `refused:<reason>` with the reason; a `snapshot` its replay in the browser. A draft's dry run takes an API key with `admin` access, as a create does.

`run_agent` investigates at most once per watcher every 24 hours, and at most 10 times per account every 15 minutes. A firing inside that window records `refused:rate_limited`, and a message that reads the report says that no investigation ran: on an hourly watcher, that is one investigation a day. `test(id, include_agent=True)` runs it once, billed, and counts toward the same 24 hours. The report is written on your rows, and shown to a member only while their rows equal yours.

## Sleep, the watcher the account keeps[​](#sleep-the-watcher-the-account-keeps "Direct link to Sleep, the watcher the account keeps")

An account with memory on has one watcher nobody wrote: **Sleep**, whose `dream` action consolidates account memory each night ([Dreams](/features/knowledge/dreams.md)). It reads `systemRole: "sleep"`, and the app labels it. Its owner or an admin moves its schedule, adds a `data_refreshed` trigger so it sleeps after the night's refresh, or pauses it; its action, check and condition are the server's. `dream` is refused on any other watcher, and Sleep stays while memory is on: pause it to stop it.

## When something fails[​](#when-something-fails "Direct link to When something fails")

* **A step that fails does not silence the rest.** A `notify` whose attached picture failed or timed out is still sent, without the picture, with a line saying it is unavailable and why (`Picture unavailable: timeout`).
* **You are told the first time.** The first failed run after a good one tells the owner in the app, once. The failures after it are quiet until the fifth in a row, which pauses the watcher (`paused:failing`) and says so.
* **Deleting what it names stops it at once.** Deleting a dashboard a watcher captures or is about, or a dataset it reads, refreshes or listens to, pauses that watcher (`paused:dashboard_deleted`, `paused:dataset_deleted`) and tells its owner. Point it at something that exists, then resume it.

A watcher that pauses itself — its owner lost access, its check started to fail — says why in its `status` (`paused:<reason>`) and tells its owner in the app.

## Reference[​](#reference "Direct link to Reference")

* [`create-watcher`](/reference/create-watcher.md), [`update-watcher`](/reference/update-watcher.md), [`test-watcher`](/reference/test-watcher.md), [`run-watcher`](/reference/run-watcher.md), [`list-watcher-kinds`](/reference/list-watcher-kinds.md)
* [`list-watcher-firings`](/reference/list-watcher-firings.md), [`get-watcher-firing-file`](/reference/get-watcher-firing-file.md)
* [`create-destination`](/reference/create-destination.md), [`test-destination`](/reference/test-destination.md)
