Closed gmurthy closed 1 year ago
You should create prompts that clearly distinguish between previous chat history and the new input like below (I didn't test).
...
To answer for the new input, use the following format:
New Input: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [Google Search, lookup_ingredients]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
AI: the final answer to the original input question in JSON format
DO NOT make up an answer. Only answer based on the information you have. Return response in JSON format with the fields: intent, entities(optional), message.
Previous chat history:
Human: Show me the ingredients for making greek salad
AI: XXX
Human: XXX
AI: XXX
Begin!:
New Input:
The two look too similar in your prompt and may lead to a misunderstanding regarding the importance of the new input.
Orignally, convesational agent differentiate them (as "Human:" and "New Input:") https://github.com/hwchase17/langchain/blob/master/langchain/agents/conversational/prompt.py
Thanks for the response @yakigac. Your theory was correct. Adding more clarity to the prompt to distinguish between new input and chat history fixed the problem. Thanks!
Closing this issue.
@gmurthy Can u share pls your final prompt for the memory conflicts
I'm hitting an issue where adding memory to an agent causes the LLM to misbehave, starting from the second interaction onwards. The first interaction works fine, and the same sequence of interactions without memory also works fine. Let me demonstrate with an example:
Agent Code:
Interaction 1:
Output (Correct):
Interaction 2:
Output (Incorrect):
For interaction 2, it does not appear that the tool (lookup_ingredients) actually got invoked and the results I get are usually truncated or incorrect. If I add a
memory.clear()
before the second interaction, it works perfect and if I remove the memory altogether, that works fine too.What am I missing - any thoughts?