"Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?",     'output': "Leo DiCaprio's girlfriend is Vittoria Ceretti and her current age raised to the 0.43 power is 3.991298452658078."}Using chat models‚ÄãYou can also create ReAct agents that use chat models instead of LLMs as the agent driver.The main difference here is a different prompt. We will use JSON to encode the agent's actions (chat models are a bit tougher to steet, so using JSON helps to enforce the output format).from langchain.chat_models import ChatOpenAIchat_model = ChatOpenAI(temperature=0)prompt = hub.pull("hwchase17/react-json")prompt = prompt.partial(    tools=render_text_description(tools),    tool_names=", ".join([t.name for t in tools]),)chat_model_with_stop = chat_model.bind(stop=["\nObservation"])from langchain.agents.output_parsers import ReActJsonSingleInputOutputParseragent = {    "input": lambda x: x["input"],    "agent_scratchpad": lambda x: format_log_to_str(x['intermediate_steps'])} | prompt | chat_model_with_stop | ReActJsonSingleInputOutputParser()agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)agent_executor.invoke({"input": "Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?"})We can also use an off-the-shelf agent classagent = initialize_agent(tools, chat_model, agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=True)agent.run("Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?")PreviousOpenAI Multi Functions AgentNextReAct document storeUsing LCELUsing ZeroShotReactAgentUsing chat modelsCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.
This walkthrough showcases using an agent to implement the ReAct logic.
This walkthrough showcases using an agent to implement the ReAct logic. ->: "Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?",     'output': "Leo DiCaprio's girlfriend is Vittoria Ceretti and her current age raised to the 0.43 power is 3.991298452658078."}Using chat models‚ÄãYou can also create ReAct agents that use chat models instead of LLMs as the agent driver.The main difference here is a different prompt. We will use JSON to encode the agent's actions (chat models are a bit tougher to steet, so using JSON helps to enforce the output format).from langchain.chat_models import ChatOpenAIchat_model = ChatOpenAI(temperature=0)prompt = hub.pull("hwchase17/react-json")prompt = prompt.partial(    tools=render_text_description(tools),    tool_names=", ".join([t.name for t in tools]),)chat_model_with_stop = chat_model.bind(stop=["\nObservation"])from langchain.agents.output_parsers import ReActJsonSingleInputOutputParseragent = {    "input": lambda x: x["input"],    "agent_scratchpad": lambda x: format_log_to_str(x['intermediate_steps'])} | prompt | chat_model_with_stop | ReActJsonSingleInputOutputParser()agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)agent_executor.invoke({"input": "Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?"})We can also use an off-the-shelf agent classagent = initialize_agent(tools, chat_model, agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=True)agent.run("Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?")PreviousOpenAI Multi Functions AgentNextReAct document storeUsing LCELUsing ZeroShotReactAgentUsing chat modelsCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.