-
Notifications
You must be signed in to change notification settings - Fork 15.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting ConversationBufferMemory to work with create_pandas_dataframe_agent #3106
Comments
👇 SOLVED_DOWN 🎊 Kinda Backstory:While: trying to have more than 1 chat-history as a key (the goal was having a chat-history for each user) Issue:Just wanted to add that I'm going thru the excat smae issue. memory = ConversationBufferMemory(memory_key="chat-history", return_messages=True)
# create and return the chat agent
agent = initialize_agent(
tools=tools,
llm=model,
agent="chat-conversational-react-description",
verbose=True,
memory=memory
)
search_me = "how to cook a banana"
agent.run(search_me) Error: ValueError: A single string input was passed in, but this chain expects multiple inputs ({'chat_history', 'input'}). When a chain expects multiple inputs, please call it by passing in a dictionary, eg `chain({'foo': 1, 'bar': 2})` Edit: SOLUTION:Apperently I was to tired to notice, however all what we have to do is the following: out = agent({"input": search_me, "chat_history": []})
print(out)
Then later on you will just have to save the output and of course your input: memory.save_context({"input": search_me}, {"ouput": out})
memory.load_memory_variables({"username_id"}) it does show indeed only the desired key searches (in this case it's dynamically associated to each user)
|
@eike-heimpel is it working for you? I am also having a similar issue where I am using multiple tools. One is RetrievalQA and the next is the Pandas toolkit. But Pandas toolkit is not able to access memory. Any solution for this? |
Just to add to the features request to have the Panda agent use memory |
@tevslin This worked for me
|
Thank you. That works very well. I did have to change the defaults of PREFIX and SUFFIX since they were undefined. for production I'd suggest that memory be defined by the caller and passed in as an optional parameter with a default of None. Also the defaults for SUFFIX and PREFIX can be changed in prompts.py in the \pandas folder or overridden by the caller, Are you going to create a pull-request for this? |
Sure I will create one!!. May I know what you mean by defining a caller? |
I just meant that the code which invokes create_pandas_dataframe_agent should allocate the memory buffer if it wants one and pass it as an optional parameter to create_pandas_dataframe_agent. |
If the memory parameter is optional, then in the prompt the input variable {chat_history} would also be an optional parameter. |
You are absolutely right. Thanks.
From: Rishav Dash ***@***.***>
Sent: Monday, May 1, 2023 11:11 AM
To: hwchase17/langchain ***@***.***>
Cc: Tom Evslin ***@***.***>; Mention ***@***.***>
Subject: Re: [hwchase17/langchain] Getting ConversationBufferMemory to work with create_pandas_dataframe_agent (Issue #3106)
I just meant that the code which invokes create_pandas_dataframe_agent should allocate the memory buffer if it wants one and pass it as an optional parameter to create_pandas_dataframe_agent.
If the memory parameter is optional, then in the prompt the input variable {chat_history} would also be an optional parameter.
—
Reply to this email directly, view it on GitHub <#3106 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AGLSBBSSRCX5LBDIX7N3MKLXD7HBZANCNFSM6AAAAAAXDCEVV4> .
You are receiving this because you were mentioned. <https://github.com/notifications/beacon/AGLSBBREKIUAJRDC7ZLV3S3XD7HBZA5CNFSM6AAAAAAXDCEVV6WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTS3F4XJY.gif> Message ID: ***@***.*** ***@***.***> >
|
@tevslin @Rishav-hub thanks for taking a look here, this sounds good! Is there a PR already that I could take a look at? |
Till now I have not made a PR regarding this. |
Will we create a PR for this? |
Will the PR also work with OpenAI functions? |
I am facing an error saying "chat_history" not defined. What mistake might I have committed? |
Can you send the code which is throwing this particular error? |
I made it all work! You need to change the Example code as a stackoverflow answer can be found here: |
hi Rishav, thanks for the great work! can I just clarify that to implement memory for create_pandas_dataframe_agent, all you did was to change the function defined? can I also ask if you're comfortable sharing your script that runs the agent? I'm having some issues implementing memory for the pandas df agent. |
I'm getting:
|
Doing this worked for me:
and while calling the agent:
Quoting from this: #2068 (comment) |
from langchain.memory.buffer import ConversationBufferMemory app = Flask(name) #Initialize Openai Load environment variables from .env fileload_dotenv('.env') Initialize pinecone and set indexpinecone.init( Initialize embeddings and AIprojectwe_embeddings = OpenAIEmbeddings() Prompt Templatetemplate = """ CHAT HISTORY: ANSWER: Llmsllm = ChatOpenAI(temperature=0) p_chain = ConversationalRetrievalChain( #For MUSE Initialize embeddings and AImuse_embeddings = OpenAIEmbeddings() Prompt Templatetemplate = """ QUESTION: ANSWER: muse_memory = ConversationBufferMemory(memory_key="chat_history", input_key="question",return_messages=True) muse_retriever = Pinecone.from_existing_index(index_name=index_name, embedding=muse_embeddings, namespace="cust-muse-mojomosaic-pinecone") Llmsllm = ChatOpenAI(temperature=0) m_chain = ConversationalRetrievalChain( ) #initilaize tool Set up Agentmodel_name="gpt-4" chatagent = initialize_agent(tools, agent_llm, agent=AgentType.OPENAI_FUNCTIONS, memory = agent_memory,verbose=True) @app.route('/') @app.route('/send_message', methods=['POST']) if name == 'main': Invoking: 127.0.0.1 - - [01/Nov/2023 00:30:17] "POST /send_message HTTP/1.1" 500 - |
How to use the function to start asking questions? @Rishav-hub |
@tevslin Can you please share your SUFFIX and PREFIX that you have used for working with a CSV that uses memory and do not hallucinate much on the response. Thanks in advance |
I haven’t been using Langchain lately as much as I appreciate it (busy with Autogen) and have never used it with CSVs,
From: 3dhunter97 ***@***.***>
Sent: Friday, January 12, 2024 1:49 AM
To: langchain-ai/langchain ***@***.***>
Cc: Tom Evslin ***@***.***>; Mention ***@***.***>
Subject: Re: [langchain-ai/langchain] Getting ConversationBufferMemory to work with create_pandas_dataframe_agent (Issue #3106)
Thank you. That works very well. I did have to change the defaults of PREFIX and SUFFIX since they were undefined.
for production I'd suggest that memory be defined by the caller and passed in as an optional parameter with a default of None. Also the defaults for SUFFIX and PREFIX can be changed in prompts.py in the \pandas folder or overridden by the caller, Are you going to create a pull-request for this?
@tevslin <https://github.com/tevslin> Can you please share your SUFFIX and PREFIX that you have used for working with a CSV that uses memory and do not hallucinate much on the response. Thanks in advance
—
Reply to this email directly, view it on GitHub <#3106 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AGLSBBQCHBVLBFTVH5NNZ6DYODMG5AVCNFSM6AAAAAAXDCEVV6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBYGUZDENRSGM> .
You are receiving this because you were mentioned. <https://github.com/notifications/beacon/AGLSBBXSEETFCXGZESQQXI3YODMG5A5CNFSM6AAAAAAXDCEVV6WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTQSCIX6.gif> Message ID: ***@***.*** ***@***.***> >
|
Error |
|
I am having some issues with the agent and agent executor. I have a pipeline as such.
And I am trying to use the agent.invoke.
I am getting an error. Short summary:
Trace:
Help please? |
I have been trying to add memory to my
create_pandas_dataframe_agent
agent and ran into some issues.I created the agent like this
and ran into
I was able to fix it by modifying the
create_pandas_dataframe_agent
to accept the memory object and then passing that along to theAgentCreator
like so:Not sure what I did wrong or if I am misunderstanding something in general, maybe this is just the current behavior and adding memory would be a feature request?
The text was updated successfully, but these errors were encountered: