From 4df4a40296cc2921f6f86805b5b304ee4a3e5614 Mon Sep 17 00:00:00 2001 From: thzxx Date: Sat, 20 Jun 2026 13:29:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20spawn=5Ftask=20=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=8F=AA=E8=83=BD=E4=BB=8E=E8=AE=BE=E7=BD=AE=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=EF=BC=8C=E7=A6=81=E6=AD=A2=20AI=20=E8=87=AA?= =?UTF-8?q?=E9=80=89=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/services/tool-registry.ts | 27 +++++++++----------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/renderer/services/tool-registry.ts b/src/renderer/services/tool-registry.ts index 18d3fed..4d7692d 100644 --- a/src/renderer/services/tool-registry.ts +++ b/src/renderer/services/tool-registry.ts @@ -478,14 +478,13 @@ export const TOOL_DEFINITIONS: ToolDefinition[] = [ type: 'function', function: { name: 'spawn_task', - description: 'Spawn a sub-agent to independently execute a task using read-only tools (file reading, web search, browser viewing, memory/session/skill queries). Use this to parallelize independent research or analysis sub-tasks. For the model parameter, prefer smaller models (e.g. "qwen3:1.8b", "qwen3:4b") for simple lookups and the current model for complex analysis. Leave blank to use the default configured in Settings.', + description: 'Spawn a sub-agent to independently execute a task using read-only tools (file reading, web search, browser viewing, memory/session/skill queries). Use this to parallelize independent research or analysis sub-tasks. The model is configured in Settings and cannot be overridden per call.', parameters: { type: 'object', required: ['task'], properties: { task: { type: 'string', description: 'The task description for the sub-agent to execute.' }, - context: { type: 'string', description: 'Optional additional context or reference data for the sub-agent.' }, - model: { type: 'string', description: 'Optional model name. If the specified model is not installed, the default model will be used automatically. Best practice: only specify a model you know exists (e.g. "qwen3:1.8b"), or leave blank for the Settings default.' } + context: { type: 'string', description: 'Optional additional context or reference data for the sub-agent.' } } } } @@ -886,28 +885,20 @@ export async function executeTool(toolName: string, args: Record('subAgentModel', ''); - // 校验指定模型是否存在,不存在则回退 + // 只使用设置面板配置的子代理模型,忽略 AI 传入的 model 参数 + const configuredModel = state.get('subAgentModel', ''); let model: string | undefined; - if (specifiedModel) { - try { - const api = state.get(KEYS.API); - const models = await api.listModels(); - const names = new Set(models.models?.map((m: any) => m.name) || []); - if (names.has(specifiedModel)) { - model = specifiedModel; - } else { - logWarn(`子代理指定模型 "${specifiedModel}" 未安装,回退到默认模型`); - } - } catch { model = undefined; } + if (configuredModel) { + // 设置面板存的模型名直接使用(面板加载时已验证过列表) + model = configuredModel; } if (!task) return { success: false, error: '缺少 task 参数' }; - logInfo(`子代理委派: ${task.slice(0, 80)}${model ? ` (模型: ${model})` : ''}`); + logInfo(`子代理委派: ${task.slice(0, 80)}${model ? ` (模型: ${model})` : ' (跟随当前模型)'}`); const result = await executeSubAgent(task, context, model ? { model } : {}); logToolResult('spawn_task', result.success, result.success ? `完成, ${(result as any).loops} 轮` : result.error); return result;