Skip to content

CodingToolSet 的 capability toggle(enable_lsp / enable_tasks / enable_web)应提升到 ToolRegistry 级别 #25

Description

@cynicalight

Summary

当前 enable_lspenable_tasksenable_webCodingToolSet 的构造参数,但它们的语义是 agent 级别的 capability("这个 agent 有没有 LSP / task / web 能力"),而非 toolset 级别的("shell 工具有 LSP 但 editor 工具没有")。这导致两个问题:

  1. 死参数enable_lspenable_tasks 被双重门控在 profile == "full" 内部(coding_impl.py:166),非 "full" profile 下无论设什么值都不生效。
  2. 冗余样板:同一个 agent loop 里每创建一个 CodingToolSet 都要重复声明相同的 toggle 值。

建议将这些 toggle 移到 ToolRegistry 构造参数,CodingToolSet 只保留 profile

Current behavior

# 同一个 agent 内,三个 toolset 的 enable_lsp/enable_tasks/enable_web 总是相同的,
# 但每个都要写一遍。而且 enable_lsp/enable_tasks 在非 "full" profile 下是死参数。
editor_tools = CodingToolSet(profile="editor", enable_lsp=False, enable_tasks=False, enable_web=False)
shell_tools  = CodingToolSet(profile="shell",  enable_lsp=False, enable_tasks=False, enable_web=False)
file_tools   = CodingToolSet(profile="files",  enable_lsp=False, enable_tasks=False, enable_web=False)

根因在 coding_impl.pytools() 方法:

# Line 166: lsp_query 和 task_* 只在 profile == "full" 分支内
if self.expose_modern_names and self.profile == "full":
    ...
    if self.enable_lsp:        # Line 184 — 非 full profile 永远走不到这里
        items.append(self.lsp_query)
    if self.enable_tasks:      # Line 186 — 同上
        items.extend([self.task_create, ...])

Proposed change

# ToolRegistry 统一管理能力开关
class ToolRegistry:
    def __init__(self, *, enable_lsp: bool = True, enable_tasks: bool = True, 
                 enable_web: bool = True):
        ...

# CodingToolSet 只保留 profile,不再接受 capability toggle
class CodingToolSet:
    def __init__(self, workspace_root=".", *, profile="full"):
        ...

# 用户代码简化为
registry = ToolRegistry(enable_lsp=False, enable_tasks=False, enable_web=False)
registry.include_toolset([
    CodingToolSet(profile="editor"),
    CodingToolSet(profile="shell"),
    CodingToolSet(profile="files"),
])

Why this makes sense

  • LSP server 是 agent 内的共享资源,不存在"shell 工具能查 LSP 但 editor 工具不能"这种有意义的区分。agent 要么有 LSP,要么没有。
  • task 管理同理,task 是 session 级别的概念,不需要 per-toolset 开关。
  • profile 已经承担了"选哪些工具"的职责(editor 给编辑工具、shell 给命令工具),capability toggle 是另一个正交维度,不应混在同一个构造参数里。

Backward compatibility

可以在 CodingToolSet.__init__ 中保留这些参数但标记为 deprecated,转发到 ToolRegistry,过渡一个版本后移除。


Happy to submit a PR if this direction looks good.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions