2023-06-19 14:15:56 -04:00
|
|
|
const { initializeAgentExecutorWithOptions } = require('langchain/agents');
|
2023-06-13 23:39:22 -04:00
|
|
|
const { BufferMemory, ChatMessageHistory } = require('langchain/memory');
|
|
|
|
|
|
|
|
|
|
const initializeFunctionsAgent = async ({
|
|
|
|
|
tools,
|
|
|
|
|
model,
|
|
|
|
|
pastMessages,
|
2023-06-19 14:15:56 -04:00
|
|
|
// currentDateString,
|
2023-06-13 23:39:22 -04:00
|
|
|
...rest
|
|
|
|
|
}) => {
|
2023-06-22 20:40:23 -04:00
|
|
|
|
2023-06-13 23:39:22 -04:00
|
|
|
const memory = new BufferMemory({
|
|
|
|
|
chatHistory: new ChatMessageHistory(pastMessages),
|
|
|
|
|
memoryKey: 'chat_history',
|
|
|
|
|
humanPrefix: 'User',
|
|
|
|
|
aiPrefix: 'Assistant',
|
|
|
|
|
inputKey: 'input',
|
2023-06-19 14:15:56 -04:00
|
|
|
outputKey: 'output',
|
|
|
|
|
returnMessages: true,
|
2023-06-13 23:39:22 -04:00
|
|
|
});
|
|
|
|
|
|
2023-06-19 14:15:56 -04:00
|
|
|
return await initializeAgentExecutorWithOptions(
|
|
|
|
|
tools,
|
|
|
|
|
model,
|
|
|
|
|
{
|
|
|
|
|
agentType: "openai-functions",
|
|
|
|
|
memory,
|
|
|
|
|
...rest,
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
2023-06-13 23:39:22 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = initializeFunctionsAgent;
|
|
|
|
|
|