Use this file to discover all available pages before exploring further.
Connect to agents from any JavaScript runtime — browsers, Node.js, Deno, Bun, or edge functions — using WebSockets or HTTP. The SDK provides real-time state synchronization, RPC method calls, and streaming responses.
The name parameter identifies a specific agent instance. If omitted, defaults to "default":
// Connect to a specific chat roomuseAgent({ agent: "ChatAgent", name: "room-123" });// Connect to a user's personal agentuseAgent({ agent: "UserAgent", name: userId });// Uses "default" instanceuseAgent({ agent: "ChatAgent" });
Call methods on your agent that are decorated with @callable().
The @callable() decorator is only required for methods called from external runtimes (browsers, other services). When calling from within the same Worker, you can use standard Durable Object RPC directly on the stub without the decorator.
// Basic callconst result = await agent.call("getUser", [userId]);// Call with multiple argumentsconst result = await agent.call("createPost", [title, content, tags]);// Call with no argumentsconst result = await agent.call("getStats");
The stub property provides a cleaner syntax for method calls:
// Instead of:const user = await agent.call("getUser", ["user-123"]);// You can write:const user = await agent.stub.getUser("user-123");// Multiple arguments work naturally:const post = await agent.stub.createPost(title, content, tags);
If your agent uses MCP (Model Context Protocol) servers, you can receive updates about their state:
const agent = useAgent({ agent: "AssistantAgent", name: "session-123", onMcpUpdate: (mcpServers) => { // mcpServers is a record of server states for (const [serverId, server] of Object.entries(mcpServers)) { console.log(`${serverId}: ${server.connectionState}`); console.log(`Tools: ${server.tools?.map((t) => t.name).join(", ")}`); } }});
The client auto-reconnects and the agent automatically sends the current state on each connection. Your onStateUpdate callback will fire with the latest state — no manual re-sync needed.