langchain.llms import OpenAIfrom langchain.utilities import SerpAPIWrapperfrom langchain.chains import LLMChainfrom typing import List, Unionfrom langchain.schema import AgentAction, AgentFinishimport reSet up tools‚ÄãWe will create one legitimate tool (search) and then 99 fake tools.# Define which tools the agent can use to answer user queriessearch = SerpAPIWrapper()search_tool = Tool(    name="Search",    func=search.run,    description="useful for when you need to answer questions about current events",)def fake_func(inp: str) -> str:    return "foo"fake_tools = [    Tool(        name=f"foo-{i}",        func=fake_func,        description=f"a silly function that you can use to get more information about the number {i}",    )    for i in range(99)]ALL_TOOLS = [search_tool] + fake_toolsTool Retriever‚ÄãWe will use a vector store to create embeddings for each tool description. Then, for an incoming query we can create embeddings for that query and do a similarity search for relevant tools.from langchain.vectorstores import FAISSfrom langchain.embeddings import OpenAIEmbeddingsfrom langchain.schema import Documentdocs = [    Document(page_content=t.description, metadata={"index": i})    for i, t in enumerate(ALL_TOOLS)]vector_store = FAISS.from_documents(docs, OpenAIEmbeddings())retriever = vector_store.as_retriever()def get_tools(query):    docs = retriever.get_relevant_documents(query)    return [ALL_TOOLS[d.metadata["index"]] for d in docs]We can now test this retriever to see if it seems to work.get_tools("whats the weather?")    [Tool(name='Search', description='useful for when you need to answer questions about current events', return_direct=False, verbose=False, callback_manager=<langchain.callbacks.shared.SharedCallbackManager object at 0x114b28a90>, func=<bound method SerpAPIWrapper.run of SerpAPIWrapper(search_engine=<class 'serpapi.google_search.GoogleSearch'>, params={'engine': 'google', 'google_domain': 'google.com', 'gl': 'us', 'hl': 'en'},
This notebook builds off of this notebook and assumes familiarity with how agents work.
This notebook builds off of this notebook and assumes familiarity with how agents work. ->: langchain.llms import OpenAIfrom langchain.utilities import SerpAPIWrapperfrom langchain.chains import LLMChainfrom typing import List, Unionfrom langchain.schema import AgentAction, AgentFinishimport reSet up tools‚ÄãWe will create one legitimate tool (search) and then 99 fake tools.# Define which tools the agent can use to answer user queriessearch = SerpAPIWrapper()search_tool = Tool(    name="Search",    func=search.run,    description="useful for when you need to answer questions about current events",)def fake_func(inp: str) -> str:    return "foo"fake_tools = [    Tool(        name=f"foo-{i}",        func=fake_func,        description=f"a silly function that you can use to get more information about the number {i}",    )    for i in range(99)]ALL_TOOLS = [search_tool] + fake_toolsTool Retriever‚ÄãWe will use a vector store to create embeddings for each tool description. Then, for an incoming query we can create embeddings for that query and do a similarity search for relevant tools.from langchain.vectorstores import FAISSfrom langchain.embeddings import OpenAIEmbeddingsfrom langchain.schema import Documentdocs = [    Document(page_content=t.description, metadata={"index": i})    for i, t in enumerate(ALL_TOOLS)]vector_store = FAISS.from_documents(docs, OpenAIEmbeddings())retriever = vector_store.as_retriever()def get_tools(query):    docs = retriever.get_relevant_documents(query)    return [ALL_TOOLS[d.metadata["index"]] for d in docs]We can now test this retriever to see if it seems to work.get_tools("whats the weather?")    [Tool(name='Search', description='useful for when you need to answer questions about current events', return_direct=False, verbose=False, callback_manager=<langchain.callbacks.shared.SharedCallbackManager object at 0x114b28a90>, func=<bound method SerpAPIWrapper.run of SerpAPIWrapper(search_engine=<class 'serpapi.google_search.GoogleSearch'>, params={'engine': 'google', 'google_domain': 'google.com', 'gl': 'us', 'hl': 'en'},