Skip to content
bits
Your first agent loop · Lesson 9 of 9 · 20 min

Checkpoint: Klippy, the agent

Desk: best at a computer, with a terminal

Verified wrangler 4.157.0agents 0.33.0@cloudflare/ai-chat 0.12.2ai 7.0.162

Start from c-08 on GitHub. Starting here, or behind? Get the code at that tag:

Shell
git clone https://github.com/ryanyogan/klippy
cd klippy
git checkout c-08
Tutor:

Klippy is an agent now. One per person, a chat in your terminal, facts that outlive the chat, a y/n before it writes, limits on runaway loops and pages, and reminders that speak on their own. Time to tour it, ship it, and let bits check it.

Tutor:

1. Name the tag

The only code change: bits reads the tag from /klippy/check. In apps/agent/src/check.ts (and its test, test/check.spec.ts):

// The lesson tag this code is at. bits reads it to see how far your Klippy has come.
export const TAG = 'c-09';
TypeScriptUTF-8at c-09● lines 2–2: apps/agent/src/check.ts
Tutor:

Run pnpm test: all 64 tests should pass. If the rate-limit test fails once, run it again: it counts in 60-second windows, and a run that crosses a window boundary can miss its 429 (fixed on Klippy's main).

Tutor:

2. The tour

Every lesson in one chat, locally. Ours (the Workers AI fallback answered, not Claude; input piped, so the y doesn't echo):

recorded output
(printf "Hi, I am Ryan and I live in Dublin. Please remember that.\n/clear\nWhat should I wear today?\nSave a note: renew my passport.\ny\nRemind me in one minute to stretch.\n"; sleep 100) | KLIPPY_URL=http://localhost:8801 pnpm chat ryan-c09
Talking to Klippy "ryan-c09" (8 messages so far). /clear to start over, Ctrl+D to quit.
you> klippy> Got it, Ryan! I've remembered that you live in Dublin.
you> (chat cleared)
you> klippy> What type of clothing works for you (e.g., shirt, pants), and where will you be going? Then I can look up the Dublin weather and suggest appropriate garments.
you> klippy>
Klippy wants to use saveNote with {"body":"renew my passport"}. Allow? (y/n) klippy> Got it. I’ve saved your note: "renew my passport" (ID 16).
you> klippy> QiDone! I’ll message you in one minute to stretch.
you>
klippy> Go stretch!
Tutor:

Read it honestly:

  • Memory worked: after /clear, it still knew Dublin.

  • But it asked instead of acting. With Dublin known, a good answer calls getWeather. The free model asked a question; we expect Claude to do better, and will re-record once we have a key.

  • "QiDone!" is the fallback model's stray output, kept as recorded.

  • The last line came by itself, a minute later.

Tutor:

3. Ship it

In apps/agent:

Shell
pnpm wrangler deploy

The first deploy with the Klippy Durable Object applies its migration (v1, new_sqlite_classes) for you. Your KLIPPY_TOKEN secret and the remote D1 table are already there from earlier courses. Then talk to the live one:

Shell
KLIPPY_URL=https://klippy.<your-subdomain>.workers.dev pnpm chat me

What we recorded, and what we didn't. We haven't deployed the reference Klippy, so there's no recorded live deploy. Our dry run shows what goes up, with the Durable Object binding new since course B:

recorded output
pnpm wrangler deploy --dry-run
Total Upload: 3679.00 KiB / gzip: 711.85 KiB
Your Worker has access to the following bindings:
Binding Resource
env.Klippy (Klippy) Durable Object
env.DB (klippy-db) D1 Database
env.AI AI
env.LIMITER (10 requests/60s) Rate Limit
--dry-run: exiting now.
Tutor:

And the check, locally:

recorded output
curl -s 'http://localhost:8801/klippy/check?nonce=checkpoint-c09'
{"nonce":"checkpoint-c09","tag":"c-09","probe":{"answer":"Hello, bits!","model":"@cf/zai-org/glm-4.7-flash"}}
Tutor:

4. Let bits check it

Paste your Worker's address. bits calls /klippy/check on it and looks for this checkpoint's tag.

deploy check+60 neurons

Goal Your Klippy is live at this checkpoint: /klippy/check answers with bits' nonce and tag c-09 (or a later one)

Paste the https://….workers.dev address that wrangler deploy printed.

bits calls /klippy/check?nonce=bits-checkpoint-c09 on your Worker, from bits’ server

  • /klippy/check?nonce=bits-checkpoint-c09 answers 200 OK, not yet
  • Answers the check, not yet
  • Echoes bits' nonce, not yet
  • Is at c-09 or later, not yet

Sign in to check your deploy: the check is saved to your account, and a certificate can link it.

Tutor:

A pass proves a Worker at that address answers the way this lesson asks. It doesn't prove who wrote it.

quick check+20 neurons
Tutor:

A reminder fires. Which tools can Klippy use in that turn?

    Pick one option

    Pick one, then Check.

    Tutor:

    That's Klippy, the agent. Your code matches tag c-09 (changes from c-08). In the next course, you'll give it a face: a web front end, built by directing Claude Code.