mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-11 12:17:53 +02:00
docs: enhance Runtime and ToolRuntime class descriptions for clarity (#6689)
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user