File size: 703 Bytes
3b6afc0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const { initializeAgentExecutorWithOptions } = require('langchain/agents');
const { BufferMemory, ChatMessageHistory } = require('langchain/memory');

const initializeFunctionsAgent = async ({
  tools,
  model,
  pastMessages,
  // currentDateString,
  ...rest
}) => {
  const memory = new BufferMemory({
    chatHistory: new ChatMessageHistory(pastMessages),
    memoryKey: 'chat_history',
    humanPrefix: 'User',
    aiPrefix: 'Assistant',
    inputKey: 'input',
    outputKey: 'output',
    returnMessages: true,
  });

  return await initializeAgentExecutorWithOptions(tools, model, {
    agentType: 'openai-functions',
    memory,
    ...rest,
  });
};

module.exports = initializeFunctionsAgent;