diff --git a/docs/good-fences-slides.md b/docs/good-fences-slides.md new file mode 100644 index 0000000..139806a --- /dev/null +++ b/docs/good-fences-slides.md @@ -0,0 +1,264 @@ +--- +title: Good Fences Make Good Agents +type: slide +slideOptions: + transition: slide +--- + +# Good Fences Make Good Agents + +*with apologies to Robert Frost* + +Dan Connolly · Oct 2026 + +--- + +## ✅ TADA: Monday's roundup drafts itself + +On potluck's dashboard: **Draft 2026-W41 from diigo**, one click. + +- a week of my shared diigo bookmarks → a draft issue +- a paragraph per bookmark, with its description and tags +- I edit instead of copy-pasting links + +[Weekly PESOS, madmode-blog#23](https://github.com/dckc/madmode-blog/issues/23) + +--- + +## How: who holds what (on main, in dev) + +![weekly roundup wiring](weekly-roundup-wiring.png) + +- ✨ the cache id is a **webkey**, kept in my password manager +- ✨ diigo-week reaches only the read-only `viewer`: an h-feed of public items +- ⏳ not deployed yet; a fresh cookie means a new access and a new cache + +--- + +## ✨ Rotating the cookie (designed, on a branch) + +![cookie rotation wiring](cookie-rotation-wiring.png) + +- the cookie lives in Alice's store; `access` reads a read-only facet at every send +- Mallory, holding the instance id, can use the cookie but can't rotate it + +--- + +## It's one piece of a toybox + +| story | source | sink | trigger | +|---|---|---|---| +| S1 weekly roundup | diigo, public only | madmode draft | weekly, human edits | +| S2 album to album | **one** Google Photos album | **one** Amazon folder | each insert, nobody watching | +| S3 drag to archive.org | Google Photos | archive.org | drag-and-drop | + +Recurring needs: **narrowed capabilities** and **confined generated code**. + +--- + +## The toy version: lend a mower + +```js +client.chat.completions.create({ + messages: [{ + role: 'user', + content: 'you can use this mower for the weekend', + things: { mower }, + about: { mower: { ts: 'type Mower { start(), push(), turn(), stop() }' }} + }], +}); +``` + +- the neighbor writes code; a **tenant** runs it in a dynamic worker, endowed with only `mower` +- I lend a **governed** mower: never more than 100 yards (10 cells) from where it started + +--- + +## The fence + +```mermaid +sequenceDiagram + participant T as tenant + participant G as governed mower + participant M as mower DO + T->>G: push() + G->>M: push() + T->>G: push() + G->>M: push() + T->>G: push() + G-->>T: throws 'fence: 2 cells from start' +``` + +⏳ the governor is designed ([lend-the-mower](../good-fences/docs/lend-the-mower.md)), not built + +--- + +## ✨ The model writes code to mow + +gpt-oss-120b on Workers AI, given `about.mower` and the story; the test reads the code it writes: + +```js +async (env) => { + const { mower } = env; + mower.start(); // cuts the starting cell + for (let c = 0; c < cols; c++) { + for (let i = 0; i < rows - 1; i++) { + mower.push(); // cut next cell + } + ... + } + await mower.stop(); // wait for the whole batch to finish +``` + +✨ no `await` per call: promise pipelining, after one `lamp` example in the prompt + +--- + +## 🪄 A little tipsy + +```js + if (c < cols - 1) { + calls.push(env.mower.turn()); // turn right + calls.push(env.mower.push()); // step into next column + calls.push(env.mower.turn()); // turn right again (now facing opposite way) + } +``` + +- going north: right, step east, right → facing south ✅ +- going south: right, step **west**, right → facing north 🐛 +- run, it would mow two columns, back and forth: "mowed 2401 cells" + +--- + +## 🙌 Then: Project Think + +| ours | [Project Think](https://blog.cloudflare.com/project-think/) | +|---|---| +| the neighbor's harness | a `Think` agent: a DO with sessions, model, prompt, tools | +| `code-mode.ts`, `about` | `@cloudflare/codemode`: the model writes code against types | +| tenants in dynamic workers | `DynamicWorkerExecutor`, `globalOutbound: null` | + +"no ambient authority; capabilities granted explicitly via bindings" + +--- + +## ✅ Green + +``` +⬜⬜⬜⬜⬜⬜⬜⬜ +⬜🟩🟩🟩🟩🟩🟩⬜ +⬜🟩⬜⬜⬜⬜🟩⬜ +⬜🟩⬜⬜⬜⬜🟩⬜ +⬜🟩⬜⬜⬜⬜🟩⬜ +⬜🟩⬜⬜⬜⬜🟩⬜ +⬜🟩⬜⬜⬜⬜🟩⬜ +⬜🟩⬜⬜⬜⬜🟩⬜ +⬜🟩⬜⬜⬜⬜🟩⬜ +⬜🟩⬜⬜⬜⬜🟩⬜ +⬜🟩⬜⬜⬜⬜🟩⬜ +⬜🟩🟩🟩🟩🟩🟩⬜ +⬜⬜⬜⬜⬜⬜⬜⬜ +``` + +model → generated code → sandbox → mower: 36 calls, 30 cells + +--- + +## 🧰 …with ceremony + +The mower, as a codemode connector: + +```ts +protected tools(): ConnectorTools { + const mower = this.#mower; + return { + start: { description: "put the mower down, facing north, and cut the cell under it", execute: () => mower.start() }, + push: { description: "move forward one cell, cutting the cell it enters", execute: () => mower.push() }, + turn: { description: "turn right 90 degrees, in place", execute: () => mower.turn() }, + stop: { description: "park the mower", execute: () => mower.stop() }, + }; +} +``` + +What the model ran, 7 `execute` calls: + +```js +await codemode.search('mower') +await state.readdir({ path: '/' }) +await codemode.search('lawn') +await codemode.describe('mower.start') +await codemode.describe('mower.push') +await codemode.describe('mower.turn') +await mower.start({}); for (...) await mower.push({}); ... +``` + +--- + +## 🧱 Not methods on objects + +[Code Mode](https://blog.cloudflare.com/code-mode-mcp/) turns **tools** into a TypeScript API. + +- JSON in, JSON out: no reference goes in, no object comes back +- so a neighbor can't hand what it holds to the next neighbor + +One floor down, Workers RPC and Cap'n Web do pass references and pipeline calls. + +--- + +## 🧱 Identity, in two halves + +| | durable | passable | +|---|---|---| +| Durable Object id | ✅ | ❌ a string plus a binding the receiver must already hold | +| Workers RPC / Cap'n Web stub | ❌ dies with its request or session | ✅ | +| Endo / OCapN reference | ✅ | ✅ | + +> durable, passable object identity. I've been using endo for so long that it just feels like air to me. + +--- + +## 🧱 Where it bites + +- S2, album to album: **nobody watching**, so no session to keep a stub alive +- a scavenger hunt: a kid buys a Pete Rose card from the shopkeeper → it admits him to the clubhouse → Sam's telescope there reads a QR code a mile away → step 7 → he wins a bicycle + - every hop is a reference, held for years + - is the card genuine? the clubhouse has to ask its issuer + +--- + +## The turn: Cloudflare as a netlayer + +OCapN on top: sturdyrefs for durability, live refs within a session, third-party handoffs. + +| their technique | ours, on references | +|---|---| +| code mode against generated types | code against `about` for the objects it holds | +| `search` / `describe` over many tools | a petname directory the model can browse | +| saved snippets | tenant code exported as an entrypoint, handed on | +| `runFiber` / `stash` | vat persistence | +| sub-agents as DO facets | tenants as child vats | + +Still load-bearing: Worker Loader, Durable Objects and facets, Workers RPC, Cap'n Web, Workers AI. + +--- + +## 🧮 Retro + +✅ the weekly roundup drafts in one click +✨ webkeys in a password field; a read-only facet for the plugin +✨ model-written code pipelines, in a confined dynamic worker +🙌 Project Think: a green spike in an evening + +⏳ nothing deployed; the governor not built +🪄 tipsy tenants: always turn right +🧰 codemode ceremony: `{ description, execute }`, `search`, `describe` +🧱 no durable, passable references: an OCapN layer to build + +--- + +## Sources + +- [Good Fences Make Good Agents: design story and IBIS](good-fences-make-good-agents.md) +- [toybox user stories](../toybox-stories.md) +- [Project Think](https://blog.cloudflare.com/project-think/) · [Code Mode](https://blog.cloudflare.com/code-mode-mcp/) +- [OCapN](https://ocapn.org/) · [Cap'n Web](https://github.com/cloudflare/capnweb)