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.
Create tools
Basic tool definition
The simplest way to create a tool is by importing thetool function from the langchain package. You can use zod to define the tool’s input schema:
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 theconfig parameter:
Memory (Store)
Access persistent data across conversations using the store. The store is accessed viaconfig.store and allows you to save and retrieve user-specific or application-specific data.
Stream Writer
Stream custom updates from tools as they execute usingconfig.streamWriter. This is useful for providing real-time feedback to users about what a tool is doing.