Claude Code的Dynamic Workflows和LangGraph Deep Agents的Interpreters

发布时间:2026/6/4 1:10:24

Claude Code的Dynamic Workflows和LangGraph Deep Agents的Interpreters 一、Claude Code — Dynamic WorkflowsDynamic Workflows 让 Claude 动态编写编排脚本在单次 session 中调度数十到数百个并行 subagent并在结果交给用户之前自动完成验证。它专门针对太大、太复杂、一次过不了的任务而设计。核心机制当 workflow 启动后Claude 根据 prompt 动态规划、拆解子任务并将工作扇出到并行运行的多个 subagent。各 subagent 从独立角度攻克问题另有对抗型 agent 专门尝试推翻其结论整个流程持续迭代直到答案收敛。进度实时保存中断后从断点续跑而不是重头开始。两种启动方式直接对 Claude 说Create a workflow或在 effort 菜单开启ultracode设置让 Claude 自行判断何时启用。典型场景全代码库 bug 排查与安全审计、大规模框架迁移跨数千个文件、以及对正确性要求极高的关键工作多套独立方案 对抗验证。真实案例Bun 将约 75 万行代码从 Zig 移植到 Rust99.8% 原有测试通过从第一个 commit 到合并只用了 11 天全程由 dynamic workflows 驱动一批 agent 并行转写文件每个文件配两个 reviewer修复循环持续跑到编译和测试全过为止。二、LangGraph Deep Agents — InterpretersInterpreter 给 agent 提供一个可编程的工作空间让它在其中探索数据、协调工具调用并把中间结果挡在模型上下文之外。Agent 写代码表达意图内存中的运行时执行这段代码并只把相关结果返回给模型。与 sandbox 的区别sandbox 是对外部环境执行操作运行命令、安装依赖、修改文件而 interpreter 是在 agent 循环内部行动组合工具、保持状态、决定什么信息应该返回给模型。适用场景选择判断矩阵需求用什么一两个简单外部调用普通 tool calling需要循环、分支、重试或聚合结果的小程序Interpreter从代码中发起多个 tool 调用Interpreter 程序化 tool calling跨线程可复用的辅助函数Interpreter Interpreter SkillsShell 命令、包安装、完整 OS 文件系统Sandboxes安装与初始化pip install-Udeepagents[quickjs]fromdeepagentsimportcreate_deep_agentfromlangchain_quickjsimportCodeInterpreterMiddleware agentcreate_deep_agent(modelopenai:gpt-5.4,middleware[CodeInterpreterMiddleware()],)middleware 会向 agent 添加一个eval工具在持久化 QuickJS 上下文中运行 TypeScript捕获console.log并返回最后一个表达式的值。程序化 Tool CallingPTCPTC 把选定的 agent tool 暴露在 interpreter 的全局tools命名空间下让 agent 可以用代码在循环、分支、重试或并行批次中调用工具而不是让模型一次发一个 tool call 再等结果。中间的 tool 结果可以在 interpreter 里过滤或聚合只有最终结果回到模型上下文这在多工具多步骤流程中更节省 token。agentcreate_deep_agent(modelopenai:gpt-5.4,middleware[CodeInterpreterMiddleware(ptc[task])],)在 interpreter 里并行调度 subagentconsttopics[retrieval,memory,evaluation];constreportsawaitPromise.all(topics.map((topic)tools.task({description:Research${topic}and return three concise findings.,subagent_type:general-purpose,}),),);reports.join(\n\n);状态快照与时间旅行interpreter 状态全局变量、函数、已导入模块在每次 agent run 结束后被序列化快照下次 run 时恢复。配合 LangGraph 的 checkpointer可以回到任意历史时间点——恢复图的 checkpoint 同时恢复对应的 interpreter 状态适合调试和回放。三、Interpreter SkillsInterpreter Skills 的核心就是把 skill 目录下的 JS/TS 脚本文件注册为可import的模块agent 在 interpreter 里写await import(/skills/name)就能调用里面的函数。普通 skill 给 agent 提供指令和上下文Interpreter skill 额外给 agent 提供可导入的函数让它在 interpreter 代码中直接调用。这样就可以把领域特定的逻辑打包一次变成 agent 工作空间里的确定性构建块——不再让模型每次都重新发明一个解析器、评分器、规范化器或聚合函数而是直接 import 一个经过测试的辅助函数与工具、subagent 和运行时状态组合使用。适合做成 Interpreter Skill 的代码需满足在多个 prompt、agent 或项目间可复用足够确定性每次行为一致细节太多不适合放在模型上下文里在更大的工作流中有用比如给搜索结果评分、规范化 API 响应、验证记录、分组行、把数据转换成报告格式。文件结构skills/ └── order-helpers/ ├── SKILL.md ← 元数据 使用说明 └── index.ts ← 实际可导入的代码SKILL.md 的关键字段module: index.ts——这个字段标记它是一个 interpreter skill指向脚本文件。--- name: order-helpers description: Helper functions for normalizing and grouping order records. module: index.ts ← 必须有这个字段 --- # order-helpers Import these utilities into the REPL: typescript const { groupByStatus } await import(/skills/order-helpers); groupByStatus(...);index.ts 的内容正经的 TypeScript不是说明文字interfaceOrder{id:string;status:string;}exportfunctiongroupByStatus(orders:Order[]){returnorders.reduce((acc,order){acc[order.status]acc[order.status]??[];acc[order.status].push(order);returnacc;},{});}配置 agent 时CodeInterpreterMiddleware必须传入skills_backend参数让它知道从哪里加载 skill 模块fromdeepagentsimportcreate_deep_agentfromdeepagents.backendsimportStateBackendfromlangchain_quickjsimportCodeInterpreterMiddleware backendStateBackend()agentcreate_deep_agent(modelopenai:gpt-5.4,backendbackend,skills[/skills/],# 告诉 agent 去哪扫描 SKILL.mdmiddleware[CodeInterpreterMiddleware(skills_backendbackend)],# 同一个 backend)Agent 在 interpreter 里这样调用const{groupByStatus}awaitimport(/skills/order-helpers);constgroupedgroupByStatus(orders);grouped;SKILL.md里的module字段是让一个 skill 变为可导入的关键——没有这个字段它就只是普通 skill提供指令文本不能被 interpreter import。三者的关系总结

相关新闻