Using LangChain tools with an agent, in practice
The fastest way to understand LangChain tools is to wire one up. Define a plain Python function, decorate it with @tool, and give it a docstring that says exactly what it does and when to use it — that docstring is the interface, because it is what the model reads when deciding whether to call the tool. Pass a list of tools to your agent (create_react_agent in LangGraph, or an AgentExecutor in classic LangChain), and the model chooses among them at each step: it emits a tool call with arguments, LangChain executes your function, and the result is fed back into the loop as context for the next decision. Three habits prevent most tool-use failures in production: keep each tool narrow enough that its name and description are unambiguous, validate arguments with a schema so malformed calls fail loudly rather than silently, and return errors as readable messages the model can react to — an agent that can see why a call failed can usually recover; one that gets a stack trace cannot.
How LangChain defines tools
A LangChain tool has three required elements: a name that identifies it to the model, a description that explains what it does and when to use it (written for the model to read, not the developer), and an input schema that defines what arguments it accepts. The model uses the name and description to decide whether to call the tool and the schema to format the call correctly. The tool's implementation is a Python function that receives the parsed arguments and returns a result — which can be a string, a structured object, or an error message. LangChain provides both a decorator-based API for converting existing Python functions to tools and a class-based API for tools that require more configuration.
Pre-built tools and toolkits
LangChain includes a library of pre-built tool integrations for common use cases: web search via various search APIs, website content retrieval, SQL database querying, Python code execution, file system access, Wikipedia lookup, and many others. Toolkits group related tools together — a SQL toolkit includes tools for introspecting the database schema and executing queries; a Python toolkit includes tools for writing and executing code in a sandboxed environment. These pre-built tools accelerate development for common integrations but often need customization for production use — the default implementations may not match the security requirements, error handling, or data format of the specific application.
Tool errors and fallback handling
Tools that fail — due to API errors, invalid inputs, or execution exceptions — return error messages to the model rather than crashing the agent. The model can interpret these errors and decide how to proceed: retrying with different arguments, using an alternative tool, or informing the user that the operation failed. The quality of error messages affects the model's ability to recover: an error message that explains what went wrong and what valid inputs look like enables smarter recovery than a generic exception traceback. Designing tool error handling with the model's interpretation in mind — writing error messages that are informative to a language model — is a practice that significantly affects agent reliability in the face of inevitable tool failures.