mirror of
https://github.com/Mintplex-Labs/langchainjs.git
synced 2026-07-01 12:17:38 -04:00
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:
@@ -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;
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user