feat: SmartRouter - intelligent model routing based on task complexity#315
Open
zhangPinkdolphin wants to merge 4 commits into
Open
feat: SmartRouter - intelligent model routing based on task complexity#315zhangPinkdolphin wants to merge 4 commits into
zhangPinkdolphin wants to merge 4 commits into
Conversation
Add SmartRouter class that classifies user queries into simple/complex based on keywords, query length, and code patterns.
Add /llm auto command, auto_route property, and automatic model routing in gen_answer based on task complexity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
为 GenericAgent 添加智能路由能力。根据用户查询的复杂度(关键词/长度/代码模式),自动选择简单模型(flash)或复杂模型(pro)。
改动内容
1. llmcore.py — SmartRouter 类 (+56行)
新增
SmartRouter类,通过分析查询文本中的关键词、长度和代码特征,将任务分类为 simple/complex。COMPLEX_KEYWORDS: 涉及代码、框架、架构、性能优化等复杂主题的关键词列表classify(query): 返回'simple'或'complex'disable()/enable(): 手动锁定/恢复自动判断2. agentmain.py — 三处修改
SmartRouter__init__: 初始化self.router = SmartRouter()和self.auto_route = False/llm auto命令: 运行时切换自动路由开关/llm simple|complex命令: 手动指定模型组run()方法: 在调用agent_runner_loop前,若auto_route开启,自动classify(query)并切换llmclient使用方式
/llm auto/llm simple/llm complex前置条件
在
mykey.py中配置两个 MixinSession:0: 简单模型组(flash 优先),命名规则含_simple1: 复杂模型组(pro 优先),命名规则含_complex当自动路由生效时,SmartRouter 会根据任务复杂度自动切换
self.llm_no指向对应的 MixinSession。兼容性
/llm list、/resume等功能