Skip to content

fix: align subagent tool descriptions with availability - #4066

Open
7Sageer wants to merge 8 commits into
mainfrom
fix/subagent-tool-availability
Open

7Sageer wants to merge 8 commits into
mainfrom
fix/subagent-tool-availability

Conversation

@7Sageer

@7Sageer 7Sageer commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

子 agent 的工具描述可能列出实际无法启用的工具,例如未配置搜索服务时仍宣称可以使用 WebSearch。

Bug Reproduction Steps

  1. 在没有配置 WebSearch provider 或托管搜索凭据的环境中启动会话。
  2. 查看 Agent 工具描述中的 explore 工具名单,其中仍包含 WebSearch。
  3. 创建 explore 子 agent,其实际工具列表没有 WebSearch。

关闭 WaitFor 或缺少工具所需的运行环境能力时,也会出现相同问题。

Root Cause

工具初次激活会检查贡献的 when 条件和运行环境能力,但描述生成只枚举静态贡献。两处现在复用同一套可用性判断,描述继续按目标子 agent 的 profile 叠加全局、session 和 workspace 工具策略。

媒体工具和动态工具需要按子模型判断。候选列表统一处理可选或强制子模型的能力,避免依赖父模型的注册结果;显式工具名单和未声明 tools 的 profile 共用这一候选列表。实际注册的用户同名工具优先于内置贡献。

Code Changes

工具描述
- 静态贡献名单及独立 NotifyUser 判断
+ 共用 runtime / when 可用性检查,保留用户同名覆盖
+ 按候选子模型计算媒体工具与 select_tools 的描述
+ 未声明 tools 的 profile 展示具体可用名单

工具初次注册
- 内联 runtime / when 检查
+ 共用可用性检查

工具生命周期保持原有语义:普通激活跳过已注册工具;runtime 变化只撤销不再满足 runtime 要求的工具。when 失效会从描述中移除内置贡献,但不会因此注销已注册工具。WebSearch 在执行时仍能返回搜索配置已移除的明确错误。

子 agent 继续继承调用方的 runtime 和用户工具;模型选择策略与 MCP 通配符规则不变。

Behavior Changes and Affected Users

行为 变化前 变化后 受影响人群 退路
条件工具描述 可能列出不可用的 WebSearch、WaitFor 或依赖 runtime 的工具 根据当前运行条件过滤 缺少搜索配置、关闭 WaitFor 或使用受限运行环境的会话 配置搜索服务、开启对应 flag 或恢复环境能力
未声明工具名单的 profile 显示 Tools: all 或 all except ... 列出当前可用且策略允许的具体工具 自定义 agent 用户 工具权限不变;不再提供旧的笼统展示格式
媒体工具描述 部分枚举路径依赖父模型的注册结果 所有 profile 共用子模型媒体候选项 父子模型媒体能力不同或强制子模型的用户 调整子模型配置;实际模型能力和工具权限不变
动态工具描述 可能列出不可用的 select_tools 同时检查动态工具 flag 和候选子模型能力 未声明 tools 的自定义 agent 用户 开启 flag 并选择支持动态工具的子模型
用户同名工具覆盖 描述可能采用内置贡献的可用条件 保留实际注册的用户同名工具 注册自定义工具的 SDK 调用方 删除用户覆盖即可使用内置工具
explore 联网指引 无条件建议 WebSearch 或 FetchURL 以相应工具可用为前提 新创建的 explore agent 工具可用时仍提供联网指引
plan 联网指引 无条件宣称可以联网 以联网工具可用为前提 新创建的 plan agent 工具可用时仍可联网

测试覆盖搜索 provider 缺失与恢复、WaitFor / NotifyUser 条件、runtime 要求、用户覆盖、profile 限制及父子模型能力组合。新增 runtime 事件回归测试验证:when 失效后,runtime 变化仍保留满足 runtime 要求的已注册工具,也保留没有 runtime 要求的工具;既有测试继续覆盖能力失效时的撤销及恢复。

验证:

  • 激活服务与工具描述定向测试:57 项通过,其他 108 项未运行。
  • 新增 runtime 事件回归用例在修复前失败、修复后通过。
  • 引擎 TypeScript 类型检查、变更文件的 lint / type-aware lint、无注释检查通过。

