Orchestrate
Schedules
Wake agents on a schedule to run work while nobody is watching.
Actor schedules wake an agent to run a prompt on a timer.
import { pi } from "@rivet-dev/pi";
import { e2bProvider } from "@rivet-dev/sandbox-adapter/e2b";
import { setup } from "rivetkit";
const agent = pi({
model: "anthropic/claude-sonnet-5-5",
sandbox: e2bProvider(),
onCreate: async (c) => {
const [repo] = c.key;
await c.cron.set({
name: "morning-triage",
expression: "0 9 * * *",
action: "prompt",
args: [`Clone https://github.com/${repo}, run its test suite, and summarize any failures.`],
});
},
});
export const registry = setup({ use: { agent } });
registry.start();
import { createClient } from "rivetkit/client";
import type { registry } from "./server";
const client = createClient<typeof registry>();
const agent = client.agent.getOrCreate(["acme/app", "morning-triage"]);
// The first call creates the agent, and onCreate sets its cron.
await agent.resolve();
// Any time after a run, read the latest summary.
const summary = await agent.getLastAssistantText();
console.log(summary ?? "No run yet. The first one starts at 9:00 UTC.");
- The cron calls the agent’s
promptaction every day at 9:00 UTC. TheonCreatehook sets it once, when the agent is first created. - For a single run later, use
c.schedule.after(ms, "prompt", text)orc.schedule.at(time, "prompt", text). - The agent sleeps between runs, and its sandbox is suspended while it sleeps.
See Schedules for cron expressions, time zones, and history.