Jukebox-OS:面向 AI Agent 的确定性时光倒流回放与 ACID 工具沙箱
英文标题:🔶 Jukebox-OS: Deterministic time-travel replay and ACID tool sandbox for AI agents
针对当前主流 Agent 框架在工具调用副作用(Side Effects)处理上缺乏回滚机制的痛点,开发者 Marius Carlsson 推出了基于 Rust 构建并提供 Python 绑定的系统级运行时 Jukebox-OS。该系统引入了数据库级 ACID 事务沙箱与基于 Merkle CAS 的黑匣子记录机制,支持在 0.4 毫秒内离线且零 API 成本地确定性回放 50 步 Agent 执行过程,并支持在任意步骤分叉调试。基准测试显示,其回放性能较重跑 API 提升约 9.3 万倍,副作用回滚延迟仅 0.19 毫秒,并内置循环检测熔断器,为构建高可靠生产级 Agent 提供了坚实的基础设施底座。
3.2 KB
65.7 KB
中文
🍒 今日特色(为什么选择 JUKEBOX?)
现代 Agent 框架(LangGraph、AutoGen、CrewAI、OpenAI Agents SDK)非常擅长编排 Prompt,但它们往往将副作用(Side Effects)视为“发射后不管”。当一个包含 15 步的 Agent 工作流在第 8 步修改了三个 SQL 表和五个本地文件后,又在第 12 步出现幻觉时,“对聊天记录打检查点(Checkpointing)”根本无法挽回局面。
JUKEBOX(由 Marius Carlsson 设计架构)是一个采用 Rust 编写并提供 Python 绑定的系统级运行时,它为任何 AI Agent 技术栈带来了数据库级 ACID 事务和确定性黑胶级回放(Deterministic Vinyl Replay):
| 菜单项目 | 包厢配置(特性) | 为什么平台工程师喜爱它 |
|---|---|---|
| 💿 Vinyl CAS 飞行记录仪 (Vinyl CAS Flight-Recorder) | 每个 LLM 请求、流式分块、随机种子、工具输入/输出以及时钟脉冲,均通过 BLAKE3/BLAKE2b 哈希记录到便携式 .jbx 磁带中。 |
在离线状态下以 0.4ms 极速回放 50 步 Agent 运行记录,且 API 成本为 $0.00。可以在 GitHub Issue 中像提交 core dump 一样分享失败的 .jbx 文件。 |
| 🛡️ 影子包厢(ACID 工具沙箱)(Shadow Booth) | 在写时复制(Copy-on-Write, CoW)WASI 暂存层内拦截本地文件写入、Shell 命令、SQL 查询以及 Anthropic MCP 调用。 | 副作用只有在验证器调用 tx.commit() 时才会真正作用于现实世界。如果 Agent 未通过安全检查,tx.rollback() 不会留下任何痕迹。 |
🎛️ 时光倒流分叉 (Track B-Side) |
将探针落在失败生产 Trace 的第 9 帧上,将 gpt-4o 替换为 claude-3-7-sonnet 或调整系统提示词,然后继续执行。 |
第 1 到 8 步直接从 Merkle 磁带瞬间解析完成;只有第 9 步及之后才会真正请求实时网络。支持并排对比两条时间线。 |
| 🚨 防跳针装置(循环熔断器)(Anti-Skip Needle) | 流式语义相似度与 AST-diff 监控器,负责监视 Agent 之间的交互对话及 Token 消耗速度。 | 当两个 Agent 陷入礼貌的递归死亡循环时自动触发熔断——在传呼机报警前拯救你的云预算。 |
🥞 蓝盘特餐(60 秒快速上手)
1. 步入包厢(安装)
git clone https://github.com/socrates6969/jukebox-os.git
cd jukebox-os
pip install -e .
2. 将任意 Agent 包装在事务性黑胶磁道中
import asyncio
from jukebox import Jukebox, SandboxPolicy, CircuitBreaker
jb = Jukebox(
tape_dir="./tapes",
sandbox=SandboxPolicy(filesystem="copy_on_write", mcp_mode="staged_acid"),
breaker=CircuitBreaker(max_cost_usd=0.50, max_semantic_repeat=3),
)
@jb.track(name="invoice-reconciliation-agent")
async def run_accounting_agent(customer_id: str, amount_usd: float) -> dict:
async with jb.transaction(tape_id="tr_8f92a1c4") as tx:
tx.record_agent_turn(
agent_name="planner",
message=f"Staging refund of ${amount_usd} for {customer_id}",
model="gpt-4o",
cost_usd=0.008,
)
tx.stage_file_write(
path="./tapes/staged_ledger_demo.json",
content=f'{{"customer": "{customer_id}", "refund_usd": {amount_usd}}}',
)
if amount_usd > 500.0:
await tx.rollback(reason="Refund exceeds $500 autonomous threshold")
return {"status": "ROLLED_BACK", "tape_id": tx.tape_id}
await tx.commit()
return {"status": "COMMITTED", "tape_id": tx.tape_id}
if __name__ == "__main__":
print(asyncio.run(run_accounting_agent("cust_9981", 420.00)))
3. 下针播放:Python 中的时光倒流分叉
from jukebox import Tape
tape = Tape.load("./tapes/tr_8f92a1c4.jbx")
b_side = tape.fork(
at_frame=3,
override_model="claude-3-7-sonnet-latest",
override_system_prompt="You are a strict SQL auditor. Never issue DELETE without a WHERE clause.",
)
print(b_side.replay_and_diff().to_markdown())
📋 点餐菜单(系统架构)
+-----------------------------------------------------------------------------------+
| APPLICATION & ORCHESTRATION LAYER |
| [ LangGraph ] [ CrewAI ] [ AutoGen ] [ OpenAI / Anthropic SDK ] |
+-----------------------------------------+-----------------------------------------+
| @jukebox.track / MCP Proxy
v
+-----------------------------------------------------------------------------------+
| 🍒 JUKEBOX RUST CORE RUNTIME (libjukebox) 🔮 |
| |
| +-------------------------+ +-----------------------+ +---------------------+ |
| | ANTI-SKIP NEEDLE | | BLAKE3 MERKLE CAS | | OTEL GEN_AI | |
| | • Cosine Loop Breaker | | • Zero-Cost Replay | | EXPORTER | |
| | • Token Budget Gate | | • .jbx Binary Tape | | • Spans & Metrics | |
| +-------------------------+ +-----------------------+ +---------------------+ |
| |
| +-----------------------------------------------------------------------------+ |
| | SHADOW BOOTH: TRANSACTIONAL WASI & CoW SANDBOX | |
| | [ Virtual CoW Filesystem ] [ SQL Savepoint Proxy ] [ MCP Stage Gate ] | |
| +--------------------------------------+--------------------------------------+ |
+-----------------------------------------|-----------------------------------------+
|
+--------------------+--------------------+
| |
[ VERIFIER PASSES ] [ VERIFIER FAILS ]
| |
v v
( ATOMIC WORLD COMMIT ) ( INSTANT ZERO-RESIDUE )
Writes flushed to Disk/API ROLLBACK & ALERT
🚗 柜台服务与汽车穿梭餐厅(CLI & TUI)
# 列出本地包厢中最近的 Agent 飞行记录
$ jukebox ls --tape-dir ./tapes
🍒 JUKEBOX 24-HOUR FLIGHT RECORDER // LOCAL BOOTH TAPES 🔮
------------------------------------------------------------------------------
TRACK ID AGENT NAME FRAMES COST STATUS
------------------------------------------------------------------------------
tr_8f92a1c4 invoice-reconciliation-agent 5 $0.0080 COMMITTED
# 在 1ms 内回放并加密验证 .jbx Merkle 磁带
$ jukebox replay ./tapes/tr_8f92a1c4.jbx
🔥 主厨餐桌 / 出餐线(基准测试)
| 指标 | 原生框架(无沙箱) | 每次运行启动 Docker 容器 | 🍒 JUKEBOX 运行时 |
|---|---|---|---|
| 运行时拦截开销 | 0.00 ms(基准) |
+1,420.0 ms(冷启动) |
每帧 +0.34 ms |
| 回放第 1–15 步(时光倒流) | 38,400 ms(重新调用 API) |
39,800 ms(重新调用 API) |
0.41 ms(提速 93,000x) |
| 10 次调试回放的 API 成本 | $1.84 |
$1.84 |
$0.00(100% CAS 命中) |
| 副作用回滚延迟 | ❌ 无法回滚(需手动清理) | 640 ms(容器销毁) |
0.19 ms(丢弃 CoW 指针) |
| 失控死循环检测 | ❌ 仅在达到 max_iterations 后 |
❌ 仅在达到 max_iterations 后 |
0.18 ms(语义 AST 熔断) |
🪙 给厨师的小费(贡献与社区)
-
Fork 仓库并拉把椅子坐下:
git clone https://github.com/socrates6969/jukebox-os.git cd jukebox-os pip install -e . pytest pytest -v -
店铺守则(行为准则): 请阅读我们的 CODE_OF_CONDUCT.md 和 CONTRIBUTING.md。
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░ BUILT WITH CHROME, NEON & RUST BY MARIUS CARLSSON (@mariuscarlsson) ░
░ "THANK YOU FOR DINING AT JUKEBOX — DRIVE SAFELY!" ░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
⭐ 在 GitHub 上 Star jukebox-os • 🔮 启动 24 小时在线餐馆检查器(Live Diner Inspector)
English / 原文
🍒 Today's Specials (Why JUKEBOX?)
Modern agent frameworks (LangGraph , AutoGen , CrewAI , OpenAI Agents SDK) are great at orchestrating prompts, but they treat side effects as fire-and-forget. When a 15-step agent workflow hallucinates on Step 12 after mutating three SQL tables and five local files on Step 8, "checkpointing the chat history" won't save you.
JUKEBOX (architected by Marius Carlsson) is a systems-level runtime written in Rust with Python bindings that brings database-grade ACID transactions and deterministic vinyl replay to any AI agent stack:
| Menu Item | What Goes In The Booth | Why Platform Engineers Love It |
|---|---|---|
| 💿 Vinyl CAS Flight-Recorder | Every LLM request, streaming chunk, seed, tool input/output, and clock tick is hashed via BLAKE3/BLAKE2b into a portable .jbx tape. |
Rewind & Replay 50-step agent runs in 0.4ms offline at $0.00 API cost. Share a failed .jbx file in a GitHub Issue like a core dump. |
| 🛡️ Shadow Booth (ACID Tool Sandbox) | Intercepts local file writes, shell commands, SQL queries, and Anthropic MCP calls inside a Copy-on-Write (CoW) WASI staging layer. | Side effects only hit the real world when your verifier calls tx.commit(). If an agent fails a safety check, tx.rollback() leaves zero trace. |
🎛️ Time-Travel Forking (Track B-Side) |
Drop the needle at Frame #9 of a failed production trace, swap gpt-4o for claude-3-7-sonnet or tweak a system prompt, and resume. |
Steps 1–8 resolve instantaneously from the Merkle tape; only Step 9+ hits the live network. Diff both timelines side-by-side. |
| 🚨 Anti-Skip Needle (Loop Circuit-Breaker) | Streaming semantic similarity & AST-diff monitor that watches inter-agent chatter and token burn velocity. | Automatically trips the breaker when two agents enter a polite recursive death spiral—saving your cloud budget before the pager fires. |
🥞 The Blue Plate Special (60-Second Quickstart)
1. Slide Into a Booth (Installation)
git clone https://github.com/socrates6969/jukebox-os.git
cd jukebox-os
pip install -e .
2. Wrap Any Agent in a Transactional Vinyl Track
import asyncio
from jukebox import Jukebox, SandboxPolicy, CircuitBreaker
jb = Jukebox(
tape_dir="./tapes",
sandbox=SandboxPolicy(filesystem="copy_on_write", mcp_mode="staged_acid"),
breaker=CircuitBreaker(max_cost_usd=0.50, max_semantic_repeat=3),
)
@jb.track(name="invoice-reconciliation-agent")
async def run_accounting_agent(customer_id: str, amount_usd: float) -> dict:
async with jb.transaction(tape_id="tr_8f92a1c4") as tx:
tx.record_agent_turn(
agent_name="planner",
message=f"Staging refund of ${amount_usd} for {customer_id}",
model="gpt-4o",
cost_usd=0.008,
)
tx.stage_file_write(
path="./tapes/staged_ledger_demo.json",
content=f'{{"customer": "{customer_id}", "refund_usd": {amount_usd}}}',
)
if amount_usd > 500.0:
await tx.rollback(reason="Refund exceeds $500 autonomous threshold")
return {"status": "ROLLED_BACK", "tape_id": tx.tape_id}
await tx.commit()
return {"status": "COMMITTED", "tape_id": tx.tape_id}
if __name__ == "__main__":
print(asyncio.run(run_accounting_agent("cust_9981", 420.00)))
3. Drop the Needle: Time-Travel Forking in Python
from jukebox import Tape
tape = Tape.load("./tapes/tr_8f92a1c4.jbx")
b_side = tape.fork(
at_frame=3,
override_model="claude-3-7-sonnet-latest",
override_system_prompt="You are a strict SQL auditor. Never issue DELETE without a WHERE clause.",
)
print(b_side.replay_and_diff().to_markdown())
📋 A La Carte Menu (System Architecture)
+-----------------------------------------------------------------------------------+
| APPLICATION & ORCHESTRATION LAYER |
| [ LangGraph ] [ CrewAI ] [ AutoGen ] [ OpenAI / Anthropic SDK ] |
+-----------------------------------------+-----------------------------------------+
| @jukebox.track / MCP Proxy
v
+-----------------------------------------------------------------------------------+
| 🍒 JUKEBOX RUST CORE RUNTIME (libjukebox) 🔮 |
| |
| +-------------------------+ +-----------------------+ +---------------------+ |
| | ANTI-SKIP NEEDLE | | BLAKE3 MERKLE CAS | | OTEL GEN_AI | |
| | • Cosine Loop Breaker | | • Zero-Cost Replay | | EXPORTER | |
| | • Token Budget Gate | | • .jbx Binary Tape | | • Spans & Metrics | |
| +-------------------------+ +-----------------------+ +---------------------+ |
| |
| +-----------------------------------------------------------------------------+ |
| | SHADOW BOOTH: TRANSACTIONAL WASI & CoW SANDBOX | |
| | [ Virtual CoW Filesystem ] [ SQL Savepoint Proxy ] [ MCP Stage Gate ] | |
| +--------------------------------------+--------------------------------------+ |
+-----------------------------------------|-----------------------------------------+
|
+--------------------+--------------------+
| |
[ VERIFIER PASSES ] [ VERIFIER FAILS ]
| |
v v
( ATOMIC WORLD COMMIT ) ( INSTANT ZERO-RESIDUE )
Writes flushed to Disk/API ROLLBACK & ALERT
🚗 Counter Service & Drive-Thru (CLI & TUI)
# List recent agent flight recordings in your local booth
$ jukebox ls --tape-dir ./tapes
🍒 JUKEBOX 24-HOUR FLIGHT RECORDER // LOCAL BOOTH TAPES 🔮
------------------------------------------------------------------------------
TRACK ID AGENT NAME FRAMES COST STATUS
------------------------------------------------------------------------------
tr_8f92a1c4 invoice-reconciliation-agent 5 $0.0080 COMMITTED
# Replay & cryptographically verify a .jbx Merkle tape in <1ms
$ jukebox replay ./tapes/tr_8f92a1c4.jbx
🔥 Chef's Table / The Line (Benchmarks)
| Metric | Raw Framework (No Sandbox) | Docker Container Per Run | 🍒 JUKEBOX Runtime |
|---|---|---|---|
| Runtime Interception Overhead | 0.00 ms (Baseline) |
+1,420.0 ms (Cold boot) |
+0.34 ms per frame |
| Replay Steps 1–15 (Time-Travel) | 38,400 ms (Re-runs APIs) |
39,800 ms (Re-runs APIs) |
0.41 ms (93,000x faster) |
| API Cost on 10x Debug Replays | $1.84 |
$1.84 |
$0.00 (100% CAS Hit) |
| Side-Effect Rollback Latency | ❌ Impossible (Manual cleanup) | 640 ms (Container teardown) |
0.19 ms (CoW pointer drop) |
| Runaway Loop Detection | ❌ Only after max_iterations |
❌ Only after max_iterations |
0.18 ms (Semantic AST trip) |
🪙 Tipping the Cooks (Contributing & Community)
-
Fork the Repo & Pull Up a Stool:
git clone https://github.com/socrates6969/jukebox-os.git cd jukebox-os pip install -e . pytest pytest -v -
House Rules (Code of Conduct): Read our CODE_OF_CONDUCT.md and CONTRIBUTING.md.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░ BUILT WITH CHROME, NEON & RUST BY MARIUS CARLSSON (@mariuscarlsson) ░
░ "THANK YOU FOR DINING AT JUKEBOX — DRIVE SAFELY!" ░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
⭐ Starjukebox-os on GitHub • 🔮 Launch Live 24-Hr Diner Inspector