Exploring LangChain's Quickstart (4) - Dynamically Select the Tools (Agent)
In this series, we explore the ‘Quickstart’ section of the LangChain documentation.
Previously, we developed chains that operated on predefined steps. In this article, we explore how the LLM chooses the right tools for processing based on user input, introducing the concept of an agent.
A Recap
In a previous post, we built a retriever from LangChain’s documentation.
Let’s revisit that setup:
import os
from langchain_openai import OpenAIEmbeddings
from langchain_community.document_loaders import WebBaseLoader
from langchain_community.vectorstores import FAISS
from langchain_text_splitters import RecursiveCharacterTextSplitter
# Set up the API key as environment variable
with open('.openai') as f:
os.environ['OPENAI_API_KEY'] = f.read().strip()
# Load web page content
loader = WebBaseLoader("https://python.langchain.com/docs/get_started/introduction")
docs = loader.load()
# Load embeddings
embeddings = OpenAIEmbeddings()
# Split documents
text_splitter = RecursiveCharacterTextSplitter()
documents = text_splitter.split_documents(docs)
# Vectorize documents and create a vector store
vector = FAISS.from_documents(documents, embeddings)
# Create a retriever
retriever = vector.as_retriever()
8. Dynamically Select the Tools (Agent)
In this article, we’re creating an agent that utilizes the retriever if the user’s question concerns LangChain. For other topics, it will conduct internet searches. The LLM will determine which process to employ based on the query.

