From 8bf6572e5b69ea6c5e23eef31a8baa7003928d40 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 1 Jul 2026 16:41:25 +0000 Subject: [PATCH] fix(ai): continue durable agent tool loops (#2730) Signed-off-by: Nathan Colosimo <110621881+NathanColosimo@users.noreply.github.com> --- .changeset/durable-agent-tool-stop-detection.md | 5 +++++ packages/ai/src/agent/stream-text-iterator.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/durable-agent-tool-stop-detection.md diff --git a/.changeset/durable-agent-tool-stop-detection.md b/.changeset/durable-agent-tool-stop-detection.md new file mode 100644 index 0000000000..4a5938084f --- /dev/null +++ b/.changeset/durable-agent-tool-stop-detection.md @@ -0,0 +1,5 @@ +--- +'@workflow/ai': patch +--- + +Continue DurableAgent tool loops whenever a model step contains tool calls, regardless of the reported finish reason. diff --git a/packages/ai/src/agent/stream-text-iterator.ts b/packages/ai/src/agent/stream-text-iterator.ts index 07b7e87bd5..112672249d 100644 --- a/packages/ai/src/agent/stream-text-iterator.ts +++ b/packages/ai/src/agent/stream-text-iterator.ts @@ -327,7 +327,7 @@ export async function* streamTextIterator({ // Normalize finishReason - AI SDK v6 returns { unified, raw }, v5 returns a string const finishReason = normalizeFinishReason(finish?.finishReason); - if (finishReason === 'tool-calls') { + if (finishReason === 'tool-calls' || toolCalls.length > 0) { lastStepWasToolCalls = true; // Build reasoning content parts from the step result.