Skip to content
GitHub Get Started
Agent

Pi

server.ts
import { agentOs } from "rivetkit/agent-os";
import { setup } from "rivetkit";
import common from "@rivet-dev/agent-os-common";
import pi from "@rivet-dev/agent-os-pi";
const vm = agentOs({
options: { software: [common, pi] },
});
export const registry = setup({ use: { vm } });
registry.start();

Read Sessions first for session options, streaming events, prompts, and lifecycle management.

Pi supports extensions that let you register custom tools, modify the system prompt, and hook into agent lifecycle events. Write a .js file into the VM’s extensions directory before creating a session and Pi discovers it automatically.

Pi scans two directories for .js extension files:

DirectoryScope
~/.pi/agent/extensions/Global — applies to all Pi sessions
<cwd>/.pi/extensions/Project — applies only when cwd matches
const extensionCode = `
export default function(pi) {
// Modify the system prompt before each agent turn
pi.on("before_agent_start", async (event) => {
return {
systemPrompt: event.systemPrompt +
"\\n\\nAlways respond in formal English."
};
});
}
`;
// Write the extension before creating the session
await agent.mkdir("/home/user/.pi/agent/extensions", { recursive: true });
await agent.writeFile("/home/user/.pi/agent/extensions/formal.js", extensionCode);
// Pi discovers the extension automatically
const { sessionId } = await agent.createSession("pi", {
env: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY },
});

See the Pi extension documentation for the full extension API.