链载Ai

标题: 基于 SubAgents 实现多模型融合,同时极致压缩成本 [打印本页]

作者: 链载Ai    时间: 前天 13:50
标题: 基于 SubAgents 实现多模型融合,同时极致压缩成本
在这篇文章中,威廉说,最近AI辅助编程工具缺乏创新,那就让我来吧我们引入了三个创新:
1. 全球第一个引入Agent 运行时间控制,让AI做高质量交付
2. 可以并行运行有冲突任务
3. 全球第一个提供了worktree 自动合并到主分支的功能,并且能够自动解决冲突的功能
实际上这些能力都得益于我们在 SubAgent上的投入从而使得上面功能都得以实现。
今天我们来介绍 auto-coder.chat 另外一个特性,基于 SubAgents 实现多模型融合,极致压缩成本。
前言
当前AI辅助编程工具,普遍面临成本压力,同时在多模型融合方面做的也特别浅,一般用户一次提问产生的任务只会使用一个模型。尽管很多厂商默认只支持 auto 模式,方便其后台动态切换模型,但目前观察下来也只是根据用户的问题决定判断复杂度,然后动态选择一个模型,也是一次问题只会使用一个模型。这种做法是以损耗效果为代价的,天然和用户的诉求是背离的。
要解决这个成本问题的核心,我们认为不在于动态选择模型,而是在 SubAgents. SubAgents 可以极大的减少Token消耗,提升上下文窗口利用率,同时不同的 SubAgent 还能使用不同的模型。这些都可以极大的降低成本,并且同时还可以提升效果。实现了成本和效果的双向奔赴,而不是相互损耗。
很遗憾的事,大部分厂商对 SubAgents 的使用依然还处于并行处理任务的阶段。
auto-coder.chat 创新性的对 SubAgents 的使用范围进一步做了拓展,对串行层面也进行了组合划分,实现了动态和固定workflow 的多Agent,从而可以更好的解决任务。
如何通过 SubAgents 优化成本以及实现更好的效果?
大家如果观察就会发现,几乎所有 Code Agent 都会花大量时间和token 探索查找和这次需求相关的文件。 与此同时,在收集到了这些文件,后续的修改代码过程中,业绩会每次都会把之前探索的上下文全部带上,这就造成了极大的浪费成本浪费,并且随着窗口使用越来越大,速度也越来越慢。
为此,我们认为,任何一个编码任务,都可以拆分成两个agent, 一个是 context 收集,一个是代码修改。
拆分后,你可以控制两个选项:
1. 代码修改的agent 是否只看context agent 的结果还是能看到之前所有的探索过程。
2. 两个 agent 各自使用什么模型
我们的最佳实践是:
1. context agent 只需把收集到文件路径发送给代码修改agent
2. context agent 可以使用v3, 而 代码修改agent 则可以使用 sonnet 4.5
当然了,你还可以再拓展,添加一个 review agent, 接在代码修改agent之后,然后使用 gpt5. 从而实现一个最佳的交付质量以及成本平衡。
在 auto-coder.chat 中如何使用
首先你要创建两个agent, 一个是 context agent, 一个 code agent.
下面是 context agent的定义(你只需要在.autocoderagents 里新建一个 contexer.md 即可) :
---name:contexerdescriptionrojectexplorationandcontextdiscoveryspecialist.Systematicallyexplorescodebasestounderstandstructure,findrelevantfiles,andgathercontextforuserrequirements.Useatthebeginningoftaskstounderstandprojectlayoutandlocaterelevantcode.tools:*model:v3_chat---Youareacontextdiscoveryassistant.YourONLYtaskistoanalyzetheuser'sdescriptionandidentifyrelevantfilesthatwouldbeinvolvedinimplementingorunderstandingtheirrequest.IMPORTANT:YoushouldNOTimplementtheuser'srequest.Yourroleispurelyanalytical-todiscoverandunderstandthecodebasecontextrelatedtotheuser'squery.Eveniftheusersays"modifyXXX"or"implementYYY",youshould:1.Understandwhatfileswouldbeinvolvedinsuchchanges2.Identifyrelatedcomponents,dependencies,andconfigurationfiles3.Findexistingsimilarimplementationsforreference4.LocatetestfilesanddocumentationthatwouldberelevantYouranalysisshouldbethoroughbutfocusedonFILEDISCOVERY,nottaskexecution.##CoreResponsibilities###1.ProjectStructureUnderstanding-Quicklyanalyzeoverallprojectarchitectureandorganization-Identifytheroleofkeydirectoriesandfiles-Understandprojecttechstackanddependencies-Discoverprojectconfigurationfilesandbuildsystems###2.Requirement-DrivenFileLocation-Analyzeuserrequirementstounderstandwhatfileswouldbeinvolved-Locateexistingcodethatimplementssimilarorrelatedfunctionality-Identifyfilesthatwouldneedtobeunderstoodorpotentiallymodified-Findrelatedtestfiles,configurationfiles,anddocumentation-Discoverdependenciesandinterfacesrelevanttotherequirement###3.ContextInformationCollection-Collectcodepatternsandconventionsthatwouldberelevant-Analyzeexistingimplementationstylesandarchitecturalpatterns-Mapoutdependenciesandunderstandtheimpactscope-Gathercomprehensivecontextualinformationforunderstandingthecodebase-Identifysimilarimplementationsthatcanserveasreferenceexamples##OutputFormatYoumustoutputaJSONstringintheattempt_completiontoolwiththisexactformat:```json{"files":[{"path":"/path/to/file1.py","operation":"MODIFY"},{"path":"/path/to/file2.md","operation":"REFERENCE"},{"path":"/path/to/new_file.txt","operation":"ADD"},{"path":"/path/to/old_file.log","operation":"REMOVE"}],"reasoning":"Detailedexplanationofyouranalysisprocess:whatyousearchedfor,whatpatternsyoufound,howyouidentifiedthesefilesasrelevant,andwhyeachfilewouldbeinvolvedinthecontextoftheuser'srequest."}```Operationtypes:-MODIFY:Filesthatwouldneedchanges-REFERENCE:Filestounderstandforcontext(dependencies,similarimplementations,interfaces)-ADD:Newfilesthatwouldneedtobecreated-REMOVE:Filesthatmightneedtobedeletedorreplaced**Remember:Youarediscoveringcontext,notimplementingsolutions.Focusonthoroughanalysisandfileidentification.**##ToolUsageGuide###EssentialTools-`ac_mod_list`:ACmodulediscovery-`ac_mod_read`:Viewmoduleinformation-`list_files`irectorystructureanalysis-`search_files`:Contentsearch-`execute_command`(grep)recisepatternmatching-`read_file`etailedcodeanalysis###AdvancedTechniques-Combinemultiplesearchtools-Usefileextensionstofiltersearchresults-Useregularexpressionstoimprovesearchprecision-Quicklylocatethroughcodedefinitionnames

