Skip to content

Commit b060233

Browse files
remove isToolCallInProgress (#527)
* remove isToolCallInProgress * Create flat-yaks-sing.md
1 parent c41ebbc commit b060233

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

.changeset/flat-yaks-sing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"agents": patch
3+
---
4+
5+
remove isToolCallInProgress

packages/agents/src/ai-react.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ export function useAgentChat<
218218
const id = nanoid(8);
219219
const abortController = new AbortController();
220220
let controller: ReadableStreamDefaultController;
221-
let isToolCallInProgress = false;
222221
const currentAgent = agentRef.current;
223222

224223
signal?.addEventListener("abort", () => {
@@ -240,9 +239,7 @@ export function useAgentChat<
240239

241240
abortController.abort();
242241
// Make sure to also close the stream (cf. https://github.com/cloudflare/agents-starter/issues/69)
243-
if (!isToolCallInProgress) {
244-
controller.close();
245-
}
242+
controller.close();
246243
});
247244

248245
currentAgent.addEventListener(
@@ -264,14 +261,11 @@ export function useAgentChat<
264261
} else {
265262
// Only enqueue non-empty data to prevent JSON parsing errors
266263
if (data.body?.trim()) {
267-
if (data.body.includes('"tool_calls"')) {
268-
isToolCallInProgress = true;
269-
}
270264
controller.enqueue(
271265
new TextEncoder().encode(`data: ${data.body}\n\n`)
272266
);
273267
}
274-
if (data.done && !isToolCallInProgress) {
268+
if (data.done) {
275269
controller.close();
276270
abortController.abort();
277271
}

0 commit comments

Comments
 (0)