-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(AI Agent Node): Preserve
intermediateSteps
when using output pa…
…rser with non-tool agent (#11363)
- Loading branch information
1 parent
197a126
commit e61a853
Showing
6 changed files
with
32 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { BaseOutputParser } from '@langchain/core/output_parsers'; | ||
import type { IExecuteFunctions } from 'n8n-workflow'; | ||
|
||
export async function extractParsedOutput( | ||
ctx: IExecuteFunctions, | ||
outputParser: BaseOutputParser<unknown>, | ||
output: string, | ||
): Promise<Record<string, unknown> | undefined> { | ||
const parsedOutput = (await outputParser.parse(output)) as { | ||
output: Record<string, unknown>; | ||
}; | ||
|
||
if (ctx.getNode().typeVersion <= 1.6) { | ||
return parsedOutput; | ||
} | ||
// For 1.7 and above, we try to extract the output from the parsed output | ||
// with fallback to the original output if it's not present | ||
return parsedOutput?.output ?? parsedOutput; | ||
} |