Skip to content

Commit

Permalink
Add scratchpad last, instead of splicing in the binary message
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanpaul committed Nov 22, 2024
1 parent 024c95d commit a39bae1
Showing 1 changed file with 4 additions and 2 deletions.
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.splice(3, 0, binaryMessage);
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 a39bae1

Please sign in to comment.