Skip to content

Commit bee5bd7

Browse files
committed
fix: only break loop when respond_to_user is sole tool call
Previously the loop broke after respond_to_user even when other tools ran in the same batch. If the model planned to emit follow-up tool calls (e.g. finish_target) in a subsequent round-trip, those were silently skipped. Now the loop only terminates when respond_to_user was the only tool call — batched tool calls get their follow-up round-trip as intended.
1 parent 2d12322 commit bee5bd7

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

apps/webuiapps/src/components/ChatPanel/useConversationEngine.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ export function useConversationEngine(deps: ConversationEngineDeps) {
160160
currentMessages = [...currentMessages, assistantMsg];
161161

162162
// Execute each tool call
163-
let stopLoop = false;
163+
const hasRespondToUser = response.toolCalls.some(
164+
(tc) => tc.function.name === 'respond_to_user',
165+
);
164166
for (const tc of response.toolCalls) {
165167
const result = await executeToolCall(tc, {
166168
mm,
@@ -172,17 +174,15 @@ export function useConversationEngine(deps: ConversationEngineDeps) {
172174
callbacks: callbacksRef.current,
173175
});
174176
currentMessages = [...currentMessages, result];
175-
// Mark respond_to_user as terminal — still execute remaining tool calls
176-
// (e.g. finish_target) but skip the next model round-trip afterward
177-
if (tc.function.name === 'respond_to_user') {
178-
stopLoop = true;
179-
}
180177
}
181178

182179
// Update chat history (skip system message)
183180
callbacksRef.current.setChatHistory(currentMessages.slice(1));
184181

185-
if (stopLoop) break;
182+
// Only break when respond_to_user was the sole tool call — if other
183+
// tools ran in the same batch the model may still need a follow-up
184+
// round-trip (e.g. finish_target) to commit state updates.
185+
if (hasRespondToUser && response.toolCalls.length === 1) break;
186186
}
187187
}, []);
188188

0 commit comments

Comments
 (0)