LangChain Agent Tools in 2026

📘 Tutorials 2026-08-01 · Updated 2026-08-24 3 min read

LangChain agent tools explained one by one: search, Wikipedia, arXiv, Python execution, SQL toolkit, custom tools and MCP integration, with code examples.

💡 What You Will Learn

LangChain agent tools explained one by one: search, Wikipedia, arXiv, Python execution, SQL toolkit, custom tools and MCP integration, with code examples.

📜 Table of Contents

LangChain Agent Tools: Built-in Tools and How to Use Them

LLMs can think but not act: they do not know today's news, cannot run code or query your database. LangChain (143k+ stars on GitHub) solves this by giving models tools. This article explains each built-in tool with ready-to-copy code.

How Tools Work in an Agent

The agent loop: model receives a question → decides it needs information → the framework calls the right tool → results are fed back into context → model continues until a final answer. The tool's name and description decide whether the model picks it, so descriptions matter more than implementations.

Built-in Tools

TavilySearchResults — web search requiring a Tavily API key; returns results with source links. Best for real-time info (news, prices, docs). Free tier has monthly quota; check the official site. WikipediaQueryRun — free, no key. Good for factual questions; content can lag behind breaking news. ArxivQueryRun — free. Searches arXiv papers by keyword; useful for literature review. PythonREPLTool — lets the model write and execute Python. Security warning: the model runs code on your machine; only use in trusted environments. SQLDatabaseToolkit — converts natural language into SQL. Includes sub-tools for listing schemas, executing queries and checking errors. Great for "chat with your database". Others: DuckDuckGoSearchRun (free, no key), Requests tools (HTTP), ShellTool (shell commands, risky), SerpAPI/GoogleSearch (need keys).

Custom Tools with @tool

from langchain_core.tools import tool

@tool
def get_stock_price(symbol: str) -> str:
    """Get the latest price for a stock. symbol is a ticker like AAPL."""
    return f"{symbol}: $XXX"

The docstring must say what the tool does, what parameters mean, and an example. Type annotations are converted into the JSON schema the model sees.

MCP Integration (2026 trend)

from langchain_mcp_adapters.tools import load_mcp_tools
tools = await load_mcp_tools(session)

Any MCP server can be loaded as tools directly, no adapter code needed. Thousands of ready-made MCP servers exist on GitHub.

Best Practices

  1. Be specific in tool descriptions
  2. Add handle_tool_error=True so a tool crash does not kill the agent
  3. Use llm.bind_tools(tools) for native tool-calling instead of parsing JSON
  4. Keep tool count small (5-8 works best)
  5. Gate dangerous tools (code exec, shell, DB writes) behind human approval

FAQ

Q: How is tool calling different from hallucination? A: With tools bound, the model emits a structured call request; the framework executes it and returns real results into context. Q: Are free search tools enough? A: DuckDuckGo is free and keyless, fine for low volume; for stable results consider paid search APIs (see official pricing). Q: Do custom tools require retraining? A: No. Tools are injected at runtime; changing a description takes effect immediately.

Note: LangChain APIs evolve quickly; check the official docs for the latest version.

❓ FAQ

Do I need a Tavily API key?

TavilySearchResults requires a free API key; DuckDuckGoSearchRun does not.

Can tools call other tools?

Yes, through agent routing or sub-agents in LangGraph.

Related Articles
2026-07-16
AI Agent vs Software SaaS 2026
2026-08-11
MLOps Tools 2026: The 12 Open Source Projects That Cover the Whole Pipeline
2026-07-10
I used AI as a Rust mentor - it taught better than any textbook
2026-07-23
Open Source RAG Framework Comparison 2026: LangChain vs LlamaIndex vs Haystack
2026-07-17
AI Agent Input Sanitization 2026
2026-08-05
Local LLM Setup for Coding in 2026: Ollama (178k Stars) + Continue + Cline - Private AI Pair Programmer

Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.

💬 Comments (0)

No comments yet. Be the first!

Login to comment