AGENT / PATTERNSSOURCE ↗

A FIELD GUIDE · 0.0.1

Use tokens to
build the things.

A small catalog generated only from runnable examples with live Cloudflare deployment receipts.

RUNNABLE SOURCE→LIVE HTTPS PROBE→SANITIZED RECEIPT
01

Bound every loop

A Cloudflare Worker enforces turn and token reservations around real Workers AI calls.

Use when

An agent iterates over model calls and must have a programmatic maximum cost.

Mechanism

  1. Bind Workers AI directly to the deployed Worker with Alchemy.
  2. Reserve the declared token allowance before every model inference.
  3. Return real model outputs with a typed, asserted stop reason.
if (tokens + tokensPerTurn > maxTokens) return result('token-budget');
tokens += tokensPerTurn;
const inference = await env.AI.run(MODEL, { prompt, max_tokens: tokensPerTurn });
outputs.push(inference.response);

EVIDENCE POLICY

Prove it or omit it.

Source
Runnable Worker code.

Deploy
Isolated Alchemy stage.

Probe
Live HTTPS assertions.

Cleanup
Destroy in a finally trap.