Skip to content

fix: direct skill invocation through Skill tool - #4713

Merged
RealKai42 merged 2 commits into
mainfrom
fix/skill-invocation-contract
Nov 9, 2026
Merged

RealKai42 merged 2 commits into
mainfrom
fix/skill-invocation-contract

Conversation

@RealKai42

@RealKai42 RealKai42 commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

使用兼容 provider 的模型在执行技能时,可能绕过 Skill 工具并直接读取 SKILL.md。这条路径不会执行既有的参数与 session context 渲染,导致依赖这些上下文的技能失败。

本 PR 统一模型侧的技能加载指引:发现阶段只提供名称和描述,执行阶段通过 Skill 进入既有渲染与激活路径。

Bug Reproduction Steps

  1. 在工作区启用一个技能,其正文包含 $ARGUMENTS 或 ${KIMI_SESSION_ID},并要求模型执行该技能。
  2. 模型根据旧系统提示和清单中的路径,使用 Read 直接读取 SKILL.md,而不是调用 Skill。
  3. 模型继续执行读取到的原始指令,占位符仍是字面文本;依赖真实 session ID 的脚本随后报告缺少会话 ID,模型转去探测环境变量和服务状态。

Root Cause

旧系统提示明确要求“read the skill file for its instructions”,模型技能清单又逐项暴露 SKILL.md 路径,与 Skill 工具描述中的调用要求形成两条相互竞争的路径。

直接读取文件不会经过既有的技能渲染与激活实现,因此 $ARGUMENTS、${KIMI_SESSION_ID} 和激活记录都不会按正式路径处理。内置技能的路径还是 builtin://… 这样的伪路径,Read 打不开,照旧提示走一定失败。本 PR 修复的是造成错误选择的提示与清单契约,不增加运行时硬拦截;实际模型选择仍需通过实模型评测验证。

Code Changes

核心思路是让发现与执行各自承担单一职责:发现清单只负责技能匹配,Skill 负责加载和激活。清单不再逐项给出 SKILL.md 路径,改为在末尾列一次技能根目录,供检查或编辑技能时定位文件;技能加载后,<skill-loaded dir="..."> 继续提供该技能的目录。

  技能发现
