Skip to main content
Tools extend what agents can do—letting them fetch real-time data, execute code, query external databases, and take actions in the world. Under the hood, tools are callable functions with well-defined inputs and outputs that get passed to a chat model. The model decides when to invoke a tool based on the conversation context, and what input arguments to provide.
For details on how models handle tool calls, see Tool calling.

Create tools

Basic tool definition

The simplest way to create a tool is by importing the tool function from the langchain package. You can use zod to define the tool’s input schema:
Server-side tool useSome chat models (e.g., OpenAI, Anthropic, and Gemini) feature built-in tools that are executed server-side, such as web search and code interpreters. Refer to the provider overview to learn how to access these tools with your specific chat model.

Accessing context

Why this matters: Tools are most powerful when they can access agent state, runtime context, and long-term memory. This enables tools to make context-aware decisions, personalize responses, and maintain information across conversations.The runtime context provides a structured way to supply runtime data, such as DB connections, user IDs, or config, into your tools. This avoids global state and keeps tools testable and reusable.

Context

Tools can access an agent’s runtime context through the config parameter:

Memory (Store)

Access persistent data across conversations using the store. The store is accessed via config.store and allows you to save and retrieve user-specific or application-specific data.

Stream writer

Stream custom updates from tools as they execute using config.streamWriter. This is useful for providing real-time feedback to users about what a tool is doing.

Connect these docs to Claude, VSCode, and more via MCP for real-time answers.