From 2dd39432a3923f4f04161a64373d3047089ebd29 Mon Sep 17 00:00:00 2001 From: Mason Daugherty Date: Mon, 26 Jan 2026 13:22:54 -0800 Subject: [PATCH] docs: enhance `Runtime` and `ToolRuntime` class descriptions for clarity (#6689) --- libs/langgraph/langgraph/runtime.py | 15 +++++++++++++++ libs/prebuilt/langgraph/prebuilt/tool_node.py | 15 +++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/libs/langgraph/langgraph/runtime.py b/libs/langgraph/langgraph/runtime.py index 0f23ec69a..872b9987c 100644 --- a/libs/langgraph/langgraph/runtime.py +++ b/libs/langgraph/langgraph/runtime.py @@ -28,6 +28,21 @@ class _RuntimeOverrides(TypedDict, Generic[ContextT], total=False): class Runtime(Generic[ContextT]): """Convenience class that bundles run-scoped context and other runtime utilities. + This class is injected into graph nodes and middleware. It provides access to + `context`, `store`, `stream_writer`, and `previous`. + + !!! note "Accessing `config`" + + `Runtime` does not include `config`. To access `RunnableConfig`, you can inject + it directly by adding a `config: RunnableConfig` parameter to your node function + (recommended), or use `get_config()` from `langgraph.config`. + + !!! note + `ToolRuntime` (from `langgraph.prebuilt`) is a subclass that provides similar + functionality but is designed specifically for tools. It shares `context`, `store`, + and `stream_writer` with `Runtime`, and adds tool-specific attributes like `config`, + `state`, and `tool_call_id`. + !!! version-added "Added in version v0.6.0" Example: diff --git a/libs/prebuilt/langgraph/prebuilt/tool_node.py b/libs/prebuilt/langgraph/prebuilt/tool_node.py index 0731616aa..31b3f6b98 100644 --- a/libs/prebuilt/langgraph/prebuilt/tool_node.py +++ b/libs/prebuilt/langgraph/prebuilt/tool_node.py @@ -1531,16 +1531,23 @@ def tools_condition( class ToolRuntime(_DirectlyInjectedToolArg, Generic[ContextT, StateT]): """Runtime context automatically injected into tools. - When a tool function has a parameter named `tool_runtime` with type hint + !!! note + + This is distinct from `Runtime` (from `langgraph.runtime`), which is injected + into graph nodes and middleware. `ToolRuntime` includes additional tool-specific + attributes like `config`, `state`, and `tool_call_id` that `Runtime` does not + have. + + When a tool function has a parameter named `runtime` with type hint `ToolRuntime`, the tool execution system will automatically inject an instance containing: - `state`: The current graph state - `tool_call_id`: The ID of the current tool call - `config`: `RunnableConfig` for the current execution - - `context`: Runtime context (from langgraph `Runtime`) - - `store`: `BaseStore` instance for persistent storage (from langgraph `Runtime`) - - `stream_writer`: `StreamWriter` for streaming output (from langgraph `Runtime`) + - `context`: Runtime context (shared with `Runtime`) + - `store`: `BaseStore` instance for persistent storage (shared with `Runtime`) + - `stream_writer`: `StreamWriter` for streaming output (shared with `Runtime`) No `Annotated` wrapper is needed - just use `runtime: ToolRuntime` as a parameter.