-
Notifications
You must be signed in to change notification settings - Fork 119
fix: filter unregistered profile tools from active set and improve missing tool error #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@moonshot-ai/agent-core": patch | ||
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Filter unregistered profile tools from active set and warn when they require configuration. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,13 @@ export class ToolManager { | |
| protected enabledTools: Set<string> = new Set(); | ||
| /** Glob patterns (e.g. `mcp__*`, `mcp__github__*`) gating which MCP tools the profile exposes. */ | ||
| private mcpAccessPatterns: string[] = []; | ||
| /** | ||
| * Profile-requested builtin tool names that could not be resolved because | ||
| * `initializeBuiltinTools()` had not run yet. Replayed once builtins are | ||
| * available so tools such as `WebSearch` — which require a service that may | ||
| * be present at init time — are not silently dropped on first profile apply. | ||
| */ | ||
| private pendingBuiltinToolNames: string[] = []; | ||
| protected readonly store: Partial<ToolStoreData> = {}; | ||
| private mcpToolStatusUnsubscribe: (() => void) | undefined; | ||
|
|
||
|
|
@@ -297,7 +304,26 @@ export class ToolManager { | |
| }); | ||
| // MCP entries are glob patterns gated separately; the rest are exact | ||
| // builtin/user tool names. The split keeps every caller on one string[]. | ||
| this.enabledTools = new Set(names.filter((name) => !isMcpToolName(name))); | ||
| const nonMcpNames = names.filter((name) => !isMcpToolName(name)); | ||
| const availableNames = nonMcpNames.filter( | ||
| (name) => this.builtinTools.has(name) || this.userTools.has(name), | ||
| ); | ||
| const missingTools = nonMcpNames.filter((name) => !availableNames.includes(name)); | ||
| if (missingTools.length > 0) { | ||
| if (this.builtinTools.size > 0) { | ||
| // Builtins are fully initialized — missing tools are genuinely unavailable. | ||
| this.agent.log.warn( | ||
| `The following tools listed in the active profile are not available and will be omitted: ${missingTools.join(', ')}. ` + | ||
| `They may require additional service configuration.`, | ||
| ); | ||
| } | ||
| // Save pending builtin names so they can be re-applied once builtins | ||
| // are initialized (e.g. when the model is configured after profile apply). | ||
| this.pendingBuiltinToolNames = missingTools; | ||
| } else { | ||
| this.pendingBuiltinToolNames = []; | ||
| } | ||
| this.enabledTools = new Set(availableNames); | ||
| this.mcpAccessPatterns = names.filter((name) => isMcpToolName(name)); | ||
| } | ||
|
|
||
|
|
@@ -399,6 +425,28 @@ export class ToolManager { | |
| .filter((tool) => !!tool) | ||
| .map((tool) => [tool.name, tool] as const), | ||
| ); | ||
| // Re-apply pending profile tool names that were deferred because builtins | ||
| // had not been initialized when `setActiveTools` was first called. | ||
| if (this.pendingBuiltinToolNames.length > 0) { | ||
| const nowAvailable = this.pendingBuiltinToolNames.filter( | ||
| (name) => this.builtinTools.has(name) || this.userTools.has(name), | ||
| ); | ||
| if (nowAvailable.length > 0) { | ||
| for (const name of nowAvailable) { | ||
| this.enabledTools.add(name); | ||
|
Comment on lines
+430
to
+436
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a profile is applied before builtins are initialized, Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
| const stillMissing = this.pendingBuiltinToolNames.filter( | ||
| (name) => !nowAvailable.includes(name), | ||
| ); | ||
| if (stillMissing.length > 0) { | ||
| this.agent.log.warn( | ||
| `The following tools listed in the active profile are not available and will be omitted: ${stillMissing.join(', ')}. ` + | ||
| `They may require additional service configuration.`, | ||
| ); | ||
| } | ||
| this.pendingBuiltinToolNames = []; | ||
| } | ||
| } | ||
|
|
||
| private createVideoUploader(provider: ChatProvider): b.VideoUploader | undefined { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.