docs: enhance Runtime and ToolRuntime class descriptions for clarity (#6689)

This commit is contained in:
Mason Daugherty
2026-01-26 13:22:54 -08:00
committed by GitHub
parent 3ff6340379
commit 2dd39432a3
2 changed files with 26 additions and 4 deletions
+15
View File
@@ -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:
+11 -4
View File
@@ -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.