from langchain.memory import ConversationBufferMemory # Skipped here - Define your own prefix, suffix, and description with "chat_history" for the prompt # Keep the original list of tools # Create the prompt using ZeroShotAgent with additonal "chat_history" as input variables agent_prompt = ZeroShotAgent.create_prompt( tools, prefix=prefix, suffix=suffix, input_variables=["input", "chat_history", "agent_scratchpad"], ) # Create an instance of ZeroShotAgent with the LLMChain and the allowed tool names zero_shot_agent = ZeroShotAgent( llm_chain=LLMChain(llm=llm, prompt=agent_prompt), allowed_tools=[tool.name for tool in tools] ) # Initiate memory which allows for storing and extracting messages memory = ConversationBufferMemory(memory_key="chat_history") # Create an AgentExecutor with memory parameter agent_chain = AgentExecutor.from_agent_and_tools( agent=zero_shot_agent, tools=tools, verbose=True, handle_parsing_errors=True, memory=memory ) # Define initial question as user input user_inquiry = "How do customers adapt their shopping habits during different seasons?" # Run the agent to generate a response agent_executor.run(user_inquiry) # Define follow-up question as user input user_inquiry = "Can you elaborate more?" # Run the agent to generate another response agent_executor.run(user_inquiry)