Shepherd:开源 Python 运行时,让 Agent 运行可分支回放
Meet Shepherd: An Open-Source Python Substrate That Lets Meta-Agents Fork, Replay, and Revert Any Agent Run
做 Agent 工程的同学必看,这个开源运行时把 Agent 运行变成可分支回放的状态,能大幅降低长任务失败重跑的成本,赶紧去 GitHub 上试试。
Long-running agents accumulate state that no transcript captures. A coding agent at step 10 holds edited files, a running dev server, installed packages, and a warm prompt cache. When it misreads a traceback and rewrites a file that was already correct, neither available recovery path is cheap: patching forward grows the context and the token bill, and restarting from step one re-pays every model and tool call while reproducing nothing exactly, because runs are non-deterministic. Jumping back to step eight is the option engineers actually want, and it is the one existing runtimes cannot offer. Git versions files, not a live process or a cache. Researchers at Northeastern University and Stanford University have released Shepherd, a Python runtime substrate that records an agent run as a Git-like trace of typed events, so any past state can be forked and replayed. The research team reports forks 5× faster than Docker and over 95% prompt-cache reuse on replay.
长时间运行的代理会积累任何记录都无法捕获的状态。一个在第10步的编码代理持有已编辑的文件、正在运行的开发服务器、已安装的包和热提示缓存。当它误读回溯并重写一个本来正确的文件时,两种可用的恢复路径都不便宜:向前修补会增长上下文和令牌账单,而从第一步重新开始会重新支付每个模型和工具调用,同时由于运行是非确定性的,无法精确复现任何内容。跳回第八步是工程师真正想要的选项,而这是现有运行时无法提供的。Git 版本化的是文件,而不是实时进程或缓存。东北大学和斯坦福大学的研究人员发布了 Shepherd,一个 Python 运行时基础,它将代理运行记录为类似 Git 的类型化事件轨迹,因此任何过去的状态都可以被分叉和重放。研究团队报告称,分叉比 Docker 快 5 倍,重放时提示缓存重用率超过 95%。
Is it deployable?
它可以部署吗?
Yes but it is available in early alpha and not ready for production. Shepherd is MIT-licensed and installable with pip install shepherd-ai from PyPI. It needs Python 3.11+. OS-level grant enforcement runs on macOS (Seatbelt) and Linux (Landlock, in a privileged container).
可以,但它处于早期 alpha 阶段,尚未准备好用于生产。Shepherd 采用 MIT 许可证,可通过 pip install shepherd-ai 从 PyPI 安装。它需要 Python 3.11+。操作系统级别的授权执行在 macOS(Seatbelt)和 Linux(Landlock,在特权容器中)上运行。
- Industries: Software engineering and DevOps, AI infrastructure and agent-platform vendors, quantitative finance research, security tooling and offensive-security research, and data engineering. The common trait is not the vertical. It is long-horizon agent runs against heavy sandbox state, where a failed run is expensive to redo.
- Applications: Live supervision of coding agents, with a meta-agent reverting a bad write before it commits. Automated recovery from a wrong tool call, without a full restart. Branching exploration over candidate agent strategies, compared side by side. Rollout generation for reinforcement learning, forking at selected turns.
- 行业:软件工程和 DevOps、AI 基础设施和代理平台供应商、量化金融研究、安全工具和进攻性安全研究,以及数据工程。共同特征不是垂直领域,而是长时间运行的代理在重型沙盒状态下的运行,其中失败的运行重做成本高昂。
- 应用:编码代理的实时监督,元代理在错误写入提交之前将其还原。从错误的工具调用中自动恢复,无需完全重启。对候选代理策略进行分支探索,并排比较。为强化学习生成 rollout,在选定的轮次进行分叉。
What Shepherd changes
Shepherd 改变了什么
Shepherd is a Python substrate that records an agent’s execution as a first-class object. Every agent-environment interaction becomes a typed event in a Git-like execution trace. Core operations are formalized as functions and mechanized in Lean.
Shepherd 是一个 Python 基础,将代理的执行记录为一等对象。每次代理-环境交互都成为类似 Git 的执行轨迹中的类型化事件。核心操作被形式化为函数,并在 Lean 中机械化。
Each interaction is effectively a commit. Unlike Git, the commit covers the agent process and the filesystem together, copy-on-write. A branch therefore carries live state, not just files. Returning to an earlier point is a single fork from that commit.
每次交互实际上都是一次提交。与 Git 不同,提交覆盖代理进程和文件系统,采用写时复制。因此,分支携带实时状态,而不仅仅是文件。返回到较早的点是从该提交进行单次分叉。
The research team reports that Shepherd forks the agent process and its filesystem 5× faster than Docker. Because the prompt prefix through the branch point is unchanged, replay achieves over 95% prompt-cache reuse.
研究团队报告称,Shepherd 分支代理进程及其文件系统的速度比 Docker 快 5 倍。由于分支点之前的提示前缀保持不变,重放实现了超过 95% 的提示缓存复用。
The documentation organizes the framework around four concepts: tasks, effects, runs, and workspaces. A task is a typed function whose body the model fills in, so the signature is the contract. An effect is every crossing of the task boundary, and it can be watched, answered, or refused. A run is the durable record of those crossings.
文档围绕四个概念组织框架:任务、效果、运行和工作区。任务是一个类型化函数,其主体由模型填充,因此签名即契约。效果是任务边界的每一次跨越,可以被观察、应答或拒绝。运行是这些跨越的持久记录。
Permissions are declared in the signature. A May[GitRepo, ReadOnly] binding is compiled to that run’s writable roots and enforced at the native syscall jail.
权限在签名中声明。May[GitRepo, ReadOnly] 绑定被编译为该运行的可写根,并在原生系统调用沙箱中强制执行。
Once a run is forkable, a meta-agent can sit on top
一旦运行可分支,元代理就可以位于其上
Forking enables higher-order agents that observe a trace and intervene before a bad write commits. The research team demonstrates three applications:
分支使得高阶代理能够观察轨迹并在不良写入提交之前进行干预。研究团队展示了三个应用:
- In runtime intervention, a live supervisor raised pair-coding pass rates on CooperBench from 28.8% to 54.7%.
- In counterfactual meta-optimization, branching exploration beat baselines across four benchmarks by up to 11 points, while cutting wall-clock time by up to 58%.
- In Tree-RL training, forking rollouts at selected turns improved TerminalBench-2 from 34.2% to 39.4%.
- 在运行时干预中,实时监督器将 CooperBench 上的结对编程通过率从 28.8% 提升到 54.7%。
- 在反事实元优化中,分支探索在四个基准上比基线高出最多 11 个百分点,同时将墙钟时间缩短最多 58%。
- 在 Tree-RL 训练中,在选定轮次进行分支回放将 TerminalBench-2 从 34.2% 提升到 39.4%。
Key Takeaways
关键要点
- Shepherd records each agent-environment interaction as a typed event in a Git-like, forkable trace.
- A commit covers the agent process and filesystem together, so a rewind restores live state, not just files.
- Reported: 5× faster forks than Docker and over 95% prompt-cache reuse on replay.
- A live supervisor lifted CooperBench pair-coding pass rates from 28.8% to 54.7%.
- Shepherd 将每次代理-环境交互记录为类似 Git 的可分支轨迹中的类型化事件。
- 一次提交同时覆盖代理进程和文件系统,因此回滚恢复的是实时状态,而不仅仅是文件。
- 报告:分支速度比 Docker 快 5 倍,重放时提示缓存复用率超过 95%。
- 实时监督器将 CooperBench 结对编程通过率从 28.8% 提升到 54.7%。
Check out the Paper, GitHub, Experiments repo, Project page and PyPI. Also, feel free to follow us on Twitter and don’t forget to join our 150k+ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well.
查看论文、GitHub、实验仓库、项目页面和 PyPI。此外,欢迎在 Twitter 上关注我们,别忘了加入我们的 150k+ ML SubReddit 并订阅我们的通讯。等等!你在 Telegram 上吗?现在你也可以在 Telegram 上加入我们。
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力