AI / LangGraph LangChain Interview questions
How do tools work in LangChain agents?
A Tool in LangChain is a callable that an agent can invoke when it needs to interact with the outside world. Every tool has three required attributes: a name (how the LLM refers to it), a description (what it does and when to use it — the LLM reads this to decide), and an input schema (the parameters it expects).
When the agent decides to call a tool, AgentExecutor:
- Finds the tool by name in its tools list
- Parses the agent's action into the tool's input format
- Calls
tool.run(input)ortool.arun(input) - Returns the result as an "Observation" back to the agent
LangChain ships dozens of pre-built tools in langchain-community: web search (Tavily, SerpAPI), code execution (PythonREPL), database query (SQLDatabase), Wikipedia, file I/O, and more. You access them as:
from langchain_community.tools.tavily_search import TavilySearchResults from langchain.tools import WikipediaQueryRun search = TavilySearchResults(max_results=3) wiki = WikipediaQueryRun() tools = [search, wiki]
A critical practical point: the tool description matters more than the implementation. The LLM decides whether to call a tool based entirely on reading its description. A vague description leads to incorrect tool selection; a precise description improves agent accuracy.
More Related questions...