Skip to main content
Many AI applications interact with users via natural language. However, some use cases require models to interface directly with external systems—such as APIs, databases, or file systems—using structured input. Tools are components that agents call to perform actions. They extend model capabilities by letting them interact with the world through well-defined inputs and outputs. Tools encapsulate a callable function and its input schema. These can be passed to compatible chat models, allowing the model to decide whether to invoke a tool and with what arguments. In these scenarios, tool calling enables models to generate requests that conform to a specified 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.

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:
Type hints are required as they define the tool’s input schema. The docstring should be informative and concise to help the model understand the tool’s purpose.

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.
Tools can access runtime information through the 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 - RunnableConfig for 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.
Accessing state: Tools can access the current graph state using ToolRuntime:
The runtime parameter is hidden from the model. For the example above, the model only sees pref_name in the tool schema - runtime is not included in the request.
Updating state: Use 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 through runtime.context. Tools can access runtime context through ToolRuntime:

Memory (Store)

Access persistent data across conversations using the store. The store is accessed via runtime.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 using runtime.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.

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