Skip to content

Commit 14b6e41

Browse files
jslim-23joonlim
andauthored
fix(components): reuse extracted response content for ConditionAgent JSON parsing (#6072)
* fix: normalize conditionagent response content before parsing * fix(components): reuse normalized response content in ConditionAgent --------- Co-authored-by: joonlim <joonlim@joonlims-Mac-Studio.local>
1 parent d16c97e commit 14b6e41

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

packages/components/nodes/agentflow/ConditionAgent/ConditionAgent.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,12 @@ class ConditionAgent_Agentflow implements INode {
391391
// Calculate execution time
392392
const endTime = Date.now()
393393
const timeDelta = endTime - startTime
394+
const responseContent = extractResponseContent(response)
394395

395396
// End analytics tracking (pass structured output with usage metadata)
396397
if (analyticHandlers && llmIds) {
397398
const analyticsOutput: any = {
398-
content: extractResponseContent(response)
399+
content: responseContent
399400
}
400401
// Include usage metadata if available
401402
if (response.usage_metadata) {
@@ -407,19 +408,16 @@ class ConditionAgent_Agentflow implements INode {
407408
}
408409
await analyticHandlers.onLLMEnd(llmIds, analyticsOutput, { model: modelName, provider: model })
409410
}
410-
411411
let calledOutputName: string
412412
try {
413-
const parsedResponse = this.parseJsonMarkdown(response.content as string)
413+
const parsedResponse = this.parseJsonMarkdown(responseContent)
414414
if (!parsedResponse.output || typeof parsedResponse.output !== 'string') {
415415
throw new Error('LLM response is missing the "output" key or it is not a string.')
416416
}
417417
calledOutputName = parsedResponse.output
418418
} catch (error) {
419419
throw new Error(
420-
`Failed to parse a valid scenario from the LLM's response. Please check if the model is capable of following JSON output instructions. Raw LLM Response: "${
421-
response.content as string
422-
}"`
420+
`Failed to parse a valid scenario from the LLM's response. Please check if the model is capable of following JSON output instructions. Raw LLM Response: "${responseContent}"`
423421
)
424422
}
425423

@@ -472,7 +470,7 @@ class ConditionAgent_Agentflow implements INode {
472470

473471
const output: any = {
474472
conditions,
475-
content: extractResponseContent(response),
473+
content: responseContent,
476474
timeMetadata: {
477475
start: startTime,
478476
end: endTime,

0 commit comments

Comments
 (0)