| 1 | # PiHarness |
| 2 | |
| 3 | This example runs the experimental `PiHarness` from Cloudflare Agents pull |
| 4 | request 2197 in a celld Durable Object. The example calls Cloudflare Workers AI |
| 5 | through the OpenAI-compatible endpoint, and it selects Llama 3.2 1B by default. |
| 6 | |
| 7 | Celld serves no Workers AI binding, so the example owns its credentials. It |
| 8 | reads `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` from the Worker |
| 9 | variables, and it builds the adapter that the pi provider needs. The example |
| 10 | stops at startup when either variable is absent, because a stand-in model |
| 11 | answers every prompt and therefore hides a broken configuration. |
| 12 | |
| 13 | The `agents` package on npm does not contain `PiHarness`, therefore this example |
| 14 | depends on a preview build of pull request 2197. The preview build can change or |
| 15 | expire, so an install can fail until that pull request is released. |
| 16 | |
| 17 | Install the dependencies, pass the credentials as Worker variables, then start |
| 18 | the example from this directory: |
| 19 | |
| 20 | ```sh |
| 21 | npm ci |
| 22 | |
| 23 | CELLD_VAR_CLOUDFLARE_ACCOUNT_ID="your-account-id" \ |
| 24 | CELLD_VAR_CLOUDFLARE_API_TOKEN="your-token" \ |
| 25 | celld dev . |
| 26 | ``` |
| 27 | |
| 28 | A `CELLD_VARS_FILE` entry works too, and it keeps the token out of the shell |
| 29 | history. |
| 30 | |
| 31 | Run a prompt and inspect the persisted transcript: |
| 32 | |
| 33 | ```sh |
| 34 | curl http://127.0.0.1:9876/ |
| 35 | curl http://127.0.0.1:9876/messages |
| 36 | ``` |
| 37 | |
| 38 | The prompt route answers 200 for a completed run, and 502 with the reported |
| 39 | errors for a failed one. |
| 40 | |
| 41 | The Durable Object storage holds the transcript, so the state survives a |
| 42 | restart. A model change does not migrate that state, therefore start again with |
| 43 | `celld dev --clean .` after you edit `PI_MODEL`. |