Unable to implement memory in RAG agent, asking for chat_history
Labels: name: area: memory, name: area: agent, name: auto:question, name: integration: pinecone

### Issue you'd like to raise.


Hi I am trying to implement memory in an RAG agent and am following documentation, but I get the following error:

ValueError: variable chat_history should be a list of base messages, got 

It seems that I should be passing in a chat_history, but all the notebook examples I have seen only pass the question. I have seen some implementations use initialize_agent(), while others use AgentExecutor(). Any help on how to implement memory with the agent would be greatly appreciated.

this is my implementation:

```from langchain.vectorstores import Pinecone
from langchain.llms import Cohere
from langchain.retrievers.multi_query import MultiQueryRetriever
from langchain.prompts import PromptTemplate
import logging

from langchain.chains import LLMChain, ConversationChain
from langchain.chains.conversation.memory import ConversationBufferWindowMemory
from langchain.chains import RetrievalQA
from langchain.agents import Tool
from langchain.retrievers import ContextualCompressionRetriever
from langchain.retrievers.document_compressors import CohereRerank


index = pinecone.Index(index_name)
vectorstore = Pinecone(index, embeddings, "text")

llm = Cohere(cohere_api_key=cohere_api_key)

retriever_from_llm = MultiQueryRetriever.from_llm(
    retriever=vectorstore.as_retriever(search_kwargs={"k": 10, 
                                                    'filter': {'user_id_str': '42',
                                                               'internal_mydocai_id_str': {"$in":["4", "5"]}}}), llm=llm
)

from langchain.prompts import PromptTemplate

QUERY_PROMPT = PromptTemplate(
    input_variables=["question"],
    template="""You are an AI language model assistant. Your task is to output the original query and four 
    different versions of the given user query to retrieve relevant documents from a vector 
    database. By generating multiple perspectives on the user question, your goal is to help
    the user overcome some of the limitations of the distance-based similarity search, while staying in the scope of the original question. 
    Provide the original query and the alternative questions separated by newlines. Do not output anything else.
    Original question: {question}""",
)

logging.basicConfig()
logging.getLogger("langchain.retrievers.multi_query").setLevel(logging.INFO)



compressor = CohereRerank(model= "rerank-multilingual-v2.0", cohere_api_key=cohere_api_key, client=co, user_agent="mydocument", top_n=5
)
compression_retriever = ContextualCompressionRetriever(
    base_compressor=compressor, base_retriever=retriever_from_llm
)

compressed_docs = compression_retriever.get_relevant_documents(
    question


                                        
memory = ConversationBufferWindowMemory(k=2, memory_key="chat_history", input_key='input', output_key="output")


# retrieval qa chain
qa = RetrievalQA.from_chain_type(
    llm=llm,
    chain_type="stuff",
    retriever=compression_retriever,
)

tools = [
    Tool(
        name='Knowledge Base',
        func=qa.run,
        description=(
            'use this tool when answering general knowledge queries to get '
            'more information about the topic'
        )
    )
]

agent = initialize_agent(
    agent='chat-conversational-react-description',
    tools=tools,
    llm=llm,
    verbose=True,
    max_iterations=3,    
    early_stopping_method='generate',
    memory=memory
)

agent(question)

```

Error:
```
ValueError: variable chat_history should be a list of base messages, got 

### Suggestion:

_No response_