Skip to content

Other hosts

A Pi harness needs three things from where it runs: a storage only it owns, somewhere for the coding tools to work, and, for code mode, somewhere to run scripts. On a Durable Object those are the object’s SQLite, a sandbox and the object’s own thread. On a long-lived machine they are a file, the machine itself and a worker thread. The harness, its models and its tools don’t change.

Pi.SqliteFile keeps conversations in a SQLite file. Pi allows one owner per storage, so the file must belong to one process: a Fly Machine with a volume, an ECS task on EFS, a container with a mounted disk.

const StorageLive = Pi.SqliteFile("/data/pi.sqlite");

A machine is not evicted while it has work, so there is no alarm. The harness resumes unfinished runs once, when the process starts and first opens it.

Pi.LocalEnv runs the coding tools on the machine itself, in place of a sandbox:

const CodingToolsLive = Pi.CodingTools.pipe(
Layer.provideMerge(Pi.LocalEnv({ cwd: "/workspace" })),
);

Every conversation then works in the same file system. Give each one its own cwd to keep them apart:

yield* harness.createConversation({ name: "pr-142", cwd: "/workspace/pr-142" });

AI.EvalQuickJS() runs code mode programs in QuickJS on a worker thread, so a long script doesn’t block the process:

const CodeModeLive = AI.CodeModeAsync.pipe(Layer.provide(AI.EvalQuickJS()));

The Layers for a machine, composed once:

src/layers.ts
import * as AI from "@alchemy.run/ai";
import * as Pi from "@alchemy.run/pi";
import * as Layer from "effect/Layer";
import { FastLive } from "./models.ts";
import { AddLive } from "./Add.tool.ts";
export const HarnessLive = Layer.mergeAll(
FastLive,
AddLive,
Pi.SqliteFile("/data/pi.sqlite"),
Pi.CodingTools.pipe(Layer.provideMerge(Pi.LocalEnv({ cwd: "/workspace" }))),
AI.CodeModeAsync.pipe(Layer.provide(AI.EvalQuickJS())),
);

All of these need Node.js or Bun.

Pi.MemoryStorage keeps conversations in memory and loses them when the process ends:

const TestLive = Layer.mergeAll(FastLive, AddLive, Pi.MemoryStorage);