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 TypesSelf-ask with searchOn this pageSelf-ask with searchThis walkthrough showcases the self-ask with search chain.from langchain.llms import OpenAIfrom langchain.utilities import SerpAPIWrapperfrom langchain.agents import initialize_agent, Toolfrom langchain.agents import AgentTypellm = OpenAI(temperature=0)search = SerpAPIWrapper()tools = [    Tool(        name="Intermediate Answer",        func=search.run,        description="useful for when you need to ask with search",    )]Using LangChain Expression Language‚ÄãFirst we will show how to construct this agent from components using LangChain Expression Languagefrom langchain.agents.output_parsers import SelfAskOutputParserfrom langchain.agents.format_scratchpad import format_log_to_strfrom langchain import hubprompt = hub.pull("hwchase17/self-ask-with-search")llm_with_stop = llm.bind(stop=["\nIntermediate answer:"])agent = {    "input": lambda x: x["input"],    # Use some custom observation_prefix/llm_prefix for formatting    "agent_scratchpad": lambda x: format_log_to_str(        x['intermediate_steps'],         observation_prefix="\nIntermediate answer: ",        llm_prefix="",    ),} | prompt | llm_with_stop | SelfAskOutputParser()from langchain.agents import AgentExecutoragent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)agent_executor.invoke({"input": "What is the hometown of the reigning men's U.S. Open champion?"})            > Entering new AgentExecutor chain...
This walkthrough showcases the self-ask with search chain.
This walkthrough showcases the self-ask with search chain. ->: 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 TypesSelf-ask with searchOn this pageSelf-ask with searchThis walkthrough showcases the self-ask with search chain.from langchain.llms import OpenAIfrom langchain.utilities import SerpAPIWrapperfrom langchain.agents import initialize_agent, Toolfrom langchain.agents import AgentTypellm = OpenAI(temperature=0)search = SerpAPIWrapper()tools = [    Tool(        name="Intermediate Answer",        func=search.run,        description="useful for when you need to ask with search",    )]Using LangChain Expression Language‚ÄãFirst we will show how to construct this agent from components using LangChain Expression Languagefrom langchain.agents.output_parsers import SelfAskOutputParserfrom langchain.agents.format_scratchpad import format_log_to_strfrom langchain import hubprompt = hub.pull("hwchase17/self-ask-with-search")llm_with_stop = llm.bind(stop=["\nIntermediate answer:"])agent = {    "input": lambda x: x["input"],    # Use some custom observation_prefix/llm_prefix for formatting    "agent_scratchpad": lambda x: format_log_to_str(        x['intermediate_steps'],         observation_prefix="\nIntermediate answer: ",        llm_prefix="",    ),} | prompt | llm_with_stop | SelfAskOutputParser()from langchain.agents import AgentExecutoragent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)agent_executor.invoke({"input": "What is the hometown of the reigning men's U.S. Open champion?"})            > Entering new AgentExecutor chain...