From 78d994fdda15ed5dce4e14d7c5d5c172e8103368 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 5 May 2026 16:31:59 +0000 Subject: [PATCH] fix: handle tool calls in streaming mode - fall back to non-streaming Model says "let me research" then calls web_search tool. Streaming path ignored tool_calls entirely (no-op comment). Now: detect tool_calls delta, cancel stream, fall back to non-streaming which properly executes tools and returns results. --- src/bot/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bot/index.js b/src/bot/index.js index b2802618..edde6fca 100644 --- a/src/bot/index.js +++ b/src/bot/index.js @@ -379,10 +379,11 @@ export async function initBot(config, api, tools, skills, agents) { fullResponse += content; onDelta(content); } - // Check for tool calls in streaming + // Tool calls in streaming - abort stream, fall back to non-streaming (handles tools) if (delta.tool_calls) { - // Tool calls in streaming mode — accumulate and handle after stream - // For now, fall through to non-streaming tool handling + logger.info("Tool call in stream, falling back to non-streaming"); + reader.cancel().catch(() => {}); + return await chatWithAI(body.messages, { maxTokens: body.max_tokens }); } } } catch {