子任务想换个便宜模型跑?Sub-Agent 这样设计
「Regnexe 实战系列」第 3 篇共 10 篇对应仓库ExampleReadme03SubAgentTest。上一篇02. Skill只能借工具不能占。真实场景主 Agent 用旗舰模型子任务想省钱很多团队做多 Agent 系统会遇到这个成本问题主任务需要强模型做复杂推理但拆出来的某个子任务——比如估算一下这次出差大概花多少钱——逻辑很简单用旗舰模型纯属浪费。理想情况是主 Agent 用deepseek-v4-flash这种强模型子任务用更便宜的模型单独跑互不影响。上一篇讲的 Skill 做不到这件事——它被设计成强制继承主模型。这篇要讲的Sub-Agent规则正好反过来。Sub-Agent 的核心规则可以拥有而不是只能借SubAgentConfig.builder().model(aliyun:qwen-plus)// 自己的模型跟主 Agent 完全独立.ownTools(List.of(myPrivateTool))// 私有工具外面看不到.build();对比一下两种类型的规则差异SkillSub-Agent模型强制继承父 Agent自己的模型或写inherit继承工具只能借allowedTools私有拥有ownTools外部不可见适合跟主 Agent 紧耦合的轻量子流程需要隔离、需要独立模型的独立子任务model字段默认值就是inherit——不配就跟 Skill 一样继承父模型一旦写了具体值比如aliyun:qwen-plus就会走独立的ModelProvider分支单独构建一个模型实例。实战代码仓库里的ExampleReadme03SubAgentTest一个expense_estimatorSub-Agent自己的模型aliyun:qwen-plus自己的私有工具estimate_trip_cost// 私有工具只在 SubAgent 内部执行器里可见通过 ownTools 注入ToolestimateCostToolTool.builder().name(estimate_trip_cost).description(Estimates total cost for a multi-day business trip.).params(days: int -- trip length; city: String -- destination city).func(input-3-day Chengdu trip estimate: flights 1800 CNY, hotel 1200 CNY, meals 600 CNY. Total: 3600 CNY.).build();SubAgentConfigexpenseEstimatorSubAgentConfig.builder().name(expense_estimator).description(Estimates the total cost of a business trip. TRIGGER: Use when the user asks for a trip budget or cost estimate.).model(aliyun:qwen-plus)// 自己的模型独立于主 Agent 的默认模型.systemPrompt( You are a travel expense estimator. 1. Call estimate_trip_cost with the trip length and destination. 2. Report the total and a one-line breakdown. ).ownTools(List.of(estimateCostTool)).build();RegnexeAgentagentregnexeAgentBuilder.withDefaultModel(Vendor.ALIYUN,deepseek-v4-flash)// 主 Agent 用的模型.withSubAgent(expenseEstimator).withEventListener(newConsoleEventListener()).withMaxRounds(3).build();AgentResultresultagent.execute(What would a 3-day business trip to Chengdu cost?);主 Agent 跑deepseek-v4-flashexpense_estimator内部跑aliyun:qwen-plus——两个模型互不干扰各自配各自的。关键点ownTools 为什么外面看不到estimate_trip_cost这个工具从头到尾没有出现在withTool或者 marketplace 的任何注册调用里。它只存在于expenseEstimator.ownTools这一个地方。这意味着主 Agent 的 Planner 在 Search 阶段候选列表里压根不会出现estimate_trip_cost它没法直接调用这个工具——唯一的入口是先选中expense_estimator这个 Sub-Agent工具才会在它内部的执行循环里被用上。这是真正意义上的私有——不是权限控制是从能力市场的可见性上就把它隔离掉了。适合那些你不想让外层 Agent 瞎调用、必须经过子任务封装好的逻辑统一处理的场景。小结Skill 还是 Sub-Agent三秒判断问自己一句话这个子能力需要自己的模型或者需要外部完全看不到的私有工具吗要——用 Sub-Agent不要就是想复用主 Agent 的模型省成本——用 Skill两种类型不是谁更高级是这套 harness 解决不同问题的工具。下一篇会讲怎么把这两种类型连同普通 tool 一起用注解打包进一个类里一次注册全搞定。 上一篇02. Skill只能借工具不能占 下一篇04. Plugin 注解打包一切 项目地址https://github.com/flower-trees/regnexe-agent