Repository navigation
fix(agent-core-v2): reconcile tool definitions after updates - #4719
Conversation
🦋 Changeset detectedLatest commit: 5f204ef The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5f204eff14
ℹ️ 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".
| const added = change.added.filter((tool) => this.isDynamicallyLoadable(tool)); | ||
| const removed = change.removed.filter((tool) => | ||
| this.isDynamicallyLoadable(tool) || !change.added.some( | ||
| (next) => next.name === tool.name && !this.isDynamicallyLoadable(next), | ||
| )); |
There was a problem hiding this comment.
Preserve unsupported-model warnings for inline replacements
When the flag is enabled but a request resolves with dynamically_loaded_tools: false (for example after switching to a model without that capability), a same-name inline schema replacement makes both filtered lists empty here, so no change announcement is persisted. defaultToolsForDisclosure(false) still builds from initialTools(), while shapeUnsupportedDynamicToolContext uses these announcements to warn that replaced definitions may fail; the model therefore silently receives the obsolete parameter schema even though the executor validates the replacement, so calls whose parameters changed can fail. Preserve this replacement in the unsupported-model projection or expose its current schema there.
AGENTS.md reference: AGENTS.md:L110-L112
Useful? React with 👍 / 👎.
Requirement or Bug
启用动态工具加载的会话在工具更新后,可能向模型同时声明同名工具的不同版本;恢复已保存的会话后,冲突还会继续出现。内联工具更新也会注入没有实际工具增删的提醒。本 PR 修复请求中的定义冲突,并跳过这类空公告。
Bug Reproduction Steps
select_tools加载;加载后,新定义出现在历史system.tools中。added、removed均为空的公告。回归测试使用构造的工具和保存状态复现,无需模型网络请求或真实用户日志。
Root Cause
初始工具快照用于稳定工具列表,但按名称排除 runtime 工具时,也排除了初始工具的新版定义。动态加载从当前定义取 schema,历史投影又没有收到实际顶层工具列表,因此两个版本会一起进入请求。旧加载状态还会把重新归为内联的工具判为不可执行。
公告按变化记录逐条生成;过滤掉内联替换后,即使没有剩余增删,旧实现仍返回一条提醒。
这是 Core 内部的根因修复:保留原始快照和持久化历史,只统一当前请求使用的定义、加载判断和公告。
Code Changes
主要逻辑在
toolSelectService.ts;toolSelect.ts为历史投影增加可选工具列表参数,toolSelectPolicy.ts传入本次请求实际使用的列表。真正新增的 runtime 工具和原本 deferred 的工具继续按已有流程加载。Behavior Changes and Affected Users
select_tools106 项聚焦测试全部通过,覆盖构造旧状态并恢复、实际 Kimi 请求编码、本地 executor 执行、保留未变化工具和 deferred 工具、显式工具列表、MCP 新旧 schema、跳过空公告后的动态增删及权限变化。Core 类型检查及注释检查通过;局部类型感知 lint 为 0 错误,7 条警告均位于未修改的现有语句。
验证边界:没有请求线上模型,也没有读取或复测真实用户的原始会话。真实原会话仍需在包含修复的版本中继续对话验证。
验证命令
pnpm -C packages/agent-core-v2 exec vitest run test/agent/toolSelect/toolSelectService.test.ts test/agent/toolSelect/dynamicTools.test.ts --config vitest.config.tspnpm -C packages/agent-core-v2 exec tsc --noEmit -p tsconfig.jsonoxlint --type-awarenode scripts/check-no-comments.mjsgit diff --checkChecklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.目前未关联已获维护者
/approve的 issue;本 PR 提供独立复现、修复和回归验证。没有新增命令、配置或需要同步的公开文档。