- 名称 + 描述 + 每项的 SKILL.md 路径
+ 名称 + 描述,末尾列一次技能根目录(### Skill roots)
    ↓
- 系统提示引导直接 Read
+ 系统提示引导调用 Skill
    ↓
  Skill(skill, args)
    ↓
  既有参数 / session context 渲染与激活路径
    ↓
  <skill-loaded dir="...">(技能里的相对路径按 dir 解析)
  • profile-shared.ts:只替换一句系统提示,将“读取技能文件”改为“使用 Skill 工具”。
  • registry.ts:模型清单不再逐项输出 Path;有可调用技能时,在清单末尾用 ### Skill roots 列出本次扫描到的技能根目录,这些目录与 Read、Edit、Glob 已允许访问的技能目录相同。
  • skill.md:原有的调用要求保持不变;新增两句:不要通过读取技能文件来调用技能,直接读取只用于检查或编辑技能;技能加载后,其中的相对路径按 <skill-loaded> 的 dir 解析。
  • 测试:覆盖清单结构和 Skill 路径的渲染行为;按 test: remove wording-pinning tests of model-facing prose across both suites #3031 的约定,不新增锁定 prompt 原文的断言。
决策 选择 没选 理由
清单里的路径 去掉逐项 Path,在末尾列一次根目录 保留逐项 Path;完全不给路径 逐项路径正是引导模型直接 Read 的入口;完全不给的话,检查或编辑技能时模型找不到文件,用户级技能不在工作目录里,Glob 也搜不到。Codex 的技能目录同样用 ### Skill roots 列出根目录。
Skill 的调用要求 保持原句不变 增加“在任何任务动作之前调用”、增加调用示例 本 PR 只解决“读文件还是调工具”;调用时机和示例会改变技能的触发频率,需要单独评估。

阅读时先看 registry.ts 和 profile-shared.ts 理解模型可见输入,再看 skill.md 和 skill.test.ts 理解调用契约;其余测试改动可略读。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
系统提示中的技能加载句 引导模型读取技能文件 引导模型调用 Skill 使用模型技能的 TUI、print、desktop/web、VS Code、ACP、SDK 会话,尤其 OpenAI 兼容 provider 无配置回退;检查和编辑技能文件仍可直接 Read
模型技能清单条目 每项额外展示 Path: <SKILL.md> 只展示名称、描述及已有的 When to use 依赖逐项路径去检查或编辑技能文件的会话 清单末尾的 ### Skill roots 列出技能根目录;技能加载后仍提供 dir
模型技能清单末尾 无 有可调用技能时追加 ### Skill roots 和扫描到的根目录;技能变化时的清单更新提醒也带上这几行 无(新增信息) 不涉及
Skill 工具中的直接读取边界 未区分调用技能与读取技能文件 不能通过读取技能文件来调用技能;直接读取只用于检查或编辑技能 技能作者、调试技能文件的模型 检查和编辑技能文件仍可直接 Read
技能内相对路径的解析 未说明,模型可从清单里的路径推出技能目录 按 <skill-loaded> 的 dir 解析 技能正文引用 references/、scripts/ 等相对路径的会话 不需要:dir 属性此前已经存在

受影响模块与覆盖:

  • 系统提示:只替换一句;按 test: remove wording-pinning tests of model-facing prose across both suites #3031 的约定不锁定措辞,由现有的 skills_section 结构测试覆盖。
  • 模型清单:registry.test.ts 覆盖不再逐项输出路径、根目录列在技能之后,以及没有可调用技能时清单仍为空。
  • 技能调用:skill.test.ts 覆盖 $ARGUMENTS 和真实 session ID 经 Skill 路径正确渲染,且加载块带有 dir 属性。
  • 未修改配置键、CLI 参数、wire/state manifest、REST/WebSocket API、SDK 导出或会话存储格式,因此这些客户端和数据不需要迁移。
  • 没有 UI 变化,不需要截图或录屏。尚未用真实 provider 重放会话,模型选择行为仍需后续实模型评测确认。
验证记录
  • 聚焦测试:3 个文件,93 个测试全部通过。
  • 相关测试:29 个文件,831 个测试通过,1 个跳过。
  • pnpm -C packages/agent-core-v2 typecheck:通过。
  • 注释检查通过;改动文件的 oxlint 为 0 error,唯一的 warning 来自 registry.test.ts 中既有的 makeSkill 默认参数。
  • git diff --check:通过。
  • 只读内部标识审计:无阻断项。
  • gen-docs 已评估:公开 /skill: 用法不变,无需文档更新。

Checklist

  • I have read the CONTRIBUTING document.
  • N/A: no external issue; this PR fixes a bug found through an actual session.
  • 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, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 12:47
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T06:09:51.160167Z 9745788 New commits
🔒 Security Review ✅ Completed 2026-11-05T12:52:24.203651Z 49a8efb PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@changeset-bot

changeset-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9745788

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

@pkg-pr-new

pkg-pr-new Bot commented Nov 5, 2026 •

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

commit: 9745788

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.

🔵 Needs a closer look

现有测试仅验证提示文本和渲染路径,尚需在曾复现问题的兼容 provider 上进行真实模型回放,确认模型会遵循新提示调用 Skill,而非直接读取技能文件。

No open issues 🎉

What changed in this PR

本 PR 统一 agent-core-v2 的模型技能加载指引,引导模型通过 Skill 工具进入既有的参数渲染、会话上下文注入和技能激活流程,避免直接读取技能文件而绕过这些处理。改动属于提示与清单契约调整,不增加运行时硬拦截。

Changes:

  • 系统提示改为要求调用 Skill,模型技能清单移除文件路径。
  • 工具描述明确调用顺序、直接读取的例外及参数示例,保留既有去重规则。
  • 补充提示、清单和上下文渲染的回归测试,并添加 CLI patch changeset。
File Description
packages/​agent-core-v2/​test/​features/​skill/​skill.test.ts 验证工具描述及参数、会话 ID 的渲染。
packages/​agent-core-v2/​test/​features/​skill/​catalog/​registry.test.ts 验证模型清单不再包含技能文件路径。
packages/​agent-core-v2/​test/​app/​agentProfileCatalog/​profile-shared.test.ts 防止系统提示恢复直接读取技能文件的指引。
packages/​agent-core-v2/​src/​features/​skill/​tools/​skill.md 明确工具调用要求、读取例外和参数示例。
packages/​agent-core-v2/​src/​features/​skill/​catalog/​registry.ts 移除模型技能清单中的 Path 字段。
packages/​agent-core-v2/​src/​app/​agentProfileCatalog/​profile-shared.ts 将系统提示中的技能加载方式改为调用 Skill。
.changeset/​skill-tool-invocation-contract.md 记录面向用户的技能调用指引修复。

Review effort: Balanced

Restore the original BLOCKING sentence in the Skill tool description and
drop the added timing clause and example. Scope the direct-read rule to
the skill file itself, resolve relative paths in a loaded skill against
its <skill-loaded> dir, and list the scanned skill roots once at the end
of the model skill listing so skills can still be inspected or edited.
Drop the tests that pinned prompt wording.

@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: 9745788896

ℹ️ 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".

@@ -1 +1,3 @@
Invoke a registered skill from the current skill listing. BLOCKING REQUIREMENT: when a skill from the listing matches the user's request, you MUST call this tool (not free-form text). Do not re-invoke a skill to repeat work already done: if a `<skill-loaded>` block for it with the same `args` is already present in the conversation, follow those instructions directly instead of calling the tool again. Do call the tool again when you need the skill with different arguments — the loaded block was expanded with the earlier `args` and will not reflect new inputs. No newline at end of file
Invoke a registered skill from the current skill listing. BLOCKING REQUIREMENT: when a skill from the listing matches the user's request, you MUST call this tool (not free-form text). Do not read a skill's file to invoke it; read the file directly only to inspect or edit the skill. Once a skill is loaded, resolve relative paths in its instructions against the `dir` attribute of its `<skill-loaded>` block.

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 Limit skill-directory rebasing to bundled resources

For existing skills that reference workspace files, this new instruction changes their paths incorrectly. For example, .agents/skills/translate-docs/SKILL.md:15-19 requires checking docs/zh/, docs/en/, and docs/AGENTS.md and stopping if they are missing. Resolving those against the loaded skill's dir instead checks .agents/skills/translate-docs/docs/..., causing an otherwise valid translation task to stop. Likewise, write-tui intentionally mixes workspace-relative apps/kimi-code/AGENTS.md with skill-relative ./DESIGN.md. Restrict this guidance to skill-bundled resources and preserve workspace-relative targets rather than rebasing every path in the instructions.

AGENTS.md reference: AGENTS.md:L118-L120

Useful? React with 👍 / 👎.

@RealKai42
RealKai42 merged commit cd48f5e into main Nov 9, 2026
17 checks passed
@RealKai42
RealKai42 deleted the fix/skill-invocation-contract branch November 9, 2026 06:42
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