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 with the@tool decorator. By default, the function’s docstring becomes the tool’s description that helps the model understand when to use it:
Customize tool properties
Custom tool name
By default, the tool name comes from the function name. Override it when you need something more descriptive:Custom tool description
Override the auto-generated tool description for clearer model guidance:Advanced schema definition
Define complex inputs with Pydantic models or JSON schemas:Reserved argument names
The following parameter names are reserved and cannot be used as tool arguments. Using these names will cause runtime errors.
To access runtime information, use the
ToolRuntime parameter instead of naming your own arguments config or runtime.
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.Runtime context provides a way to inject dependencies (like database connections, user IDs, or configuration) into your tools at runtime, making them more testable and reusable.
ToolRuntime parameter, which provides:
- State - Mutable data that flows through execution (e.g., messages, counters, custom fields)
- Context - Immutable configuration like user IDs, session details, or application-specific configuration
- Store - Persistent long-term memory across conversations
- Stream Writer - Stream custom updates as tools execute
- Config -
RunnableConfigfor the execution - Tool Call ID - ID of the current tool call
ToolRuntime
Use ToolRuntime to access all runtime information in a single parameter. Simply add runtime: ToolRuntime to your tool signature, and it will be automatically injected without being exposed to the LLM.
ToolRuntime: A unified parameter that provides tools access to state, context, store, streaming, config, and tool call ID. This replaces the older pattern of using separate InjectedState, InjectedStore, get_runtime, and InjectedToolCallId annotations.The runtime automatically provides these capabilities to your tool functions without you having to pass them explicitly or use global state.ToolRuntime:
Command to update the agent’s state or control the graph’s execution flow:
Context
Access immutable configuration and contextual data like user IDs, session details, or application-specific configuration throughruntime.context.
Tools can access runtime context through ToolRuntime:
Memory (Store)
Access persistent data across conversations using the store. The store is accessed viaruntime.store and allows you to save and retrieve user-specific or application-specific data.
Tools can access and update the store through ToolRuntime:
Stream Writer
Stream custom updates from tools as they execute usingruntime.stream_writer. This is useful for providing real-time feedback to users about what a tool is doing.
If you use
runtime.stream_writer inside your tool, the tool must be invoked within a LangGraph execution context. See Streaming for more details.