{"version":3,"file":"openai_functions.cjs","names":["OpenAIAgentTokenBufferMemory","ConversationSummaryBufferMemory","initializeAgentExecutorWithOptions"],"sources":["../../../../src/agents/toolkits/conversational_retrieval/openai_functions.ts"],"sourcesContent":["import { StructuredToolInterface } from \"@langchain/core/tools\";\nimport { ChatOpenAI } from \"@langchain/openai\";\nimport { ConversationSummaryBufferMemory } from \"../../../memory/summary_buffer.js\";\nimport { initializeAgentExecutorWithOptions } from \"../../initialize.js\";\nimport { OpenAIAgentTokenBufferMemory } from \"./token_buffer_memory.js\";\n\nexport type ConversationalRetrievalAgentOptions = {\n  rememberIntermediateSteps?: boolean;\n  memoryKey?: string;\n  outputKey?: string;\n  inputKey?: string;\n  prefix?: string;\n  verbose?: boolean;\n};\n\n/**\n * Asynchronous function that creates a conversational retrieval agent\n * using a language model, tools, and options. It initializes the buffer\n * memory based on the provided options and initializes the AgentExecutor\n * with the tools, language model, and memory.\n * @param llm Instance of ChatOpenAI used as the language model for the agent.\n * @param tools Array of StructuredTool instances used by the agent.\n * @param options Optional ConversationalRetrievalAgentOptions to customize the agent.\n * @returns A Promise that resolves to an initialized AgentExecutor.\n */\nexport async function createConversationalRetrievalAgent(\n  llm: ChatOpenAI,\n  tools: StructuredToolInterface[],\n  options?: ConversationalRetrievalAgentOptions\n) {\n  const {\n    rememberIntermediateSteps = true,\n    memoryKey = \"chat_history\",\n    outputKey = \"output\",\n    inputKey = \"input\",\n    prefix,\n    verbose,\n  } = options ?? {};\n  let memory;\n  if (rememberIntermediateSteps) {\n    memory = new OpenAIAgentTokenBufferMemory({\n      memoryKey,\n      llm,\n      outputKey,\n      inputKey,\n    });\n  } else {\n    memory = new ConversationSummaryBufferMemory({\n      memoryKey,\n      llm,\n      maxTokenLimit: 12000,\n      returnMessages: true,\n      outputKey,\n      inputKey,\n    });\n  }\n  const executor = await initializeAgentExecutorWithOptions(tools, llm, {\n    agentType: \"openai-functions\",\n    memory,\n    verbose,\n    returnIntermediateSteps: rememberIntermediateSteps,\n    agentArgs: {\n      prefix:\n        prefix ??\n        `Do your best to answer the questions. Feel free to use any tools available to look up relevant information, only if necessary.`,\n    },\n  });\n  return executor;\n}\n"],"mappings":";;;;;;;;;;;;;;AAyBA,eAAsB,mCACpB,KACA,OACA,SACA;CACA,MAAM,EACJ,4BAA4B,MAC5B,YAAY,gBACZ,YAAY,UACZ,WAAW,SACX,QACA,YACE,WAAW,EAAE;CACjB,IAAI;AACJ,KAAI,0BACF,UAAS,IAAIA,4BAAAA,6BAA6B;EACxC;EACA;EACA;EACA;EACD,CAAC;KAEF,UAAS,IAAIC,uBAAAA,gCAAgC;EAC3C;EACA;EACA,eAAe;EACf,gBAAgB;EAChB;EACA;EACD,CAAC;AAaJ,QAXiB,MAAMC,mBAAAA,mCAAmC,OAAO,KAAK;EACpE,WAAW;EACX;EACA;EACA,yBAAyB;EACzB,WAAW,EACT,QACE,UACA,kIACH;EACF,CAAC"}