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
)
]
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.
self_ask_with_search = initialize_agent(tools, llm, agent_path="lc@2826ef9e8acdf88465e1e5fc8a7bf59e0f9d0a85://agents/self-ask-with-search/agent.json", verbose=True)
No `_type` key found, defaulting to `prompt`.