Skip to content

Commit c524511

Browse files
committed
Make parsing response to with n more lenient
1 parent 827b3e1 commit c524511

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/agent-runtime/src/run-agent-step.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,18 @@ export const runAgentStep = async (
288288
onCostCalculated,
289289
n: params.n,
290290
})
291-
const nResponses = JSON.parse(responsesString) as string[]
291+
292+
let nResponses: string[]
293+
try {
294+
nResponses = JSON.parse(responsesString) as string[]
295+
if (!Array.isArray(nResponses)) {
296+
// If it parsed but isn't an array, treat as single response
297+
nResponses = [responsesString]
298+
}
299+
} catch (e) {
300+
// If parsing fails, treat as single raw response (common for n=1)
301+
nResponses = [responsesString]
302+
}
292303

293304
// Update agent state with the message history including the generations
294305
agentState = {

0 commit comments

Comments
 (0)