Skip to content

Commit

Permalink
fix(AI Agent Node): Add binary message before scratchpad to prevent t…
Browse files Browse the repository at this point in the history
…ool calling loops (#11845)
  • Loading branch information
jeanpaul authored Nov 22, 2024
1 parent adf026c commit 5c80cb5
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,16 @@ 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;
if (hasBinaryData && passthroughBinaryImages) {
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({
Expand Down

0 comments on commit 5c80cb5

Please sign in to comment.