Module 9 Lesson 3: Built-in LangChain Tools
Instant Capabilities. Exploring the library of pre-made tools for web search, calculation, and database interaction.
Built-in Tools: No Coding Required
You don't always have to write your own tools. LangChain comes with a massive library of Community Tools for common tasks. Using these saves you hours of API integration work.
1. Tavily (Search for AI)
Tavily is a search engine designed specifically for Agents. It doesn't return ads; it returns clean text that is easy for LLMs to read.
from langchain_community.tools.tavily_search import TavilySearchResults
# 1. Setup (Requires TAVILY_API_KEY in .env)
search = TavilySearchResults(k=3)
# 2. Use it directly or in an agent
results = search.invoke({"query": "What is the capital of France?"})
2. PythonREPL (The Sandbox)
This tool allows the agent to write and execute its own Python code to solve math problems or create charts.
- DANGER: Never use this in production without a secure Docker sandbox! (Module 13 of Agentic Course).
3. Wikipedia API
A classic tool for historical or general knowledge.
from langchain_community.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())
4. Visualizing the Toolset
| Tool | Capability | Best Use Case |
|---|---|---|
| Tavily | Real-time Web | Current events, price checks. |
| PythonREPL | Logic / Calculation | Complex math, data analysis. |
| DuckDuckGo | Search | Private, anonymous web search. |
| YouTube | Transcript Retrieval | Summarizing videos. |
5. Engineering Tip: Tool Persistence
Some tools require long-running connections (like a SQL tool). Use the load_tools utility to manage their lifecycle efficiently.
from langchain.agents import load_tools
tools = load_tools(["wikipedia", "llm-math"], llm=model)
Key Takeaways
- LangChain Community provides hundreds of ready-to-use tools.
- Tavily is the current standard for agentic web search.
PythonREPLgives the agent "Infinite" logical capability via code.- Always check the Security of a tool before giving it to an autonomous agent.