feat(Functions Agent): use official langchain function executor/agent for better output handling (#538)

* style(FunctionsAgent.js): remove unnecessary comments and update PREFIX variable
refactor(initializeFunctionsAgent.js): update to use initializeAgentExecutorWithOptions
deps(package.json): update langchain to v0.0.95
refactor(askGPTPlugins.js): pass endpointOption to onStart function

* fix(ChatAgent.js): handle undefined delta content in progressMessage.choices array
This commit is contained in:
Danny Avila 2023-06-19 14:15:56 -04:00 committed by GitHub
parent 49e2cdf76c
commit f84da37c9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 28 deletions

View file

@ -1,32 +1,47 @@
const FunctionsAgent = require('./FunctionsAgent');
const { AgentExecutor } = require('langchain/agents');
// const FunctionsAgent = require('./FunctionsAgent');
// const { AgentExecutor, initializeAgentExecutorWithOptions } = require('langchain/agents');
const { initializeAgentExecutorWithOptions } = require('langchain/agents');
const { BufferMemory, ChatMessageHistory } = require('langchain/memory');
const initializeFunctionsAgent = async ({
tools,
model,
pastMessages,
currentDateString,
// currentDateString,
...rest
}) => {
const agent = FunctionsAgent.fromLLMAndTools(
model,
tools,
{
currentDateString,
});
// 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'
outputKey: 'output',
returnMessages: true,
});
return AgentExecutor.fromAgentAndTools({ agent, tools, memory, ...rest });
// return AgentExecutor.fromAgentAndTools({ agent, tools, memory, ...rest });
return await initializeAgentExecutorWithOptions(
tools,
model,
{
agentType: "openai-functions",
memory,
maxIterations: 4,
...rest,
}
);
};
module.exports = initializeFunctionsAgent;