.ipynb
.pdf
Loading from LangChainHub
 Contents 
Loading from LangChainHub
Pinning Dependencies
Loading from LangChainHub#
This notebook covers how to load agents from LangChainHub.
from langchain import OpenAI, SerpAPIWrapper
from langchain.agents import initialize_agent, Tool
llm = OpenAI(temperature=0)
search = SerpAPIWrapper()
tools = [
    Tool(
        name="Intermediate Answer",
        func=search.run,
        description="useful for when you need to ask with search"
    )
]
self_ask_with_search = initialize_agent(tools, llm, agent_path="lc://agents/self-ask-with-search/agent.json", verbose=True)
self_ask_with_search.run("What is the hometown of the reigning men's U.S. Open champion?")
No `_type` key found, defaulting to `prompt`.
> Entering new AgentExecutor chain...
 Yes.
Follow up: Who is the reigning men's U.S. Open champion?
Intermediate answer: 2016 · SUI · Stan Wawrinka ; 2017 · ESP · Rafael Nadal ; 2018 · SRB · Novak Djokovic ; 2019 · ESP · Rafael Nadal.
So the reigning men's U.S. Open champion is Rafael Nadal.
Follow up: What is Rafael Nadal's hometown?
Intermediate answer: In 2016, he once again showed his deep ties to Mallorca and opened the Rafa Nadal Academy in his hometown of Manacor.
So the final answer is: Manacor, Mallorca, Spain.
> Finished chain.
'Manacor, Mallorca, Spain.'
Pinning Dependencies#
Specific versions of LangChainHub agents can be pinned with the lc@<ref>:// syntax.