返回资讯中心
外部精选
软件工程
#开发者实时流

Carpool 推出批处理工具:将重复的 LLM 调用编译成代码以降低调用成本

来源标题:Carpool – cut LLM costs by batching tasks and compiling repeated calls into code

开源工具 Carpool 把多个独立的 LLM 任务合并进一次请求,并校验每个答案引用的来源,只重跑未通过的答案。在 Claude 上测试,每个合格答案的成本比逐个精简调用降低约 80%;相比每个任务都调用一次 Claude Code agent,降低 93–96%,且无性能回退。

Hacker News 最新nmayp2026/11/27 · 今天27 分钟阅读

以下正文由 AI 翻译自 Hacker News 最新(原文版权归原站所有),可能存在偏差,重要内容请以原文为准。

一次能搞定的事,何必跑二十四趟。

大量彼此独立的 LLM 任务,合并在一次经过验证的请求里完成。

如果你的脚本、流水线或 agent 为每个条目单独发起一次模型调用,那么每次调用都要重复支付固定的准备开销:system prompt、工具 schema、指令。carpool 把彼此独立的任务放进同一次请求,对照每条答案引用的来源逐一核验,只重做没有通过的那些。在我们针对 Claude 的测试中,与每个任务单独发起一次精简调用相比,每个被接受的答案成本降低了约 80%;与每个任务单独发起一次 Claude Code agent 调用相比,降低了 93–96%,且没有出现性能回退。1

claude plugin marketplace add nmayp/carpool claude plugin install carpool@carpool

或者离线试用这个库,无需 API key:

pip install carpool-agents carpool bench

carpool bench 使用一个每次调用成本固定的 mock 模型,所以它展示的是 carpool 的工作方式,而不是它能省下多少。要看真实数字,请运行 carpool bench --backend claude-lean(或 claude-code、codex、ollama:<model> 等)。

设置 | 基线 | carpool,首次运行 成本 / 被接受的答案 | 回退 24 个 ops 任务 | 精简调用 | 24 次调用 · 24/24 · $0.281 | 1 次调用 · 24/24 · $0.047 | −83% | 0 48 个 SQuAD 问题 | 精简调用 | 48 次调用 · 42/48 · $0.817 | 3 次调用 · 46/48 · $0.195 | −78% | 0 24 个 ops 任务 | agent 调用 | 24 次调用 · 24/24 · $1.159 | 1 次调用 · 24/24 · $0.065 | −94% | 0 48 个 SQuAD 问题 | agent 调用 | 48 次调用 · 40/48 · $2.449 | 2 次调用 · 44/48 · $0.178 | −93% | 0

精简调用是指通过 Claude Code 调用 Claude,不带任何工具,system prompt 只有一行(固定准备约 1,100 个 token);agent 调用是一次完整的 Claude Code 会话(约 26,000 个 token)。重复运行时成本更低,因为 provider 缓存了分组后的 prompt,所以表中引用的是首次运行的数字。

每个原始 JSON 文件、消融实验、分组规模扫描以及 agent 实验都在 docs/RESULTS.md 中。

每次调用都要付出 H + E_i:共享的 harness 上下文 H,加上该任务的证据 E_i。如果拆成 b 次独立调用,你就要支付 b·H。用 carpool 合并后,你只需支付一次 H:

C_group = H + Σ E_i + J_b + V_b + Σ_{i∈F} C_retry,i

其中 J_b 是分组与格式化的成本,V_b 是各项检查的成本,F 是重试的任务集合。单靠压缩几乎没有帮助:当每个任务仍然需要单独调用时,仅做 preflight 压缩只节省了 0.2%。真正省下 token 的是共享请求。

MCP server(Claude Code、Cursor、Windsurf、Cline、Codex、Gemini CLI、Claude Desktop)

pip install carpool-agents claude mcp add carpool -- carpool-mcp

它新增四个工具:carpool_prompt、carpool_verify、carpool_run 和 carpool_lookup,其中 carpool_lookup 做精确查找,不调用模型。各客户端的配置见 integrations/MCP.md。

如果某类调用总是看到同一类输入,模型可以写一个普通函数来处理其中大部分。把记录下来的调用交给 carpool compile,每行一个 JSON 对象,包含 input 和 output:

carpool compile calls.jsonl --task "map one log line to its event id" --out compiled/solve.py

这个函数可以放弃作答。只有在它未学习过的记录调用上,其答案与记录答案一致(至少 95%,且 95% 置信下界至少 85%)时,它才会被保存。在代码中,Cascade(fast, slow) 会先尝试这个函数,把所有它放弃作答的内容交给模型。

它对普通文本有效,对任何需要语义理解的内容无效。单次运行,小规模测试集;详见细节与注意事项。生成的文件以你的身份运行,部署前请先阅读。

与 carpool 一起使用。编译文件能回答的任务跳过模型;carpool 将其余的分组。循环如下:

carpool run tasks.jsonl --backend claude-code > answers.jsonl carpool compile tasks.jsonl --answers answers.jsonl --task "answer a question from its evidence" --out compiled/solve.py carpool run new-tasks.jsonl --backend claude-code --compiled compiled/solve.py

carpool bench --compiled compiled/solve.py 会给对比表增加第三行。在代码回答了三分之二任务的情况下,总 token 比单用 carpool 下降了 52%;在回答了 22% 的情况下,没有可测量的节省(§13)。该数据上的第一次编译被门禁拒绝,原因是日志中的格式不匹配,报告说明了之后做了哪些改动。

把 integrations/AGENTS.md 中的五条规则粘贴进你的 AGENTS.md、.cursorrules、GEMINI.md 或 system prompt。

pip install carpool-agents

这些 backend 报告 provider 的真实用量:claude-code、codex、gemini-cli、anthropic、openai:<model>(任何 OpenAI 兼容端点:OpenAI、OpenRouter、Groq、vLLM、通过 OPENAI_BASE_URL 接入的 LM Studio)、gemini:<model>、ollama:<model>,以及 cmd:"<any cli>"(估算)。

carpool prompt my_tasks.jsonl | pbcopy

粘贴到 ChatGPT、Claude.ai 或 Gemini,然后保存回复:

carpool parse my_tasks.jsonl reply.txt

它会打印被接受的答案,并列出哪些任务需要重试以及原因。

from carpool import Task, Source, run_carpool, AnthropicBackend tasks = [ Task("T01", "Which team maintains the fire pump at Mirefield?", [ Source("T01-a", "The fire pump at Mirefield is maintained by the Halvard Controls Group."), Source("T01-b", "The Mirefield canteen closes at 15:00 on Fridays."), ]),

... more independent tasks

res = run_carpool(tasks, AnthropicBackend()) # or CommandBackend("codex exec -") for a in res.answers.values(): print(a.task_id, a.answer, a.source_id, a.route, a.fallback_reason) print(res.ledger.n_calls, res.ledger.total_tokens, res.ledger.uncached_tokens)

带契约检查的精确操作:

from carpool import Index orders = Index(rows, key="order_id", required=("status",)) # raises if a key repeats or a status is missing orders.get("W123", "status"); orders.count(status="pending")

任务文件格式(.jsonl,每行一个任务;answers 可选,仅用于评分):

{"id": "T01

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →