mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(AI Agent Node): Add binary message before scratchpad to prevent tool calling loops (#11845)
This commit is contained in:
@@ -258,7 +258,6 @@ export async function toolsAgentExecute(this: IExecuteFunctions): Promise<INodeE
|
||||
['system', `{system_message}${outputParser ? '\n\n{formatting_instructions}' : ''}`],
|
||||
['placeholder', '{chat_history}'],
|
||||
['human', '{input}'],
|
||||
['placeholder', '{agent_scratchpad}'],
|
||||
];
|
||||
|
||||
const hasBinaryData = this.getInputData(0, 'main')?.[0]?.binary !== undefined;
|
||||
@@ -266,6 +265,9 @@ export async function toolsAgentExecute(this: IExecuteFunctions): Promise<INodeE
|
||||
const binaryMessage = await extractBinaryMessages(this);
|
||||
messages.push(binaryMessage);
|
||||
}
|
||||
// We add the agent scratchpad last, so that the agent will not run in loops
|
||||
// by adding binary messages between each interaction
|
||||
messages.push(['placeholder', '{agent_scratchpad}']);
|
||||
const prompt = ChatPromptTemplate.fromMessages(messages);
|
||||
|
||||
const agent = createToolCallingAgent({
|
||||
|
||||
Reference in New Issue
Block a user