Skip to main content
Rivet for Agents

Build AI Agents

LLMs are stateless. Agents shouldn't be. Rivet Actors provide the persistent memory, tool execution environment, and long-running context your agents need to thrive.

support_agent.ts
1import { actor } from "rivetkit";
2import { openai } from "@ai-sdk/openai";
3
4export const supportAgent = actor({
5 // Context window persists in memory
6 state: { history: [], ticketId: null },
7 actions: {
8 chat: async (c, message) => {
9 c.state.history.push({ role: 'user', content: message });
10
11 // Stream thought process
12 const result = await streamText({
13 model: openai('gpt-4-turbo'),
14 messages: c.state.history,
15 onChunk: (chunk) => c.broadcast("delta", chunk)
16 });
17 // Automatically save context
18 c.state.history.push({ role: 'assistant', content: result.text });
19 return result.text;
20 }
21 }
22});

Why Actors for Agents?

Traditional architectures force you to fetch conversation history from a database for every single token generated. Rivet Actors keep the context hot in RAM.

User
Agent Actor
(Hot Context)
Thinking...
Tool

Zero-Latency Context

Conversation history and embedding vectors stay in the Actor's heap. No database queries required to "rehydrate" the agent state for each message.

Long-Running "Thought" Loops

Agents often need to chain multiple tool calls (CoT). Actors can run for minutes or hours, maintaining their state throughout the entire reasoning chain without timeouts.

Multi-User Collaboration

Since the Actor is a live process, multiple users can connect to the same Agent instance simultaneously via WebSockets to collaborate or monitor execution.

Built for the Agentic Future

The infrastructure primitives you need to move beyond simple chatbots.

Streaming by Default

Native support for SSE and WebSocket streaming. Pipe tokens from the LLM directly to the client with zero overhead.

Tool Execution Sandbox

Actors provide a secure isolation boundary. Run Python scripts or API calls without blocking your main API fleet.

Human-in-the-Loop

Pause execution, wait for a human approval signal via RPC, and then resume the agent's context exactly where it left off.

Scheduled Wake-ups

Set an alarm for your agent. It can sleep to disk and wake up in 2 days to follow up with a user automatically.

Knowledge Graph State

Keep a complex graph of entities in memory. Update relationships dynamically as the conversation progresses.

Vendor Neutral

Swap between OpenAI, Anthropic, or local Llama models instantly. The Actor pattern abstracts the underlying intelligence.

Case Study

Customer Support Swarms

Deploy a dedicated Actor for every single active support ticket.

  • Isolation: One crashed agent doesn't affect others
  • Context: Full ticket history in memory (up to 128k tokens)
  • Handoff: Transfer actor state to a human instantly
Ticket #9402
Agent: Active
Online
Analysing user request... accessing database...
Found 3 matching orders. Asking clarification...
orchestrator.ts
1import { actor } from "rivetkit";
2
3export const manager = actor({
4 state: { subtasks: [] },
5 actions: {
6 runWorkflow: async (c, goal) => {
7 // 1. Spawn specialized workers
8 const researcher = await c.spawn(researchAgent);
9 const coder = await c.spawn(codingAgent);
10
11 // 2. Parallel execution (RPC)
12 const [context, code] = await Promise.all([
13 researcher.rpc.gatherInfo(goal),
14 coder.rpc.generate(goal)
15 ]);
16
17 // 3. Synthesize results
18 return { context, code, status: 'complete' };
19 }
20 }
21});
Multi-Agent Systems

Orchestrate Agent Swarms

Don't stop at one. Build hierarchical trees of Actors where managers delegate tasks to specialized workers. Rivet handles the supervision, networking, and message passing between them automatically.

Parallel Processing

Run 100 research agents at once.

Supervision Trees

Restart workers if they hallucinate or crash.

Shared State

Pass context references instantly between actors.

Event Bus

Pub/Sub messaging between swarm members.

Works with your stack

LangChain
LlamaIndex
Vercel AI SDK
OpenAI
Anthropic
HuggingFace

Stop building generic bots.

Start building stateful, durable, intelligent agents that actually work.