mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(AI Agent Node): Escape curly brackets in tools description for non Tool agents (#11772)
This commit is contained in:
@@ -165,10 +165,29 @@ export function serializeChatHistory(chatHistory: BaseMessage[]): string {
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
export function escapeSingleCurlyBrackets(text?: string): string | undefined {
|
||||
if (text === undefined) return undefined;
|
||||
|
||||
let result = text;
|
||||
|
||||
result = result
|
||||
// First handle triple brackets to avoid interference with double brackets
|
||||
.replace(/(?<!{){{{(?!{)/g, '{{{{')
|
||||
.replace(/(?<!})}}}(?!})/g, '}}}}')
|
||||
// Then handle single brackets, but only if they're not part of double brackets
|
||||
// Convert single { to {{ if it's not already part of {{ or {{{
|
||||
.replace(/(?<!{){(?!{)/g, '{{')
|
||||
// Convert single } to }} if it's not already part of }} or }}}
|
||||
.replace(/(?<!})}(?!})/g, '}}');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export const getConnectedTools = async (
|
||||
ctx: IExecuteFunctions,
|
||||
enforceUniqueNames: boolean,
|
||||
convertStructuredTool: boolean = true,
|
||||
escapeCurlyBrackets: boolean = false,
|
||||
) => {
|
||||
const connectedTools =
|
||||
((await ctx.getInputConnectionData(NodeConnectionType.AiTool, 0)) as Tool[]) || [];
|
||||
@@ -189,6 +208,10 @@ export const getConnectedTools = async (
|
||||
}
|
||||
seenNames.add(name);
|
||||
|
||||
if (escapeCurlyBrackets) {
|
||||
tool.description = escapeSingleCurlyBrackets(tool.description) ?? tool.description;
|
||||
}
|
||||
|
||||
if (convertStructuredTool && tool instanceof N8nTool) {
|
||||
finalTools.push(tool.asDynamicTool());
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user