Skip to content

Commit 54a26d8

Browse files
committed
fix(agent-runtime): chain XML tool calls properly to fix missing messages
The bug was that previousPromise was captured at callback creation time instead of execution time, causing each XML tool call to start fresh rather than waiting for the previous one. This fix reads previousToolCallFinished at execution time inside onTagEnd.
1 parent 0edd693 commit 54a26d8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/agent-runtime/src/tools/stream-parser.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ export async function processStream(
136136
) {
137137
const responseHandler = createResponseHandler(isXmlMode)
138138
const resultsArray = isXmlMode ? [] : toolResultsToAddAfterStream
139-
const previousPromise = isXmlMode ? Promise.resolve() : previousToolCallFinished
140139

141140
return {
142141
onTagStart: () => {},
@@ -156,6 +155,13 @@ export async function processStream(
156155
})
157156
: null
158157

158+
// Read previousToolCallFinished at execution time to ensure proper sequential chaining.
159+
// For XML mode, if this is the first tool call (still pointing to streamDonePromise),
160+
// start with a resolved promise so we don't wait for the stream to complete.
161+
const previousPromise = isXmlMode && previousToolCallFinished === streamDonePromise
162+
? Promise.resolve()
163+
: previousToolCallFinished
164+
159165
// Determine which executor to use and with what parameters
160166
let toolPromise: Promise<void>
161167
if (isNativeTool || transformed) {

0 commit comments

Comments
 (0)