mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
34 lines
828 B
JavaScript
34 lines
828 B
JavaScript
|
|
const FunctionsAgent = require('./FunctionsAgent');
|
||
|
|
const { AgentExecutor } = require('langchain/agents');
|
||
|
|
const { BufferMemory, ChatMessageHistory } = require('langchain/memory');
|
||
|
|
|
||
|
|
const initializeFunctionsAgent = async ({
|
||
|
|
tools,
|
||
|
|
model,
|
||
|
|
pastMessages,
|
||
|
|
currentDateString,
|
||
|
|
...rest
|
||
|
|
}) => {
|
||
|
|
const agent = FunctionsAgent.fromLLMAndTools(
|
||
|
|
model,
|
||
|
|
tools,
|
||
|
|
{
|
||
|
|
currentDateString,
|
||
|
|
});
|
||
|
|
|
||
|
|
const memory = new BufferMemory({
|
||
|
|
chatHistory: new ChatMessageHistory(pastMessages),
|
||
|
|
// returnMessages: true, // commenting this out retains memory
|
||
|
|
memoryKey: 'chat_history',
|
||
|
|
humanPrefix: 'User',
|
||
|
|
aiPrefix: 'Assistant',
|
||
|
|
inputKey: 'input',
|
||
|
|
outputKey: 'output'
|
||
|
|
});
|
||
|
|
|
||
|
|
return AgentExecutor.fromAgentAndTools({ agent, tools, memory, ...rest });
|
||
|
|
};
|
||
|
|
|
||
|
|
module.exports = initializeFunctionsAgent;
|
||
|
|
|