From 7b807ed1cf5c1ad37d5ac80daf2c4d877184edf2 Mon Sep 17 00:00:00 2001 From: dingyi Date: Sat, 29 Aug 2026 04:04:30 +0800 Subject: [PATCH] fix(adapters): ignore empty function_call from streaming deltas Some DeepSeek V4 relays (e.g. openlux) emit an empty function_call object ({ arguments: '', name: '' }) on the final tool_calls chunk. This leaked into additional_kwargs and made the agent see a phantom empty tool call, causing a 105-iteration loop (chatluna issue #1027). Only keep function_call when it carries an actual name or arguments. --- packages/shared-adapter/src/utils.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/shared-adapter/src/utils.ts b/packages/shared-adapter/src/utils.ts index fa0825fb3..b4bcf64c0 100644 --- a/packages/shared-adapter/src/utils.ts +++ b/packages/shared-adapter/src/utils.ts @@ -981,7 +981,14 @@ export function convertDeltaToMessageChunk( function_call?: any reasoning_content?: string } = {} - if (delta.function_call) { + // Some proxies (e.g. DeepSeek V4 relays) emit an empty function_call + // object ({ arguments: '', name: '' }) on the final tool_calls chunk. + // Ignore it so the agent does not see a phantom empty tool call. + if ( + delta.function_call && + ((delta.function_call.name?.length ?? 0) > 0 || + (delta.function_call.arguments?.length ?? 0) > 0) + ) { additionalKwargs.function_call = delta.function_call }