# Recipe: Write Your First Wake (/blog/recipe-first-wake)

2026-07-12 · kestrel.markets

## Answer card

A `WAKE` is a standing, event-driven subscription over Kestrel's trigger algebra. It watches a condition (say `velocity(1m) > p99`) and when that condition fires, it delivers a `VIEW` (a compact text Frame) to your agent. It spends **attention** (tokens, wakes), never **risk**: a wake can never open, size, or move a position. Below: the four-line recipe, the delta Frame it emits, and the one-line wake budget that keeps you from getting spammed.

## What you're building

You want your agent to notice a thing without watching the tape. Polling burns tokens on bars where nothing happens: `O(screen)` cost for `O(0)` information. A `WAKE` inverts that: the runtime watches, and only pays your agent's attention when the market crosses a line you drew. This is the attention statement in Kestrel's four-kind core (`VIEW`, `WAKE`, `PLAN`, `GRADE`). It perceives and pings. It does not trade; that's `PLAN`'s job.

## Step 1: Draw the line (the trigger)

The trigger algebra is `series x predicates x AND/OR/NOT`. Percentile anchors like `p99` are computed over the series' own recent distribution, so `velocity(1m) > p99` reads as: *the last minute's move is faster than 99% of recent minutes.* Generic instrument throughout; illustrative only.

```kestrel
USING signal SPX
WAKE vol-spike
  WHEN velocity(1m) > p99
  DELIVER delta-tape
  BUDGET 12 wakes/day
```

That's the whole subscription. `velocity(1m) > p99` is the line. `delta-tape` is the `VIEW` it hands you. `BUDGET 12 wakes/day` is the leash.

## Step 2: Define what gets delivered (the View)

A `WAKE` delivers perception, not an alert string. The `VIEW` renders the market as a Frame: the chart is in text, a vertical append-only tape, one row per candle, newest last, relative candles in basis points versus the prior close. Because it's append-only, the wake ships a **delta frame**: only the new bars since your agent last looked, plus the keyframe anchor. Perception cost is `O(new bars)`, not `O(screen)`; KV-cache-friendly.

```kestrel
VIEW delta-tape budget 300
  tape 1m last 8m bps
  keyframe open
  level p99 velocity
```

## Step 3: Set the wake budget (spend attention deliberately)

`BUDGET n wakes/day` caps how many times this subscription is allowed to spend your agent's attention. Hit the cap and the wake goes quiet until the next session: no runaway token bill on a choppy day. This is the whole point of separating attention from risk: you can be generous with a `PLAN`'s risk envelope and stingy with a `WAKE`'s wakes, or the reverse, because they draw on different budgets.

## Step 4: What firing looks like

When `velocity(1m)` crosses `p99`, the runtime pushes a delta frame. Illustrative shape:

```text
# WAKE vol-spike fired  09:47:12  (wake 3/12 today)
tape 1m  bps vs prior close  keyframe 09:30 = 5031.20
  09:44   +6
  09:45   +9
  09:46  +14
  09:47  +38   <- velocity(1m) p99 crossed
```

Eight bars became four new rows. Your agent reads the delta, decides whether it cares, and, if it does, that's when it might arm a `PLAN`. The wake informed; it did not act.

## Where a Wake is NOT the fit

- **You need to act in milliseconds.** A `WAKE` wakes your agent, and the agent is slow by design. Reflexes belong in a `PLAN`: the runtime fires it and informs you in parallel (`fire-then-inform`; the agent is never in the hot path).
- **You want continuous monitoring of a slow-moving level.** If you'd rather just read the tape on your own cadence, call the `VIEW` directly. A `WAKE` earns its keep only when the *event* matters more than the schedule.
- **You're trying to express risk.** A `WAKE` structurally cannot open risk. If you catch yourself wanting one to "just enter here," you want a `PLAN`.

## Run it

Kestrel is the open-source language and runtime: a wake authored here validates in a free `SIM` session on kestrel.markets with no account and no card (`proof-before-account`), and the certified Blotter records every fire. Anonymous trial sims, certified Grades, shareable proof URLs, and 402 Offers run today; the free tier needs no signup. The wake grammar above is the stable core.

> A WAKE spends attention, never risk: it delivers a Frame when the market crosses a line you drew, and stays silent, and free, every bar it doesn't.
