From 072fb10df0adce7c3189dec293783fc941aca0ce Mon Sep 17 00:00:00 2001 From: thzxx Date: Sat, 20 Jun 2026 14:42:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AD=90=E4=BB=A3=E7=90=86=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E6=A8=A1=E5=9E=8B=E6=97=B6=E4=BD=BF=E7=94=A8=E8=AF=A5?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E5=AE=9E=E9=99=85=E4=B8=8A=E4=B8=8B=E6=96=87?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=EF=BC=8C=E8=B7=9F=E9=9A=8F=E4=B8=BBAI?= =?UTF-8?q?=E6=97=B6=E7=94=A8=E4=B8=BBAI=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/services/sub-agent.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/renderer/services/sub-agent.ts b/src/renderer/services/sub-agent.ts index 417102b..cde6727 100644 --- a/src/renderer/services/sub-agent.ts +++ b/src/renderer/services/sub-agent.ts @@ -58,7 +58,23 @@ export async function executeSubAgent( const tools = getSubAgentTools(); const toolNames = [...SUB_AGENT_TOOL_WHITELIST].join(', '); - logInfo(`子 Agent 启动`, `任务: ${task.slice(0, 80)} | 工具: ${toolNames}`); + logInfo(`子 Agent 启动`, `任务: ${task.slice(0, 80)} | 工具: ${toolNames} | 模型: ${model}`); + + // 如果子代理使用了不同于主 AI 的模型,获取该模型的实际上下文长度 + const defaultModel = state.get('_defaultModel', ''); + let numCtx = state.get(KEYS.NUM_CTX, 24576); + if (model !== defaultModel) { + try { + const detail = await api.showModel(model); + const modelInfo = detail.model_info || {}; + for (const key of Object.keys(modelInfo)) { + if (key.endsWith('.context_length')) { + numCtx = Number(modelInfo[key]) || numCtx; + break; + } + } + } catch { /* 获取失败用默认值 */ } + } const systemPrompt = `你是一个子任务执行 Agent,拥有只读工具权限。请高效完成指定任务,给出结果报告。 ${context ? `\n附加上下文:\n${context}` : ''}`; @@ -89,7 +105,7 @@ ${context ? `\n附加上下文:\n${context}` : ''}`; stream: true, think: false, tools: tools as any, - options: { num_ctx: state.get(KEYS.NUM_CTX, 24576), temperature: 0.3 } + options: { num_ctx: numCtx, temperature: 0.3 } } as any, (chunk: any) => { if (chunk.message?.content) content += chunk.message.content; if (chunk.message?.tool_calls?.length) {