fix(core): prevent agent loop from stopping after tool calls with OpenAI-compatible providers (#14973)

Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
This commit is contained in:
Valentin Vivaldi
2026-04-01 23:34:01 -03:00
committed by GitHub
parent 2e8e278441
commit 733a3bd031
2 changed files with 40 additions and 2 deletions

View File

@@ -1362,9 +1362,18 @@ NOTE: At any point in time through this workflow you should feel free to ask the
}
if (!lastUser) throw new Error("No user message found in stream. This should never happen.")
const lastAssistantMsg = msgs.findLast(
(msg) => msg.info.role === "assistant" && msg.info.id === lastAssistant?.id,
)
// Some providers return "stop" even when the assistant message contains tool calls.
// Keep the loop running so tool results can be sent back to the model.
const hasToolCalls = lastAssistantMsg?.parts.some((part) => part.type === "tool") ?? false
if (
lastAssistant?.finish &&
!["tool-calls"].includes(lastAssistant.finish) &&
!hasToolCalls &&
lastUser.id < lastAssistant.id
) {
log.info("exiting loop", { sessionID })