rivet-dev/rivet
GitHub: rivet-dev/rivet
Rivet 是一个基于 Actor 模型的有状态工作负载编排框架,专为 AI Agent、协作应用和持久化执行场景设计,提供毫秒级冷启动、自动状态持久化和无限水平扩展能力。
Stars: 5378 | Forks: 171
## 什么是 Rivet?
Rivet Actor 是专为有状态工作负载设计的长期运行轻量级进程。状态保存在内存中并支持自动持久化。可以为每个 agent、每个会话或每个用户创建一个 Actor —— 内置 workflow、queue 和调度功能。
**后端**
```
const agent = actor({
// In-memory, persisted state for the actor
state: { messages: [] as Message[] },
// Long-running actor process
run: async (c) => {
// Process incoming messages from the queue
for await (const msg of c.queue.iter()) {
c.state.messages.push({ role: "user", content: msg.body.text });
const response = streamText({ model: openai("gpt-5"), messages: c.state.messages });
// Stream realtime events to all connected clients
for await (const delta of response.textStream) {
c.broadcast("token", delta);
}
c.state.messages.push({ role: "assistant", content: await response.text });
}
},
});
```
**客户端** (前端或后端)
```
// Connect to an actor
const agent = client.agent.getOrCreate("agent-123").connect();
// Listen for realtime events
agent.on("token", delta => process.stdout.write(delta));
// Send message to actor
await agent.queue.send("how many r's in strawberry?");
```
## 功能特性
每个 agent、每个会话、每个用户对应一个 Actor —— 包含状态、存储和网络功能。
**Rivet 提供:**
- **内存状态** — 与计算资源同置,实现即时读写。使用 SQLite 或自带数据库 (BYO) 进行持久化。
- **无限期运行,空闲时休眠** — 活跃时长期存在,空闲时自动休眠。
- **无限扩展,可缩容至零** — 支持突发工作负载且具有成本效益。
- **全球边缘网络** — 毫无复杂性可言地部署在靠近用户的位置或特定法律管辖区。
**Actor 支持:**
- **WebSocket** — 内置实时双向流传输。
- **Workflow** — 具有自动重试功能的多步操作。
- **Queue** — 用于可靠异步处理的持久化消息队列。
- **调度** — Actor 内的定时器和 cron job。
## 使用场景
一种可适应 agent、workflow、协作等多种场景的原语。
- **AI Agent** — 每个 agent 作为独立的 Actor 运行,具有持久化的上下文、记忆和调度工具调用的能力。
- **沙盒编排** — 在每个工作区的一个长期运行的 Actor 中协调沙盒会话、排队任务和安排清理工作。
- **Workflow** — 跨步骤的具有自动重试、调度和持久化状态的多步操作。
- **协作文档** — 实时协作编辑,每个文档作为一个 Actor 向所有连接的用户广播更改。
- **单租户数据库** — 每个租户对应一个 Actor,提供低延迟的内存读取和持久的租户数据持久化。
- **聊天** — 每个房间或对话对应一个 Actor,具备内存状态、持久化历史记录和实时交付功能。
## Actor 对比
**Rivet Actor 与传统基础设施对比**
| 指标 | Rivet Actor | Kubernetes Pod | 虚拟机 |
|--------|:-----------:|:--------------:|:---------------:|
| **冷启动** | **~20ms** | ~6s | ~30s |
| **单实例内存** | **~0.6KB** | ~50MB | ~512MB |
| **空闲成本** | **$0** | ~$85/月 (集群) | ~$5/月 |
| **水平扩展** | **无限** | ~5k 节点 | 手动 |
| **多区域** | **全球边缘** | 1 个区域 | 1 个区域 |
**状态**
| 指标 | Rivet Actor | Redis | Postgres |
|--------|:-----------:|:-----:|:--------:|
| **读取延迟** | **0ms** | ~1ms | ~5ms |
基准测试详情与方法论
**冷启动**
- **Rivet Actor (~20ms):** 包含持久化状态初始化,而不仅仅是进程创建。无 actor key,因此无跨区域锁。使用 Node.js 和 FoundationDB 测量。
- **Kubernetes Pod (~6s):** 在预配置的 AWS EKS m5.large 节点上使用 Node.js 24 Alpine 镜像 (压缩后 56MB)。细分:~1s 镜像拉取和解压,~3-4s 调度和容器运行时设置,~1s 容器启动。
- **虚拟机 (~30s):** 使用 Amazon Linux 2 AMI 从启动到可通过 SSH 访问的 AWS EC2 t3.nano。t3.nano 是可用的最小 EC2 实例 (512MB RAM)。
**单实例内存**
- **Rivet Actor (~0.6KB):** RSS 增量除以 actor 数量,通过在 Linux x86 上的 Node.js v24 中生成 10,000 个 actor 测量得出。
- **Kubernetes Pod (~50MB):** Linux x86 上最小空闲 Node.js 容器:Node.js v24 运行时 (~43MB RSS)、containerd-shim (~3MB)、pause 容器 (~1MB) 和 kubelet 每 pod 追踪 (~2MB)。
- **虚拟机 (~512MB):** AWS EC2 t3.nano,可用的最小 EC2 实例,分配内存为 512MB。
**读取延迟**
- **Rivet Actor (0ms):** 状态从与 actor 同机的同置 SQLite/KV 存储中读取,无网络往返。
- **Redis (~1ms):** 位于与应用程序相同可用区的 AWS ElastiCache Redis (cache.t3.micro)。
- **Postgres (~5ms):** 位于与应用程序相同可用区的 AWS RDS PostgreSQL (db.t3.micro)。
**空闲成本**
- **Rivet Actor ($0):** 假设 Rivet Actor 运行在无服务器平台上。Actor 可缩容至零,无空闲基础设施成本。传统的容器部署可能会产生空闲成本。
- **虚拟机 (~$5/月):** AWS EC2 t3.nano ($0.0052/小时计算 + $1.60/月 20GB gp3 存储) 24/7 全天候运行。t3.nano 是可用的最小 EC2 实例 (512MB RAM)。
- **Kubernetes 集群 (~$85/月):** AWS EKS 控制平面 ($73/月) 加上一个 24/7 全天候运行的 t3.nano 工作节点及 20GB gp3 存储。
**水平扩展**
- **Rivet Actor (无限):** 通过增加节点实现线性扩展,无单一集群大小限制。
- **Kubernetes (~5k 节点):** 根据 Kubernetes 可扩展性文档,官方支持最多 5,000 个节点的集群。
**多区域**
- **Rivet (全球边缘网络):** 自动在靠近用户的位置生成 actor 并处理跨区域的路由。
## 内置可观测性
从本地开发到大规模生产的强大调试和监控工具。
- **SQLite 查看器** — 实时浏览和查询您 actor 的 SQLite 数据库
- **Workflow 状态** — 在执行时检查 workflow 进度、步骤和重试情况
- **事件监控** — 追踪发生的每一个状态变更和动作
- **REPL** — 调用动作、订阅事件并直接与您的代码交互
## 部署选项
RivetKit 是一个库。当您需要扩展性、容错性和可观测性时,可将其连接到 Rivet Cloud 或进行自托管。
|
### 只是一个库
安装包并在本地运行。无需服务器,无需基础设施。在开发期间,Actor 运行在您的进程中。
```
npm install rivetkit
```
[开始使用 →](https://www.rivet.dev/docs/actors/quickstart)
|
### 自托管
单个 Rust 二进制文件或 Docker 容器。支持与 Postgres、文件系统或 FoundationDB 配合使用。
```
docker run -p 6420:6420 rivetdev/engine
```
[自托管文档 →](https://www.rivet.dev/docs/self-hosting/)
|
### Rivet Cloud
全托管服务。全球边缘网络。可连接到您现有的云平台 —— Vercel、Railway、AWS 或任何您已部署的平台。
[注册 →](https://hub.rivet.dev)
|
**开源,宽松许可** — 自托管对于企业部署、云可移植性以及避免供应商锁定非常重要。Apache 2.0 意味着您拥有您的基础设施。[在 GitHub 上查看 →](https://github.com/rivet-dev/rivet)
## 入门指南
|
### 与您的编程 Agent 配合使用
让您的编程 Agent 掌握 Rivet 技能,以创建示例或集成到现有项目中:
```
npx skills add rivet-dev/skills
```
兼容 Claude Code、Cursor、Windsurf 及其他 AI 编程工具。
|
### 从零开始
- [Node.js & Bun](https://www.rivet.dev/docs/actors/quickstart/backend)
- [React](https://www.rivet.dev/docs/actors/quickstart/react)
- [Next.js](https://www.rivet.dev/docs/actors/quickstart/next-js)
- [Cloudflare Workers](https://www.rivet.dev/docs/actors/quickstart/cloudflare-workers)
[查看文档 →](https://www.rivet.dev/docs)
|
## 集成
无服务器、容器或您自己的服务器 —— Rivet Actor 可与您现有的基础设施、框架和工具配合使用。
**基础设施**: [Vercel](https://www.rivet.dev/docs/deploy/vercel) • [Railway](https://www.rivet.dev/docs/deploy/railway) • [AWS](https://www.rivet.dev/docs/deploy/aws) • [Docker](https://www.rivet.dev/docs/self-hosting)
**框架**: [React](https://www.rivet.dev/docs/clients/react) • [Next.js](https://www.rivet.dev/docs/clients/next-js) • [Hono](https://github.com/rivet-dev/rivet/tree/main/examples/hono) • [Express](https://github.com/rivet-dev/rivet/tree/main/examples/express) • [Elysia](https://github.com/rivet-dev/rivet/tree/main/examples/elysia) • [tRPC](https://github.com/rivet-dev/rivet/tree/main/examples/trpc)
**运行时**: [Node.js](https://www.rivet.dev/docs/actors/quickstart/backend) • [Bun](https://www.rivet.dev/docs/actors/quickstart/backend) • [Deno](https://github.com/rivet-dev/rivet/tree/main/examples/deno) • [Cloudflare Workers](https://www.rivet.dev/docs/actors/quickstart/cloudflare-workers)
**工具**: [Vitest](https://www.rivet.dev/docs/actors/testing) • [Pino](https://www.rivet.dev/docs/general/logging) • [AI SDK](https://github.com/rivet-dev/rivet/tree/main/examples/ai-agent) • [OpenAPI](https://github.com/rivet-dev/rivet/tree/main/rivetkit-openapi) • [AsyncAPI](https://github.com/rivet-dev/rivet/tree/main/rivetkit-asyncapi)
[请求集成 →](https://github.com/rivet-dev/rivet/issues/new)
## 本仓库中的项目
| 项目 | 描述 |
|---------|-------------|
| [RivetKit TypeScript](./rivetkit-typescript) | 用于构建 actor 的客户端和服务端库 |
| [RivetKit Rust](./rivetkit-rust) | Rust 客户端 (实验性) |
| [RivetKit Python](./rivetkit-python) | Python 客户端 (实验性) |
| [Rivet Engine](./engine) | Rust 编排引擎 |
| ↳ [Pegboard](./engine/packages/pegboard) | Actor 编排器与网络 |
| ↳ [Gasoline](./engine/packages/gasoline) | 持久化执行引擎 |
| ↳ [Guard](./engine/packages/guard) | 流量路由代理 |
| ↳ [Epoxy](./engine/packages/epoxy) | 多区域 KV 存储库 (EPaxos) |
| [Dashboard](./frontend) | 用于调试 actor 的查看器 |
| [Website](./website) | [rivet.dev](https://www.rivet.dev) 的源码 |
| [Documentation](./website/src/content/docs) | [rivet.dev/docs](https://www.rivet.dev/docs) 的源码 |
## 社区
- [Discord](https://www.rivet.dev/discord) - 与社区交流
- [X/Twitter](https://x.com/rivet_dev) - 关注获取更新
- [Bluesky](https://bsky.app/profile/www.rivet.dev) - 关注获取更新
- [GitHub Discussions](https://github.com/rivet-dev/rivet/discussions) - 提问
- [GitHub Issues](https://github.com/rivet-dev/rivet/issues) - 报告 Bug
- [与工程师交流](https://www.rivet.dev/talk-to-an-engineer) - 讨论您的使用场景
## 许可证
[Apache 2.0](LICENSE)
标签:Actor模型, AI开发框架, AI智能体, CMS安全, DNS解析, Go语言工具, GPT-5, JavaScript, MITM代理, OpenAI, Rivet, TypeScript, WebSocket, 任务调度, 依赖分析, 内存规避, 分布式系统, 协作应用, 可视化界面, 后端开发, 响应大小分析, 大模型集成, 安全插件, 实时流式传输, 实时通信, 开源项目, 持久化执行, 无服务器, 有状态工作负载, 消息队列, 状态持久化, 状态管理, 请求拦截