We introduce Shepherd, a functional programming model that formalizes meta-agent operations on target agents as functions, with core operations mechanized in Lean. Shepherd records every agent-environment interaction as a typed event in a Git-like execution trace, enabling any past state to be forked and replayed. The system forks the agent process and its filesystem $5\times$ faster than Docker, achieving $>95\%$ prompt-cache reuse on replay. We demonstrate the model through three applications. First, in runtime intervention, a live supervisor increases pair coding pass rates from 28.8% to 54.7% on CooperBench. Second, in counterfactual meta-optimization, branching exploration outperforms baselines across four benchmarks by up to 11 points while reducing wall-clock time by up to 58%. Third, in Tree-RL training, forking rollouts at selected turns improves TerminalBench-2 performance from 34.2% to 39.4%. These results establish Shepherd as an efficient infrastructure for programming meta-agents. We open-source the system to support future research.
翻译:我们提出Shepherd,一种函数式编程模型,它将作用于目标代理的元代理操作形式化为函数,并在Lean中实现了核心操作的机械化。Shepherd将每次代理与环境的交互记录为类似Git的执行轨迹中的类型化事件,从而允许对任意历史状态进行分支与重放。该系统对代理进程及其文件系统的分支速度比Docker快5倍,重放时提示缓存复用率超过95%。我们通过三个应用展示了该模型。第一,在运行时干预中,实时监督器将CooperBench上结对编码的通过率从28.8%提升至54.7%。第二,在反事实元优化中,分支探索在四个基准测试上的表现优于基线方法最高达11个百分点,同时将实际运行时间缩减最高达58%。第三,在Tree-RL训练中,在选定回合进行分支展开使TerminalBench-2性能从34.2%提升至39.4%。这些结果确立了Shepherd作为高效编程元代理的基础设施。我们已开源该系统以支持未来研究。