We want it to be much more conversational.from langchain.agents import Toolfrom langchain.agents import AgentTypefrom langchain.memory import ConversationBufferMemoryfrom langchain.llms import OpenAIfrom langchain.utilities import SerpAPIWrapperfrom langchain.agents import initialize_agentsearch = SerpAPIWrapper()tools = [    Tool(        name="Current Search",        func=search.run,        description="useful for when you need to answer questions about current events or the current state of the world"    ),]llm=OpenAI(temperature=0)Using LCEL‚ÄãWe will first show how to create this agent using LCELfrom langchain.tools.render import render_text_descriptionfrom langchain.agents.output_parsers import ReActSingleInputOutputParserfrom langchain.agents.format_scratchpad import format_log_to_strfrom langchain import hubprompt = hub.pull("hwchase17/react-chat")prompt = prompt.partial(    tools=render_text_description(tools),    tool_names=", ".join([t.name for t in tools]),)llm_with_stop = llm.bind(stop=["\nObservation"])agent = {    "input": lambda x: x["input"],    "agent_scratchpad": lambda x: format_log_to_str(x['intermediate_steps']),    "chat_history": lambda x: x["chat_history"]} | prompt | llm_with_stop | ReActSingleInputOutputParser()from langchain.agents import AgentExecutormemory = ConversationBufferMemory(memory_key="chat_history")agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True, memory=memory)agent_executor.invoke({"input": "hi, i am bob"})['output']            > Entering new AgentExecutor chain...        Thought: Do I need to use a tool? No    Final Answer: Hi Bob, nice to meet you! How can I help you today?        > Finished chain.    'Hi Bob, nice to meet you! How can I help you today?'agent_executor.invoke({"input": "whats my name?"})['output']            > Entering new AgentExecutor chain...        Thought: Do I need to use a tool? No    Final Answer: Your name is Bob.        > Finished chain.    'Your name is
This walkthrough demonstrates how to use an agent optimized for conversation. Other agents are often optimized for using tools to figure out the best response, which is not ideal in a conversational setting where you may want the agent to be able to chat with the user as well.
This walkthrough demonstrates how to use an agent optimized for conversation. Other agents are often optimized for using tools to figure out the best response, which is not ideal in a conversational setting where you may want the agent to be able to chat with the user as well. ->: We want it to be much more conversational.from langchain.agents import Toolfrom langchain.agents import AgentTypefrom langchain.memory import ConversationBufferMemoryfrom langchain.llms import OpenAIfrom langchain.utilities import SerpAPIWrapperfrom langchain.agents import initialize_agentsearch = SerpAPIWrapper()tools = [    Tool(        name="Current Search",        func=search.run,        description="useful for when you need to answer questions about current events or the current state of the world"    ),]llm=OpenAI(temperature=0)Using LCEL‚ÄãWe will first show how to create this agent using LCELfrom langchain.tools.render import render_text_descriptionfrom langchain.agents.output_parsers import ReActSingleInputOutputParserfrom langchain.agents.format_scratchpad import format_log_to_strfrom langchain import hubprompt = hub.pull("hwchase17/react-chat")prompt = prompt.partial(    tools=render_text_description(tools),    tool_names=", ".join([t.name for t in tools]),)llm_with_stop = llm.bind(stop=["\nObservation"])agent = {    "input": lambda x: x["input"],    "agent_scratchpad": lambda x: format_log_to_str(x['intermediate_steps']),    "chat_history": lambda x: x["chat_history"]} | prompt | llm_with_stop | ReActSingleInputOutputParser()from langchain.agents import AgentExecutormemory = ConversationBufferMemory(memory_key="chat_history")agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True, memory=memory)agent_executor.invoke({"input": "hi, i am bob"})['output']            > Entering new AgentExecutor chain...        Thought: Do I need to use a tool? No    Final Answer: Hi Bob, nice to meet you! How can I help you today?        > Finished chain.    'Hi Bob, nice to meet you! How can I help you today?'agent_executor.invoke({"input": "whats my name?"})['output']            > Entering new AgentExecutor chain...        Thought: Do I need to use a tool? No    Final Answer: Your name is Bob.        > Finished chain.    'Your name is