feat(session-routing): 新增基于 Session 标题前缀的可配置 Vendor 自动绑定#260
Merged
ThreeFish-AI merged 1 commit intoJun 7, 2026
Merged
Conversation
当 Session 标题以配置前缀(默认「# 目标」)开头时,自动将该 Session 绑定到指定 vendor(默认 zhipu),不走默认 vendor 路由。前缀与目标 vendor 均通过 YAML 配置(session_policies.title_vendor_bindings), 支持多条规则、按顺序匹配首次命中生效、置空列表即禁用。 实现复用现有 SessionPolicyResolver.upsert() 运行时绑定机制,在标题 提取后、tier 解析前注入策略,仅对新 Session 首请求生效以避免覆盖手动 绑定。新增启动期 vendor 存在性校验(未知 vendor 告警而非硬失败)与 prefix/vendor 非空约束(杜绝空前缀全量误绑定)。 - config/session_policy.py: 新增 TitleVendorBinding 模型 + 配置字段 - config/config.default.yaml: 默认「# 目标」→ zhipu 绑定 - routing/executor.py: _apply_title_based_policy 方法、启动校验、双路径注入 - routing/router.py + server/app.py: 配置透传 - tests: 新增 17 个用例(前缀匹配/边缘/校验/流式与非流式端到端) 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
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.
背景与动机
CC 调用经由本代理时,vendor 路由此前仅能通过全局
tiers优先级或按session_key/client_category的 Session Policy 控制,缺少按会话语义自动分流的能力。业务上存在这样的诉求:标题以「# 目标 (Goal)」为前缀的 Session 属于特定类型任务,应稳定走指定 vendor(如 zhipu),而非默认链路。本 PR 新增基于 Session 标题前缀的 Vendor 自动绑定机制,且将前缀命中条件设计为可配置项(而非代码写死),以满足后续灵活扩展。
主要变更
TitleVendorBinding(prefix+vendor,均带非空约束),挂载于既有session_policies.title_vendor_bindings配置段,支持多条规则按序匹配、首次命中生效,置空[]即禁用。# 目标 → zhipu。_apply_title_based_policy:在标题提取后、tier 解析前注入,命中前缀时调用SessionPolicyResolver.upsert()建立运行时绑定,随后_resolve_effective_tiers自然将目标 vendor 提升至首位。config → app.py → RequestRouter → _RouteExecutor全链路打通。实现要点
SessionPolicyResolver.upsert()运行时绑定能力,零侵入现有路由逻辑,流式与非流式两条路径一致接入。is_new=False用例显式锁定该语义。prefix/vendor施加min_length=1约束,杜绝空前缀匹配全量 Session 的误配置。