Diffinery

homeflare/celldpublic

celld/examples/pi/README.md
44 lines · 1.7 KBRaw History
1# PiHarness
2
3This example runs the experimental `PiHarness` from Cloudflare Agents pull
4request 2197 in a celld Durable Object. The harness needs a model, and the
5example gets one from any OpenAI-compatible chat completions endpoint. It
6uses OpenRouter and Llama 3.2 1B by default.
7
8The pi provider expects the `ai.run()` shape of a Workers AI binding, and celld
9serves no such binding, so the example builds a small adapter that posts each
10request to `PI_ENDPOINT` with `OPENROUTER_API_KEY` as the bearer token. The
11example stops at startup when a variable is absent, because a stand-in model
12answers every prompt and therefore hides a broken configuration. Set
13`PI_ENDPOINT` and `PI_MODEL` in `wrangler.jsonc` to use a different provider,
14such as a local server.
15
16The `agents` package on npm does not contain `PiHarness`, therefore this example
17depends on a preview build of pull request 2197. The preview build can change or
18expire, so an install can fail until that pull request is released.
19
20Install the dependencies, write the key to a `.dev.vars` file in this
21directory, then start the example. The `agents` package declares many peer
22dependencies that the example does not use, so leave them out:
23
24```sh
25npm install --legacy-peer-deps
26
27echo 'OPENROUTER_API_KEY=sk-or-...' > .dev.vars
28
29celld dev .
30```
31
32Run a prompt and inspect the persisted transcript:
33
34```sh
35curl http://127.0.0.1:9876/
36curl http://127.0.0.1:9876/messages
37```
38
39The prompt route answers 200 for a completed run, and 502 with the reported
40errors for a failed one.
41
42The Durable Object storage holds the transcript, so the state survives a
43restart. A model change does not migrate that state, therefore start again with
44`celld dev --clean .` after you edit `PI_MODEL`.