CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

Feature Request: Proposal a Fourth Mode "Dual" — Pro for Reasoning + Flash for Execution

Open encyc opened this issue 6 months ago • 5 comments

提案:第四种模式 —— "Dual" 双模型路由模式

在现有的 Agent / Yolo / Plan 三种模式之外,增加第四种 Dual 模式——用 deepseek-v4-pro 做推理和规划(reasoning & planning),用 deepseek-v4-flash 做工具执行(execution),在不大幅降低质量的前提下减少 token 花费。

动机

  • deepseek-v4-pro 在复杂推理、架构设计、安全审计等场景远强于 Flash
  • 但工具调用(读文件、搜代码、跑命令、diff 等)不需要深度推理,Flash 完全够用,且便宜 ~6×
  • 目前 /model auto 的自动路由是按 turn 整体选择一个模型(要么 Pro 要么 Flash),无法在一个 turn 内做 phase 切换
  • 如果能在同一轮对话中:Pro 负责「想」,Flash 负责「做」,可以显著降低费用

现有基础设施(已部分就绪)

  1. Auto model routing (/model auto):auto_model_heuristic + resolve_auto_route_with_flash,per-turn 选模型
  2. Sub-agent router:subagent_flash_router,Flash 决定子 agent 用 Pro 还是 Flash
  3. AutoRouteSelection / AutoRouteRecommendation:模型 + reasoning effort 路由数据结构
  4. 三种现有模式:Agent、Yolo、Plan

关键缺失

  • Turn 内 phase 切换:当前 Engine 的 turn 循环不支持中途切换模型
  • 消息历史衔接:Pro 的 reasoning_content → Flash 的 tool call → Pro 的 synthesis 需要在 API 层面正确拼接
  • 工具执行模型选择:什么时候切 Flash、什么时候保留 Pro 的判断逻辑

技术可行性分析

方案 复杂度 描述
A: 串行分 phase 中 Pro 先做 planning → Flash 执行工具 → Pro 做 synthesis。每轮 2 次 API 调用
B: 子 agent 委派 低-中 Pro 作为主 agent 规划,Flash 子 agent 执行工具。复用现有 sub-agent 设施
C: 动态 mid-turn 切换 高 Pro/Flash 在同一 turn 内根据 tool call 类型动态切换。最深度的集成

方案 B 最可行:已有 sub-agent auto-router(subagent_flash_router),只需增加一个 Dual 模式开关,让主 agent 用 Pro、子 agent 用 Flash。

预期效果

  • 复杂任务(架构设计、多文件重构、安全审计):质量保持 Pro 水平
  • Token 花费:tool execution 部分省 ~80%(Flash vs Pro 的价格差)
  • 延迟:子 agent 并行执行可能反而更快

开放问题

  1. 用户如何感知当前在 Dual 模式——footer 显示什么?
  2. 是否需要一个「Dual 强度」配置(偏激进 Flash vs 偏保守 Pro)?
  3. 兼容性:Dual 模式下 /model auto 如何交互?
  4. 是否所有 tool call 都用 Flash,还是某些高风险的(如 shell exec、git push)保留 Pro?

欢迎社区讨论!如果你有类似需求或有更好的设计思路,请在下面留言。

Related

  • 现有 auto model routing: crates/tui/src/commands/config.rs resolve_auto_route_with_flash
  • 子 agent router: crates/tui/src/tools/subagent/mod.rs subagent_flash_router
  • AppMode 枚举: crates/tui/src/tui/app.rs

encyc avatar May 15 '26 07:05 encyc


English Version

Proposal: Fourth Mode "Dual" — Pro for Reasoning + Flash for Execution

Add a fourth mode alongside Agent / Yolo / Plan: Dual, where deepseek-v4-pro handles reasoning & planning and deepseek-v4-flash handles tool execution — reducing token cost without significant quality loss.

