Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/docs/architecture.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ A conversation is idle until a prompt starts a run, and goes back to idle when t

An idle agent sleeps and frees its memory. The next action on its key wakes it: the agent opens Pi from SQLite, resumes interrupted work, and reconnects to the same sandbox the first time a tool needs it, so clients don't do anything different. While the agent sleeps, its sandbox is suspended.

During a retry or poll wait longer than a minute, the Actor also sleeps, and a scheduled wake resumes the work when the wait ends.
During a retry or poll wait, the Actor also sleeps, and a scheduled wake resumes the work when the wait ends.

<div style="overflow-x:auto">
<svg viewBox="0 0 640 280" role="img" aria-label="The agent loop runs in memory and saves each step to the Actor&#x27;s SQLite database, which also holds the sandbox id. On wake, the loop is restored from SQLite and reconnects to the same sandbox. Sleep, a crash, or an upgrade clears memory, and SQLite is kept." style="width:100%;min-width:520px;max-width:640px;height:auto;display:block;margin:2.5rem auto;font-family:system-ui,sans-serif">
Expand Down
2 changes: 1 addition & 1 deletion docs/content/docs/pi.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ A fork with `fork: "current"` starts with a copy of the document. Clients can al

- When you ship new code, running work gets up to `sleepGracePeriod` (15 minutes) to finish before the Actor restarts.
- Anything cut off resumes from its last saved step, after your `onWake` runs.
- A retry wait longer than a minute lets the Actor sleep, and a scheduled wake resumes it.
- A retry wait lets the Actor sleep, and a scheduled wake resumes it when the wait ends.
- Destroying the Actor stops it immediately.

See [Architecture](/agents/docs/architecture).
Expand Down
2 changes: 2 additions & 0 deletions examples/docs/durable-ai-agents/chat-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const Plan = defineDoc<{ steps: { text: string; done: boolean }[] }>({
history: "latest",
fork: "current",
initial: () => ({ steps: [] }),
// Store the whole document every 50 changes, so loading it replays at most 50.
checkpointWhen: (_value, _ops, { deltasSinceBase }) => deltasSinceBase >= 50,
});

const updatePlan = defineTool({
Expand Down
8 changes: 4 additions & 4 deletions examples/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
},
"dependencies": {
"@daytonaio/sdk": "^0.216.0",
"@earendil-works/chord": "1.3.0",
"@earendil-works/pi-ai": "1.3.0",
"@earendil-works/pi-coding-agent": "1.3.0",
"@earendil-works/pi-durable": "1.3.0",
"@earendil-works/chord": "1.4.0",
"@earendil-works/pi-ai": "1.4.0",
"@earendil-works/pi-coding-agent": "1.4.0",
"@earendil-works/pi-durable": "1.4.0",
"@hono/node-server": "^2.1.5",
"@linear/sdk": "^97.0.0",
"@octokit/rest": "^22.0.1",
Expand Down
2 changes: 2 additions & 0 deletions examples/docs/pi/documents/chambers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export const Chambers = defineDoc<{ solved: string[] }>({
history: "latest",
fork: "current",
initial: () => ({ solved: [] }),
// Store the whole document every 50 changes, so loading it replays at most 50.
checkpointWhen: (_value, _ops, { deltasSinceBase }) => deltasSinceBase >= 50,
});
16 changes: 9 additions & 7 deletions packages/pi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,22 @@
"test": "vitest run"
},
"dependencies": {
"@earendil-works/pi-coding-agent": "^1.0.4",
"@earendil-works/pi-coding-agent": "^1.4.0",
"@opentelemetry/api": "^1.1.0",
"@rivet-dev/sandbox-adapter": "workspace:*"
},
"peerDependencies": {
"@earendil-works/chord": "^1.0.0",
"@earendil-works/pi-ai": "^1.0.0",
"@earendil-works/pi-durable": "^1.0.0",
"@earendil-works/chord": "^1.4.0",
"@earendil-works/pi-ai": "^1.4.0",
"@earendil-works/pi-durable": "^1.4.0",
"@earendil-works/pi-telemetry": "^1.4.0",
"rivetkit": ">=2.3.28 <2.4.0"
},
"devDependencies": {
"@earendil-works/chord": "1.3.0",
"@earendil-works/pi-ai": "1.3.0",
"@earendil-works/pi-durable": "1.3.0",
"@earendil-works/chord": "1.4.0",
"@earendil-works/pi-ai": "1.4.0",
"@earendil-works/pi-durable": "1.4.0",
"@earendil-works/pi-telemetry": "1.4.0",
"@opentelemetry/sdk-trace-node": "2.11.0",
"@types/node": "^24.0.0",
"rivetkit": "2.3.30",
Expand Down
5 changes: 3 additions & 2 deletions packages/pi/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
documentsByKind,
type PiOptions,
piRuntime,
resumeDueSleeps,
type Waiting,
withHarness,
} from "./runtime.js";
Expand Down Expand Up @@ -493,8 +494,8 @@ export function createPiActions(options: PiOptions) {
}),

pi: {
/** Scheduled at the end of a long wait. Opening the harness resumes the waiting work. */
wake: (c: PiContext) => run(c, async () => {}),
/** Scheduled for Pi Durable's earliest sleeping task. Resumes the tasks that are due. */
wake: (c: PiContext) => run(c, () => resumeDueSleeps(c)),
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/pi/src/answers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type PiOnAnswer = (
) => void | Promise<void>;

/** The extension that runs `onAnswer`. Conversations that use the default selection get it. */
const ANSWER_EXTENSION = "rivet-pi-on-answer";
export const ANSWER_EXTENSION = "rivet-pi-on-answer";

/**
* The app's registry and settings plus an extension whose `onYield` hook calls
Expand Down
Loading
Loading