Tools and Agents in LangChain.js
A LangChain.js tool wraps a TypeScript function with a name, description, and typed schema so a model can request it, and an agent executor repeatedly calls the model, executes any requested tools, and feeds results back, until the model gives a final answer.
Defining a tool
The schema uses Zod, a TypeScript-first validation library, to describe exactly what arguments the tool accepts, LangChain.js converts that schema into the JSON Schema the model actually sees, and validates the model's arguments against it before your function ever runs, malformed input is rejected before it reaches your code, not after.
Binding tools to a model
This needs a real API key, so it's read-only here. .bindTools() returns a new model that can respond with a tool_calls array when it decides a tool is relevant, the model never runs getWordLength itself, it only requests that your code do so.
The agent executor
Read-only, needs a real model. AgentExecutor is the loop: call the model, check for tool_calls, run any requested tools, append their results, and repeat until the model returns a final plain-text answer instead of another tool request.
NOTE
A Zod schema does double duty here: it's what generates the tool's JSON Schema description for the model, and it's what validates the model's arguments before your function runs, one source of truth instead of two things to keep in sync by hand.