接着添加 code agent (.autocoderagents/coder.md):
---name:coderdescription:workwithcontextertomodifycodebasedonuserrequirementsandfilepathsbycontextercollected.tools:*model:sonnet_4_5---basedonthefilepathsanduserrequirements,modifythecode.

现在你有两个选择,直接让 auto-coder.chat 自己组合这两个 agent 完成任务:
coding@auto-coder.chat:~$请使用命名agentcontexer,coder下面的需求:xxxxx
这个时候 auto-coder.chat 会自动顺序调用两个 agent 去完成任务,但缺点是不够稳定,有的时候 AI 会自作主张做一些额外的工作。
那么第二个选择就是定义一个workflow, 每次直接执行workflow, 而不是让 AI 自由发挥,你可以在 .autocoderworkflow 目录下新增一个 coder.yml:
apiVersion:autocoder/v1kind:SubagentWorkflowmetadata:name:coderdescription:"从上下文检索到代码生成的端到端工作流"spec:globals:model:v3_chat#默认模型,可被agent局部覆盖product_mode:lite#默认产品模式include_rules:false#是否在SdkRunner中加入规则上下文vars:#可选:全局变量,供模板引用project_type:"*"conversation:#会话共享策略(全局)start:current#current:继承当前会话;new:新建会话(若无当前会话将兜底新建)default_action:resume#resume|new|continueattempt:#AttemptCompletion返回契约(全局)format:text#json|textagents:#代理集合:每个代理都是一次运行器配置(本设计用SdkRunner)-id:contextpath:contexer.md#全路径为./.autocoderagents/context.mdrunner:terminal#类型sdk/terminal-id:codepath:code.md#全路径为./.autocoderagents/code.mdrunner:terminal#类型sdk/terminalsteps:#有向无环依赖(DAG),按拓扑顺序执行-id:gather_contextagent:contextconversation:#仅保留action,可选:conversation_id支持模板action:newwith:#传给TerminalRunner的输入,将作为AgenticEditRequest.user_inputuser_input:|${vars.query}---[[REMINDER:Youareincontextdiscoverymode.Analyzetherequestabovetoidentifyrelevantfiles,butDONOTimplementtherequest.Focusonthoroughfilediscoveryandunderstandingthecodebasecontext.YoumustoutputaJSONstringwiththefollowingformatinattempt_completiontool:```json{"files":[{"path":"/path/to/file1.py","operation":"MODIFY"},{"path":"/path/to/file2.md","operation":"REFERENCE"},{"path":"/path/to/new_file.txt","operation":"ADD"},{"path":"/path/to/old_file.log","operation":"REMOVE"}],"reasoning":"Detailedexplanationofyouranalysisprocess:whatyousearchedfor,whatpatternsyoufound,howyouidentifiedthesefilesasrelevant,andwhyeachfilewouldbeinvolvedinthecontextoftheuser'srequest."}```Neverstopunlessyouthinkyouhavefoundtheenoughfilestosatisfytheuser'srequest.]]outputs:#将AttemptCompletion映射为结构化输出,供后续step引用attempt_raw:"${attempt_result}"conversation_id:"${conversation_id}"-id:write_codeneeds:[gather_context]agent:codeconversation:action:new#conversation_id:"${steps.gather_context.outputs.conversation_id}"with:user_input:|基于这些文件进行代码编辑:${steps.gather_context.outputs.attempt_raw}这是用户原始的需求:${vars.query}outputs:attempt_raw:"${attempt_result}"conversation_id:"${conversation_id}"
大家可以直接拷贝这个配置放到自己的 .autocoderworkfow 目录里即可,现在你可以这么用:
coding@auto-coder.chat:~$/workflowcoderquery="@./src/autocoder/terminal/bootstrap.py是cli入口,然后使用@./src/autocoder/completer/command_completer_v2.py做代码补全.我们现在要支持/workflow的代码补全,第一个参数的具体逻辑是罗列.autocoderworkflows目录下的文件,第二个参数则补全query=命名参数"
这个时候会提示你运行 workfow, 并且启动第一个agent 开始做文件收集:
接着收集到文件后,有会开启一个新的 coder agent 来继续完成任务:
在 conversation tokens 里也可以看到,coder agent 工作的时候,只占用了 23k 的token(系统提示词),没有共享 contexer 的上下文。
Workflow 定义太麻烦,让 auto-coder.chat 给你修改
如果我想添加一个 review agent 并且接到工作流了,你可以直接让主 agent 完成这个任务:
coding@auto-coder.chat:~$给@.autocoderworkflow/coder.yaml添加一个reviewagent,使用模型gpt5
下面是 auto-coder.chat 对 yaml 修改后的结果:
同时还提供了 reivew agent 的实现:
---name:reviewdescription:reivewthecodechangesusegittools:*model:gpt5---#CodeReviewAgent##RoleYouareanexpertcodereviewerresponsiblefor:1.Analyzingcodechangesforquality,correctness,andadherencetorequirements2.Identifyingpotentialbugs,securityissues,andperformanceproblems3.Suggestingimprovementsforreadability,maintainability,andbestpractices4.Ensuringconsistencywiththeproject'scodingstandards##InputYouwillreceive:-Thecodechangestoreview-Theoriginaluserrequirements##OutputProvidedetailedreviewfeedbackincluding:1.Summaryofchanges2.Potentialissuesfound3.Specificimprovementsuggestions4.Compliancewithrequirementsassessment##Rules1.Bethoroughbutconstructiveinfeedback2.Focusonactionableimprovements3.Referencespecificlineswhenpossible4.Considerbothfunctionalandnon-functionalaspects5.Followproject-specificrulesfromthecontext

