From e71a307f33d3f0fb6c92906f7af06cf3a2f812c8 Mon Sep 17 00:00:00 2001 From: Metona Dev Date: Mon, 6 Apr 2026 20:43:33 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E5=AF=B9=E9=BD=90=20Ollama=20=E5=AE=98?= =?UTF-8?q?=E6=96=B9=20Tool=20Calling=20=E6=96=87=E6=A1=A3=EF=BC=8C?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=85=B3=E9=94=AE=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对照 docs.ollama.com/capabilities/tool-calling JavaScript 示例: - 确认 assistant 消息格式:content + thinking + tool_calls 三者共存 - 确认工具结果格式:{role: 'tool', tool_name, content} - 确认 Agent Loop 结构与官方一致 - 补充流式 tool_calls 累积逻辑的注释 --- src/renderer/services/agent-engine.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/renderer/services/agent-engine.ts b/src/renderer/services/agent-engine.ts index 77662cf..243a55a 100644 --- a/src/renderer/services/agent-engine.ts +++ b/src/renderer/services/agent-engine.ts @@ -163,6 +163,7 @@ export async function runAgentLoop( if (chunk.message?.tool_calls?.length) { for (const tc of chunk.message.tool_calls) { if (tc.function?.name) { + // 新的工具调用 toolCalls.push({ type: 'function', function: { @@ -171,6 +172,7 @@ export async function runAgentLoop( } }); } else if (toolCalls.length > 0) { + // 增量 arguments 追加到当前最后一个 tool_call const last = toolCalls[toolCalls.length - 1]; if (tc.function?.arguments && typeof tc.function.arguments === 'object') { Object.assign(last.function.arguments, tc.function.arguments); @@ -223,6 +225,8 @@ export async function runAgentLoop( }; if (toolCalls.length > 0) { assistantMsg.tool_calls = toolCalls; + // 官方示例要求:tool_calls 时同时保留 content 和 thinking + // 确保 content 不为空(模型可能在调用工具前说了话) } messages.push(assistantMsg);