fix(AI Agent Node): Add binary message before scratchpad to prevent tool calling loops (#11845)

This commit is contained in:
jeanpaul 2024-11-22 13:47:43 +01:00 committed by GitHub
parent adf026c201
commit 5c80cb57cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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({