Memory support for OpenAI Functions Agent (#1638)

* Memory support for OpenAI Functions Agent

* Add test, fix .run() method

* Update executor.ts

* Update langchain/src/agents/tests/openai.int.test.ts

* Fix type

---------

Co-authored-by: Nuno Campos <nuno@boringbits.io>
This commit is contained in:
Emil Sedgh
2023-06-14 02:29:25 -07:00
committed by GitHub
parent 9b17b5e2fc
commit e5af8d3250
3 changed files with 15 additions and 2 deletions
+8 -2
View File
@@ -86,7 +86,6 @@ export type InitializeAgentExecutorOptionsStructured =
| ({
agentType: "openai-functions";
agentArgs?: Parameters<typeof OpenAIAgent.fromLLMAndTools>[2];
memory?: never;
} & Omit<AgentExecutorInput, "agent" | "tools">);
/**
@@ -169,10 +168,17 @@ export async function initializeAgentExecutorWithOptions(
return executor;
}
case "openai-functions": {
const { agentArgs, ...rest } = options;
const { agentArgs, memory, ...rest } = options;
const executor = AgentExecutor.fromAgentAndTools({
agent: OpenAIAgent.fromLLMAndTools(llm, tools, agentArgs),
tools,
memory:
memory ??
new BufferMemory({
returnMessages: true,
memoryKey: "chat_history",
inputKey: "input",
}),
...rest,
});
return executor;
+1
View File
@@ -82,6 +82,7 @@ export class OpenAIAgent extends Agent {
const { prefix = PREFIX } = fields || {};
return ChatPromptTemplate.fromPromptMessages([
SystemMessagePromptTemplate.fromTemplate(prefix),
new MessagesPlaceholder("chat_history"),
HumanMessagePromptTemplate.fromTemplate("{input}"),
new MessagesPlaceholder("agent_scratchpad"),
]);
@@ -25,6 +25,12 @@ test("OpenAIAgent", async () => {
const result = await executor.run("What is the weather in New York?");
console.log(result);
const result2 = await executor.run(
"And what is the weather like in the capital of that state?"
);
console.log(result2);
});
test("OpenAIAgent streaming", async () => {