LangChain OpenAI Agent with Sources

27 Views Asked by At

I am working on building a co-pilot using node LangChain. Right now I am trying to create an agent that can use a vector retrieval tool and return the source/citations. I have the model correctly using the vector store, however, I cannot seem to find a way to get it to return the sources. Could use some advice or resources on how to do it.

Thanks!

const llm = new ChatOpenAI({
      temperature: 0,
      modelName: "..."
    });

const tools = [createRetrieverTool(getDocumentsVectorStore().asRetriever(), {
    name: 'Investor_Documents_Search',
    description:
      'Search for documents and information about any share holder or investor from this tool.'
  })];

const memory = ...
const agent = await createOpenAIToolsAgent({
      llm,
      tools,
      prompt
    });

const agentExecutor = new AgentExecutor({
      agent,
      tools,
      memory,
      returnIntermediateSteps: true,
      verbose: true
    });

return agentExecutor.invoke({
        input: query
      })

Current Output strucutre:

{
   input: "...",
   output: "...",
   history: "..."
}
0

There are 0 best solutions below