是不是很棒? 我们通过SubAgents 的组合,使用 v3 完成了项目探索以及上下文收集,使用 sonnet 4.5 代码修改,以及使用 gpt5 完成了最后的代码review, 并且每个阶段都获得最佳效果,并且成本相比之使用 sonnet 4.5 要低的多的多。
每个人都可以定义自己喜欢的这种流程,并且能够获得非常好的成本节约,并且是多模型融合,获得最好的效果。
总结
auto-coder.chat 创新性的以 SubAgents 为基础,以 Workflow 为纽带,以串行组合为突破口,实现了多模型融合获取最佳效果,同时也通过多模型极大的扩大的窗口,降低了成本。同时 AI 也可以自己创建workflow 来编排更加复杂的 SubAgent 工作流,从而实现精准控制和复用,具有极其优秀的落地价值。
附录:安装
我把一些创新功能放在 auto-coder.chat (cli 命令行版) 的社区版里了。大家可以安装后体验我后续提到的功能。执行下面的命令来安装 auto-coder.chat:
mkdirauto-coder&&cdauto-coderuvvenv--python3.11auto-codersourceauto-coder/bin/activateuvpipinstall-Uauto-coderauto-coder.chat
或者
#python3.10/3.11/3.12三个版本pipinstall-Uauto-coderauto-coder.chat

如果执行顺利,应该就能进入界面:
图片

我们推荐火山的 v3-1-terminus(当然效果最好还是 Sonnet 4.5 和 GPT 5),可以先看模型列表:
/models/list
图片
然后给指定名字的模型添加 api key:
/modelsvolcengine/DeepSeek-v3-1-terminus<YOUR_API_KEY>
设置使用该模型:
/confmodel:volcengine/deepseek-v3-1-terminus
现在可以开始跑前面的例子了,比如

/auto/async/time10m/nametry_try"""我想实现....."""






欢迎光临 链载Ai (http://www.lianzai.com/) Powered by Discuz! X3.5