🎯 By the end of this module, you will:
Integrating External Tools into an Agent
An LLM without tools is frozen at its training cutoff. By wrapping APIs as @tool functions, you give your agent live eyes on the world — from web search to database queries.
# Step 1: Schema auto-generated from your docstring
from langchain_core.tools import tool
@tool
def search_web(query: str, max_results: int = 3) -> list[dict]:
"""Searches the live web for current news and facts.
Args:
query: The search query string to look up.
max_results: Maximum number of results to return (1-10).
Returns:
A list of dicts with 'title', 'url', and 'content' keys.
"""
# LLM sees the JSON schema, not this implementation
...🔧 Mental Model: LLM Alone vs. LLM + Tools
Like asking a very smart professor who's been in a coma since 2024 about today's cricket score. They know everything that happened before, but cannot access live information.
Like giving that same professor a smartphone with internet. Now they can look up live facts, current events, and real-time data — and still apply all their expertise to synthesize the answer.
🔬 External Tool Integration Studio
External Search Tool Integration StudioTavily Search API
Experience how external search tools provide live grounded web data beyond training cutoffs
from langchain_community.tools.tavily_search import TavilySearchResults tavily_tool = TavilySearchResults(max_results=3) model_with_tools = model.bind_tools([tavily_tool])
Search tools bridge the temporal gap between LLM static training weights and dynamic, live world state.
External Tool Integration Traps
Binding 15 tools to an agent causes the LLM to become indecisive — it picks the wrong tool or skips tool calls entirely. Always start with the minimum tool set, then add only what tests prove is needed.
If your @tool raises an unhandled exception, the raw Python traceback is injected as the observation. The LLM tries to reason about it and often hallucinate a fix. Always catch exceptions and return structured error dicts.
Key Takeaways
- 1.Docstrings are Tool Instructions: Write the @tool docstring as if instructing the LLM exactly when to call it, what to pass, and what it will receive back.
- 2.The Framework Handles Dispatch: You never manually call your tool function in agent code. The framework parses the LLM's tool call JSON and executes it automatically.
- 3.Account for Latency & Cost: Web searches cost money and time. Design your agent to prefer cached knowledge (RAG) over live search when recency isn't required.
Building Simple Multi-Step LLM Workflows
Not every task needs an autonomous agent. Learn when deterministic sequential chains beat loops — and build them with LCEL's elegant pipe composition.