Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsAgent TypesConversationalOpenAI functionsOpenAI Multi Functions AgentReActReAct document storeSelf-ask with searchStructured tool chatXML AgentHow-toToolsToolkitsCallbacksModulesSecurityGuidesMoreModulesAgentsAgent TypesReActOn this pageReActThis walkthrough showcases using an agent to implement the ReAct logic.from langchain.agents import load_toolsfrom langchain.agents import initialize_agentfrom langchain.agents import AgentTypefrom langchain.llms import OpenAIFirst, let's load the language model we're going to use to control the agent.llm = OpenAI(temperature=0)Next, let's load some tools to use. Note that the llm-math tool uses an LLM, so we need to pass that in.tools = load_tools(["serpapi", "llm-math"], llm=llm)Using LCEL‚ÄãWe will first show how to create the 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")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'])} | prompt | llm_with_stop | ReActSingleInputOutputParser()from langchain.agents import AgentExecutoragent_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?"})            > Entering new AgentExecutor chain...     I need to
This walkthrough showcases using an agent to implement the ReAct logic.
This walkthrough showcases using an agent to implement the ReAct logic. ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsAgent TypesConversationalOpenAI functionsOpenAI Multi Functions AgentReActReAct document storeSelf-ask with searchStructured tool chatXML AgentHow-toToolsToolkitsCallbacksModulesSecurityGuidesMoreModulesAgentsAgent TypesReActOn this pageReActThis walkthrough showcases using an agent to implement the ReAct logic.from langchain.agents import load_toolsfrom langchain.agents import initialize_agentfrom langchain.agents import AgentTypefrom langchain.llms import OpenAIFirst, let's load the language model we're going to use to control the agent.llm = OpenAI(temperature=0)Next, let's load some tools to use. Note that the llm-math tool uses an LLM, so we need to pass that in.tools = load_tools(["serpapi", "llm-math"], llm=llm)Using LCEL‚ÄãWe will first show how to create the 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")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'])} | prompt | llm_with_stop | ReActSingleInputOutputParser()from langchain.agents import AgentExecutoragent_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?"})            > Entering new AgentExecutor chain...     I need to