Motivation

  • deepseek-v4-pro excels at complex reasoning, architecture, debugging, security reviews
  • Tool calls (read files, search code, run commands, diff, etc.) don't need deep reasoning — Flash is sufficient and ~6× cheaper
  • Current /model auto routing selects one model per turn — either Pro or Flash for the entire turn, no mid-turn phase switching
  • A mode where Pro "thinks" and Flash "does" could meaningfully reduce cost

Existing Infrastructure (partially ready)

Component Location What it does
/model auto commands/config.rs Keyword + length heuristic → pick Pro or Flash
resolve_auto_route_with_flash commands/config.rs Flash LLM as router when heuristic is ambiguous
subagent_flash_router tools/subagent/mod.rs Flash decides which model a sub-agent should use
AutoRouteSelection commands/config.rs model + reasoning_effort + source data model

What's Missing

  • Mid-turn phase switching: the Engine's turn loop sends one API request and uses a single model for the entire turn (tool call loop all within the same model)
  • No "Pro think → Flash execute → Pro synthesize" pipeline

Feasibility

Approach Complexity Description
A: Serial phases Medium Pro plans → Flash executes tools → Pro synthesizes. 2+ API calls per turn
B: Sub-agent delegation Low-Medium Pro as main agent (planning), Flash sub-agents for tool execution. Reuses existing sub-agent infrastructure
C: Dynamic mid-turn switching High Pro/Flash switch within a turn based on tool call type. Deepest integration

Approach B is the most feasible: the sub-agent auto-router (subagent_flash_router) already exists. A Dual mode toggle would pin the main agent to Pro and delegate tool work to Flash sub-agents.

Expected Impact

  • Complex tasks (architecture, multi-file refactors, security audits): Pro-level quality preserved
  • Token cost: ~80% savings on tool execution tokens (Flash vs Pro pricing)
  • Latency: parallel sub-agent execution may be faster

Open Questions

  1. What should the footer show in Dual mode?
  2. Should there be a "Dual aggressiveness" config (aggressive Flash vs conservative Pro)?
  3. How does /model auto interact with Dual mode?
  4. Should all tool calls use Flash, or keep high-risk ones (shell exec, git push) on Pro?

Related Source Files

  • crates/tui/src/commands/config.rs — resolve_auto_route_with_flash, auto_model_heuristic
  • crates/tui/src/tools/subagent/mod.rs — subagent_flash_router
  • crates/tui/src/tui/app.rs — AppMode enum

encyc avatar May 15 '26 07:05 encyc

Related follow-up: #2027 narrows the Dual-mode idea into a practical routing policy: Flash for scout/tool-heavy helper work, Pro for planning/synthesis/high-risk judgment. #2026 adds the whale-size naming ladder so Pro/Flash plus reasoning effort is understandable in the UI instead of only being raw model ids.

Hmbown avatar May 24 '26 21:05 Hmbown

Thanks for the direction, @Hmbown. I agree that adding a fourth AppMode::Dual is the wrong approach — the right move is to strengthen auto-routing so the system automatically dispatches scout/tool-heavy work to Flash and reserves Pro for planning, synthesis, and high-risk judgment.

I'd like to claim the integration layer for this across the three related issues, with a phased delivery plan that builds on #2026 and #2027 rather than duplicating them.


What I'd build (3 PRs, each independently reviewable):

