Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,12 @@ class ConditionAgent_Agentflow implements INode {
// Calculate execution time
const endTime = Date.now()
const timeDelta = endTime - startTime
const responseContent = extractResponseContent(response)

// End analytics tracking (pass structured output with usage metadata)
if (analyticHandlers && llmIds) {
const analyticsOutput: any = {
content: extractResponseContent(response)
content: responseContent
}
// Include usage metadata if available
if (response.usage_metadata) {
Expand All @@ -407,19 +408,16 @@ class ConditionAgent_Agentflow implements INode {
}
await analyticHandlers.onLLMEnd(llmIds, analyticsOutput, { model: modelName, provider: model })
}

let calledOutputName: string
try {
const parsedResponse = this.parseJsonMarkdown(response.content as string)
const parsedResponse = this.parseJsonMarkdown(responseContent)
if (!parsedResponse.output || typeof parsedResponse.output !== 'string') {
throw new Error('LLM response is missing the "output" key or it is not a string.')
}
calledOutputName = parsedResponse.output
} catch (error) {
throw new Error(
`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: "${
response.content as string
}"`
`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}"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability in error logs, it's a good practice to truncate long raw responses. The responseContent could be quite large, making the error message difficult to read. Consider truncating it if it exceeds a certain length, similar to how it's done in parseJsonBody.

Suggested change
`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}"`
"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.substring(0, 200) + (responseContent.length > 200 ? "..." : "") + "\""
References
  1. Prioritize code readability and understandability over conciseness. Truncating large blobs in logs improves the readability and utility of error messages for debugging.

)
}

Expand Down Expand Up @@ -472,7 +470,7 @@ class ConditionAgent_Agentflow implements INode {

const output: any = {
conditions,
content: extractResponseContent(response),
content: responseContent,
timeMetadata: {
start: startTime,
end: endTime,
Expand Down
Loading