Skip to content

Add on-demand worker model discovery through MCP - #38

Open
edgexyz wants to merge 6 commits into
Fei-Craft:mainfrom
edgexyz:feat/list-models
Open

edgexyz wants to merge 6 commits into
Fei-Craft:mainfrom
edgexyz:feat/list-models

Conversation

@edgexyz

@edgexyz edgexyz commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Coordinators currently need to inspect individual worker CLIs to find model IDs before dispatching. This adds an on-demand MCP tool, list_models(agent, cwd, refresh=false), that returns a worker's advertised model catalog. list_agents also reports discovery support.

Changes

  • Share ACP discovery between Kimi and DSH using a separate initialize / session/new handshake and the SDK's typed configuration options.
  • Query Antigravity through agy models and Codex through paginated app-server model/list.
  • Return model IDs, display names, advertised defaults, model-specific native effort levels, and cache metadata. Preserve null for unknown effort support and [] for explicitly empty levels.
  • Cache catalogs in memory per worker/project for one hour by default. Support explicit refresh and [models] cache_sec / timeout_sec configuration.
  • Add English/Chinese orchestration guidance, skill and MCP tool descriptions, and an isolated MCP smoke-test script.

Discovery is available to coordinator instances. ACP discovery denies permission requests and may leave an empty session in worker history. Lookup deadlines, output/page limits, diagnostic redaction, and subprocess cleanup cover worker failures and cancellation.

Validation

Tested on Windows with Python 3.14:

  • Full regression suite: 737 passed.
  • ruff check . and mypy: passed.
  • Live queries through an isolated MCP server: Kimi 4, DSH 4, Antigravity 13, Codex 7 catalog entries; cache reuse passed for each worker.
  • Tests cover SDK-backed flat/grouped ACP metadata, native effort semantics, pagination, malformed responses, timeout/cancellation cleanup, environment filtering, and cache concurrency.

The full suite reports one previously observed asyncio pipe-finalizer warning in test_quota.py::test_describe_quotas_covers_every_agent; all tests pass.

@edgexyz
edgexyz marked this pull request as ready for review October 21, 2026 09:48

@klarkxy klarkxy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed via Gemini App · Model: Gemini · Commit: d3a6f498599c717b04b2387a4cbcbda42d495468

整体评估

本 PR 设计并实现了按需探测本地 Worker 模型目录与原生推理档位的 list_models 机制(清晰区分 supported_efforts 的 None 与 [],并通过 asyncio.shield 保障超时/取消时的子进程回收)。由于仓库 main 分支已合入中心化重构 PR #42(20a0882a),而关联移植 PR #45 已在保留原作者署名的前提下将该能力迁移至中心 Hub 服务层(并先行修复了 idle_exit_due 空闲误退与 session_meta 模型白名单透传),建议不直接合入 #38,待下方审查发现的遗留问题同步修复至 #45 并合入后关闭本 PR。

1. 建议修复(架构冲突与需同步至 #45 的逻辑缺陷)

  1. 与 main 中心 Hub 架构冲突,应由移植 PR #45 承接

    • 位置:src/agent_bridge/server.py、src/agent_bridge/config.py:483
    • 触发场景:当前 main(50f154f2)已将全部工具调用收敛至 _service(ctx) 与本机 Hub HTTP API;本分支直接调用本地 _registry(ctx).list_models(...) 不仅存在多文件合并冲突(mergeable_state: "dirty"),在多协调器场景下还会绕过 Hub 共享缓存与管理员鉴权。
  2. _acp_model_catalog 漏判无 category 的 id="effort"/"reasoning" 档位选项,且未过滤原生 DSH 的空字符串默认项 ""(同样存在于 #45,建议移植修复)

    • 位置:src/agent_bridge/adapters/acp.py:723-731
    • 触发场景:
      • (a) 代码仅匹配 option.category == "thought_level" or option.id in {"thinking", "reasoning_effort"}。但真实 claude-agent-acp 返回的 id="effort" 选项不含 category 字段(参见 tests/test_claude_acp.py 夹具),导致实测调用 list_models("claude", ...) 时默认模型的 supported_efforts 静默丢失为 None;
      • (b) 原生 dsh --profile acp 的 reasoning_effort.options 首项为 {"value": "", "name": "Provider default"}(参见 tests/test_dsh_acp.py),未过滤空字符串会使返回的 supported_efforts 混入非法空串 ""。
    • 具体修改建议:将 option.id 匹配集合扩展为 {"thinking", "effort", "reasoning", "reasoning_effort"},并对候选值过滤空字符串(cleaned = [v for v in offered if v])。
  3. 旧版 dsh-acp-demo 执行只读 list_models 时未隔离 DSH_SNAPSHOT_SESSIONS_ROOT,直接污染用户业务项目根目录(建议同步至 #45 修复)

    • 位置:src/agent_bridge/adapters/acp.py:782-783, 796-809(配合 src/agent_bridge/dsh_home.py 的 prepare_dsh_launch)
    • 触发场景:list_models 标注为 READ_ONLY,但调用 prepare_dsh_launch(cmd, env) 时未传入 session_id,导致未注入 DSH_SNAPSHOT_SESSIONS_ROOT,使旧版 dsh-acp-demo 在执行 new_session 时直接在用户项目 cwd 下创建 ./.sessions/ 目录及空会话文件。
    • 具体修改建议:在 self.home 下分配专用临时会话目录注入 env["DSH_SNAPSHOT_SESSIONS_ROOT"],并在 _cleanup_discovery 中清理。

2. 建议改进(建议一并同步至 #45)

  1. 细化 _model_locks 并发锁粒度并合并并发刷新(src/agent_bridge/registry.py:173, 621-626):当前锁按 agent 粗粒度互斥且位于 asyncio.timeout(timeout_sec) 内部,不同项目 cwd 同时首次探测慢速 Worker 时易在等锁阶段超时,且并发 refresh=True 会重复拉起两次子进程;建议改为按 (agent, resolved) 的 single-flight Future 合并在途探测。
  2. 保留 codex app-server 的 stderr 尾部诊断并补齐 parse_codex_models 结构校验(src/agent_bridge/model_discovery_exec.py:23-36, 48-55, 129、tests/test_model_discovery_exec.py:105, 301):捕获 codex app-server 的限长 stderr 经 redact_diagnostic 附入异常消息;在 parse_codex_models 中校验 isinstance(entry, Mapping) 与字符串 id,并将测试夹具中已编写但漏挂的 "malformed" 加入 @pytest.mark.parametrize。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants