Langchain Retriever Agent Function Not Passing "ChatMessageHistory" When Called in Console - Python

Hello everyone,

I am facing an issue with a Python function that I have created to handle some chat functionality with the GPT-3.5 Turbo model. The function is part of a bigger project that aims to use Pinecone to search and retrieve similar documents.

Here is a simplified version of my code:

def pineconeGPT(system, user, questions, answers, instruction, metadata={}):
  llm = ChatOpenAI(model='gpt-3.5-turbo-16k', temperature=0, openai_api_key="key")
  embeddings = OpenAIEmbeddings(openai_api_key="key", model="text-embedding-ada-002")
  pinecone.init(api_key='key', environment='region')
  index = Pinecone.from_existing_index('index_name', embeddings)
  history = ChatMessageHistory()
  if len(questions) > 0:
      for i in range(len(questions)):
  retriever = index.as_retriever(search_type="similarity", search_kwargs={'filter': metadata})
  pineconeIndex = create_retriever_tool(
      "Searches and returns documents regarding the similarity."
  tools = [pineconeIndex]
  system_message = SystemMessage(content=(system))
  prompt = OpenAIFunctionsAgent.create_prompt(system_message=system_message)
  agent = OpenAIFunctionsAgent(llm=llm, tools=tools, prompt=prompt)
  agent_executor = AgentExecutor(
  result = agent_executor({"input": instruction})

The problem is that when I call this function under Langchain in the console, the ChatMessageHistory (history variable) is not being passed along as it should be. I’ve verified this by examining the call and found that history = ChatMessageHistory() is not being passed.

What I’ve tried:

  • Called retriever tool and history separately. Read the documentation and all logic seems correct
  • Checked the API keys and other credentials
  • Ensured that Pinecone and other modules are working as expected

I would appreciate any insights on what might be causing this issue and how to resolve it. Thank you in advance!