Orchestration
Multiplayer
Connect multiple clients to the same agentOS actor so all subscribers receive broadcasted session output, process logs, and shell data, enabling collaborative patterns where one user prompts and others observe.
Multiple clients observing a session
Section titled “Multiple clients observing a session”All clients connected to the same actor receive broadcasted events. This enables building collaborative UIs where multiple users watch an agent work.
import { createClient } from "@rivet-dev/agentos/client";import type { registry } from "./server";
// Client A: creates the session and sends promptsconst clientA = createClient<typeof registry>({ endpoint: "http://localhost:6420" });const agentA = clientA.vm.getOrCreate("shared-agent");
const connA = agentA.connect();connA.on("sessionEvent", (data) => { console.log("[A]", data.event.method);});
const session = await agentA.createSession("pi", { env: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY! },});await agentA.sendPrompt(session.sessionId, "Build a REST API");
// Client B: observes the same session (in a separate process)const clientB = createClient<typeof registry>({ endpoint: "http://localhost:6420" });
const connB = clientB.vm.getOrCreate("shared-agent").connect();connB.on("sessionEvent", (data) => { console.log("[B]", data.event.method);});
// Client B sees the same events as Client A