模型相关描述表达候选模型的可选能力;未强制模型时,不保证任意选中的模型都具备候选集合中的全部工具。本 PR 未新增跨模型 spawn 集成测试。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue(直接报告,未提供独立 issue)。
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill;沿用现有 CLI patch changeset,本次修订恢复原有生命周期,无需重复条目。
  • Ran gen-docs skill;使用方式和配置语义不变,相关内置联网指引已同步调整,无需新增用户文档。

@changeset-bot

changeset-bot Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f400e7d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@7Hanrui

7Hanrui commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c305d4436b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +264 to +267
const target: ToolAvailabilityTarget = {
isSubagentPreview: true,
environment: this.environment,
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid filtering subagent tools by the caller environment

When the experimental environment argument sends a subagent to a different environment, this preview evaluates capability-gated tools against the caller's binding instead. SessionSubagentService.spawn resolves that argument into a separate child binding before activation, so a caller in a process-only environment will have Read/Edit omitted from the Agent description even when the selected target has fs (and a filesystem-capable caller can advertise them for a process-only target). Do not use the caller environment to prune descriptions when the eventual subagent environment is selectable.

Useful? React with 👍 / 👎.

Comment on lines +277 to +279
return this.knownToolReferences().filter(
(ref) => !contributionNames.has(ref.name) || available.has(ref.name),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve user-tool overrides in subagent descriptions

When a user registers a tool named WebSearch while no web-search provider is configured, the registry keeps that user tool and SessionSubagentService inherits it into the child. This filter nevertheless sees the built-in WebSearch contribution, marks it unavailable, and removes the name even though the live registry entry is the user tool. Consequently profiles that allow WebSearch are described as lacking a tool the subagent will actually receive. Base the availability filter on the live entry/source, not merely on a same-named contribution.

Useful? React with 👍 / 👎.

@7Sageer
7Sageer force-pushed the fix/subagent-tool-availability branch from c305d44 to fca3586 Compare September 28, 2026 11:36
@7Sageer
7Sageer changed the base branch from feat/remote-runtime to main September 28, 2026 11:37
@7Hanrui

7Hanrui commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: fca3586755

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copilot AI balanced review requested due to automatic review settings September 29, 2026 04:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@7Hanrui

7Hanrui commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 719a615393

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@7Hanrui

7Hanrui commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: d553c86fc7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@7Hanrui

7Hanrui commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 9db8e24411

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@7Hanrui

7Hanrui commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f3e555807

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

capabilities.dynamically_loaded_tools === true && capabilities.tool_use,
)
) {
refs.delete(SELECT_TOOLS_TOOL_NAME);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve user overrides of select_tools

When an SDK caller registers a user tool named select_tools and the experimental flag is disabled (the default) or no selectable subagent model supports dynamic tools, this branch removes that live user-tool reference. The preceding loop deliberately preserves user sources, and SessionSubagentService inherits user tools into child agents, so profiles that allow it receive a functioning tool despite the Agent description withholding it. Restrict this deletion to the builtin contribution, as is already done for ReadMediaFile.

AGENTS.md reference: AGENTS.md:L100-L100

Useful? React with 👍 / 👎.

@7Sageer
7Sageer marked this pull request as ready for review September 30, 2026 09:27

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f5722cc3e5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const code = text.codePointAt(i);
if (code >= 0xdc00 && code <= 0xdfff && i > 0) {
const high = text.charCodeAt(i - 1);
const high = text.codePointAt(i - 1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve surrogate pairs while truncating from the end

When compaction truncates a user message whose retained suffix begins at an astral character such as an emoji, codePointAt(i - 1) returns the complete code point rather than the high-surrogate code unit, so this range check fails to decrement i. The character is then counted twice and, at the token boundary, the retained text can begin with an isolated low surrogate (for example, truncating "x😀" to one estimated token returns "\uDE00"), corrupting the compacted prompt; these UTF-16 checks need to remain code-unit based.

AGENTS.md reference: AGENTS.md:L98-L100

Useful? React with 👍 / 👎.

@pkg-pr-new

pkg-pr-new Bot commented Sep 30, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@f400e7d
npx https://pkg.pr.new/@moonshot-ai/kimi-code@f400e7d

commit: f400e7d

This branch has not been deployed

No deployments
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.

3 participants