PR 1 — Scout/Synthesis classifier + Route Receipt (builds on #2027's policy)

  • WorkShape enum: Synthesis / Scout / Ambiguous
  • classify_work_shape(prompt, recent_tool_calls) — a deterministic local classifier (no extra API call). Recognizes scout patterns (all read/search/grep sequences, issue triage, log skimming, status polling) and synthesis patterns (architecture, security, multi-file refactors, release decisions).
  • Hard gate: destructive shell, git push, release, credential operations always force Pro regardless of aggressiveness.
  • RouteReceipt struct: model + effort + source + human-readable reason + cost intent. Plumbed through resolve_auto_route_with_flash and resolve_subagent_assignment_route.
  • New AutoRouteSource variants: ScoutClassifier, SynthesisGuard.

PR 2 — Whale-size naming (builds on #2026's taxonomy)

  • WhaleSize enum mapping (model, reasoning_effort) pairs to user-readable labels.
  • RouteReceipt carries a WhaleSize so footer/agent cards/route receipts show e.g. "Minke Whale" instead of raw deepseek-v4-flash + high.
  • Footer renders: agent · 蓝鲸(Pro+max) · [synthesis: architecture decision]

PR 3 — Aggressiveness config + integration (the actual #1676 closure)

  • [auto] aggressiveness = "conservative" | "balanced" | "aggressive" in config.toml. Controls how eagerly scout work is dispatched to Flash.
  • No new AppMode — this is /model auto doing its job better, with a tunable knob for users who want more cost savings or more quality guardrails.

Dependencies:

#2026 (whale names)  ← independent, can ship in parallel
#2027 (scout policy)  ← PR 1 implements the classifier side
#1676 (integration)   ← PR 3 ties them together + adds aggressiveness

Questions before I start:

  1. Are #2026 and #2027 assigned or claimed by anyone yet? I don't want to step on toes — if someone is already implementing the classifier or the whale taxonomy, I'll scope my PRs to depend on their work rather than duplicate it.
  2. Is [auto] aggressiveness the right config surface, or would you prefer it scoped differently (e.g., a /routing command instead of a toml knob)?
  3. For the scout classifier — would a purely local/deterministic approach (keyword + tool-call-pattern matching, no extra API call) be acceptable, or do you want a Flash-based classifier call similar to the existing router pattern?

Happy to adjust the scope based on your feedback. If #2026 and #2027 are unclaimed, I can take the full stack end-to-end.

encyc avatar May 27 '26 06:05 encyc

Quick follow-up on the design: after digging through auto_reasoning.rs, I think the routing should cover both model and reasoning effort as a single joint decision, not two independent calls. This aligns naturally with #2026's whale-size taxonomy (6 combos of model × effort).

Current state: two independent routers

  • resolve_auto_route_with_flash picks Pro/Flash
  • auto_reasoning::select() picks Low/High/Max based on simple keywords (debug → Max, search → Low)

They are called separately and don't coordinate — you can end up with Flash + Max or Pro + Low, which are both suboptimal.

Proposed: unified WorkShape → (model, effort) routing

The classify_work_shape() I proposed in PR 1 should return a full route pair:

Scout (read/search/grep/status/triage)      → (Flash, off)
Scout (sub-agent batch search)              → (Flash, low)
Ambiguous (single-file edit, normal code)   → (Flash, high) + Flash router fallback
Synthesis (refactor/multi-file/audit)        → (Pro, high)
Synthesis (architecture/debug/security)      → (Pro, max)
Hard gate (shell exec/git push/release)      → (Pro, max) — enforced

This also fixes a current weakness: auto_reasoning::select(is_subagent=true) hardcodes Low for all sub-agents, which means a sub-agent spawned for debugging gets Low thinking when it should get Max. The unified classifier handles this naturally — the sub-agent's prompt goes through the same classify_work_shape and gets the right tier.

How aggressiveness affects effort

Aggressiveness Scout Ambiguous Synthesis
conservative Flash + low Flash router Pro + max
balanced Flash + off Flash + high Pro + high
aggressive Flash + off Flash + low Pro + high

This keeps ~80% of turn-level effort routing deterministic (no extra API call), and reserves the Flash router for genuinely ambiguous cases.

The updated PR scopes remain the same — just replacing WorkShape → model with WorkShape → (model, effort) and retiring the standalone auto_reasoning::select() call in favor of the unified classifier.

encyc avatar May 27 '26 07:05 encyc

Closing as subsumed: a Pro-for-reasoning + Flash-for-execution split is a model-policy concern, carried by HarnessPosture #2693 (and WhaleFlow role→capability mapping in EPIC #2981) rather than a fourth UI mode. Thanks for the proposal — the idea survives there.

Hmbown avatar Jun 10 '26 04:06 Hmbown