From 0232201b7b9f928b4f99a3780e1703e07670e6ac Mon Sep 17 00:00:00 2001 From: Sydney Runkle Date: Tue, 22 Jul 2025 13:28:27 -0400 Subject: [PATCH 1/8] improving docs for context --- libs/langgraph/langgraph/pregel/main.py | 8 ++++++++ libs/langgraph/langgraph/runtime.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/langgraph/langgraph/pregel/main.py b/libs/langgraph/langgraph/pregel/main.py index 1aec1da33..a402d7cf4 100644 --- a/libs/langgraph/langgraph/pregel/main.py +++ b/libs/langgraph/langgraph/pregel/main.py @@ -2438,6 +2438,8 @@ class Pregel( Args: input: The input to the graph. config: The configuration to use for the run. + context: The static context to use for the run. + !!! version-added "Added in version 0.6.0." stream_mode: The mode to stream output, defaults to `self.stream_mode`. Options are: @@ -2694,6 +2696,8 @@ class Pregel( Args: input: The input to the graph. config: The configuration to use for the run. + context: The static context to use for the run. + !!! version-added "Added in version 0.6.0." stream_mode: The mode to stream output, defaults to `self.stream_mode`. Options are: @@ -2981,6 +2985,8 @@ class Pregel( Args: input: The input data for the graph. It can be a dictionary or any other type. config: Optional. The configuration for the graph run. + context: The static context to use for the run. + !!! version-added "Added in version 0.6.0." stream_mode: Optional[str]. The stream mode for the graph run. Default is "values". print_mode: Accepts the same values as `stream_mode`, but only prints the output to the console, for debugging purposes. Does not affect the output of the graph in any way. output_keys: Optional. The output keys to retrieve from the graph run. @@ -3058,6 +3064,8 @@ class Pregel( Args: input: The input data for the computation. It can be a dictionary or any other type. config: Optional. The configuration for the computation. + context: The static context to use for the run. + !!! version-added "Added in version 0.6.0." stream_mode: Optional. The stream mode for the computation. Default is "values". print_mode: Accepts the same values as `stream_mode`, but only prints the output to the console, for debugging purposes. Does not affect the output of the graph in any way. output_keys: Optional. The output keys to include in the result. Default is None. diff --git a/libs/langgraph/langgraph/runtime.py b/libs/langgraph/langgraph/runtime.py index c819f1d4e..b5d7cdfdd 100644 --- a/libs/langgraph/langgraph/runtime.py +++ b/libs/langgraph/langgraph/runtime.py @@ -26,7 +26,7 @@ class _RuntimeOverrides(TypedDict, Generic[ContextT], total=False): class Runtime(Generic[ContextT]): """Convenience class that bundles run-scoped context and graph configuration. - !!! version-added "Added in version 1.0.0." + !!! version-added "Added in version 0.6.0." """ context: ContextT = field(default=None) # type: ignore[assignment] From 439038fc3ad5f520d9352d660c323f9e9529c9c5 Mon Sep 17 00:00:00 2001 From: Sydney Runkle Date: Thu, 24 Jul 2025 16:23:42 -0400 Subject: [PATCH 2/8] deprecation for config_schema in docs --- libs/langgraph/langgraph/func/__init__.py | 4 ++++ libs/langgraph/langgraph/graph/state.py | 4 ++++ libs/langgraph/langgraph/pregel/main.py | 1 + libs/langgraph/langgraph/runtime.py | 4 +++- libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py | 4 ++++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/langgraph/langgraph/func/__init__.py b/libs/langgraph/langgraph/func/__init__.py index 24ec545f7..ec453fec2 100644 --- a/libs/langgraph/langgraph/func/__init__.py +++ b/libs/langgraph/langgraph/func/__init__.py @@ -261,6 +261,10 @@ class entrypoint(Generic[ContextT]): passed to the workflow. cache_policy: A cache policy to use for caching the results of the workflow. retry_policy: A retry policy (or list of policies) to use for the workflow in case of a failure. + config_schema: Specifies the schema for the `configurable` key in the `RunnableConfig` object. + !!! warning "Deprecated" + This parameter is deprecated and support will be removed in v2.0.0. + Please use `context_schema` instead. Example: Using entrypoint and tasks ```python diff --git a/libs/langgraph/langgraph/graph/state.py b/libs/langgraph/langgraph/graph/state.py index 9e6d8552e..0bee5c0dc 100644 --- a/libs/langgraph/langgraph/graph/state.py +++ b/libs/langgraph/langgraph/graph/state.py @@ -128,6 +128,10 @@ class StateGraph(Generic[StateT, ContextT, InputT, OutputT]): Use this to expose immutable context data to your nodes, like user_id, db_conn, etc. input_schema: The schema class that defines the input to the graph. output_schema: The schema class that defines the output from the graph. + config_schema: Specifies the schema for the `configurable` key in the `RunnableConfig` object. + !!! warning "Deprecated" + This parameter is deprecated and support will be removed in v2.0.0. + Please use `context_schema` instead. Example: ```python diff --git a/libs/langgraph/langgraph/pregel/main.py b/libs/langgraph/langgraph/pregel/main.py index 1aec1da33..388fbf9ce 100644 --- a/libs/langgraph/langgraph/pregel/main.py +++ b/libs/langgraph/langgraph/pregel/main.py @@ -602,6 +602,7 @@ class Pregel( Defaults to None.""" context_schema: type[ContextT] | None = None + """Specifies the schema for the context object that will be passed to the workflow.""" config: RunnableConfig | None = None diff --git a/libs/langgraph/langgraph/runtime.py b/libs/langgraph/langgraph/runtime.py index c819f1d4e..c498584c2 100644 --- a/libs/langgraph/langgraph/runtime.py +++ b/libs/langgraph/langgraph/runtime.py @@ -26,7 +26,9 @@ class _RuntimeOverrides(TypedDict, Generic[ContextT], total=False): class Runtime(Generic[ContextT]): """Convenience class that bundles run-scoped context and graph configuration. - !!! version-added "Added in version 1.0.0." + !!! version-added "Added in version v0.6.0" + + TODO: write a compelling example with the new API. """ context: ContextT = field(default=None) # type: ignore[assignment] diff --git a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py index 7b63c528c..34c1a930b 100644 --- a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py +++ b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py @@ -363,6 +363,10 @@ def create_react_agent( name: An optional name for the CompiledStateGraph. This name will be automatically used when adding ReAct agent graph to another graph as a subgraph node - particularly useful for building multi-agent systems. + config_schema: Specifies the schema for the `configurable` key in the `RunnableConfig` object. + !!! warning "Deprecated" + This parameter is deprecated and support will be removed in v2.0.0. + Please use `context_schema` instead. Returns: A compiled LangChain runnable that can be used for chat interactions. From 39977ded8ccf646f2d692711f3e2fe7612c0f5b6 Mon Sep 17 00:00:00 2001 From: Sydney Runkle Date: Thu, 24 Jul 2025 16:36:51 -0400 Subject: [PATCH 3/8] runtime api ref --- docs/mkdocs.yml | 1 + libs/langgraph/langgraph/runtime.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index e76332942..506572963 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -250,6 +250,7 @@ nav: - Storage: reference/store.md - Caching: reference/cache.md - Types: reference/types.md + - Runtime: reference/runtime.md - Config: reference/config.md - Errors: reference/errors.md - Constants: reference/constants.md diff --git a/libs/langgraph/langgraph/runtime.py b/libs/langgraph/langgraph/runtime.py index c498584c2..2d430ebcd 100644 --- a/libs/langgraph/langgraph/runtime.py +++ b/libs/langgraph/langgraph/runtime.py @@ -12,6 +12,8 @@ from langgraph.types import _DC_KWARGS, StreamWriter from langgraph.typing import ContextT +__all__ = ("Runtime", "get_runtime") + def _no_op_stream_writer(_: Any) -> None: ... @@ -78,7 +80,14 @@ DEFAULT_RUNTIME = Runtime( def get_runtime(context_schema: type[ContextT] | None = None) -> Runtime[ContextT]: - """Get the runtime for the current graph run.""" + """Get the runtime for the current graph run. + + Args: + context_schema: Optional schema used for type hinting the return type of the runtime. + + Returns: + The runtime for the current graph run. + """ # TODO: in an ideal world, we would have a context manager for # the runtime that's independent of the config. this will follow From 276310e11615952dcb9348b9cc8ce302760e9094 Mon Sep 17 00:00:00 2001 From: Sydney Runkle Date: Thu, 24 Jul 2025 16:54:20 -0400 Subject: [PATCH 4/8] fix and interrupt --- docs/docs/concepts/human_in_the_loop.md | 2 +- libs/langgraph/langgraph/types.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/docs/concepts/human_in_the_loop.md b/docs/docs/concepts/human_in_the_loop.md index eabe5fe85..442a98b35 100644 --- a/docs/docs/concepts/human_in_the_loop.md +++ b/docs/docs/concepts/human_in_the_loop.md @@ -23,7 +23,7 @@ To review, edit, and approve tool calls in an agent or workflow, [use LangGraph' ## Key capabilities -* **Persistent execution state**: Interrupts use LangGraph's [persistence](../../concepts/persistence.md) layer, which saves the graph state, to indefinitely pause graph execution until you resume. This is possible because LangGraph checkpoints the graph state after each step, which allows the system to persist execution context and later resume the workflow, continuing from where it left off. This supports asynchronous human review or input without time constraints. +* **Persistent execution state**: Interrupts use LangGraph's [persistence](./persistence.md) layer, which saves the graph state, to indefinitely pause graph execution until you resume. This is possible because LangGraph checkpoints the graph state after each step, which allows the system to persist execution context and later resume the workflow, continuing from where it left off. This supports asynchronous human review or input without time constraints. There are two ways to pause a graph: diff --git a/libs/langgraph/langgraph/types.py b/libs/langgraph/langgraph/types.py index 867991b35..3dcc8f8dc 100644 --- a/libs/langgraph/langgraph/types.py +++ b/libs/langgraph/langgraph/types.py @@ -149,10 +149,25 @@ class Interrupt: """Information about an interrupt that occurred in a node. !!! version-added "Added in version 0.2.24." + + !!! version-changed "Changed in version v0.4.0" + * `interrupt_id` was introduced as a property + + !!! version-changed "Changed in version v0.6.0" + + The following attributes have been removed: + + * `ns` + * `when` + * `resumable` + * `interrupt_id`, deprecated in favor of `id` """ value: Any + """The value associated with the interrupt.""" + id: str + """The ID of the interrupt. Can be used to resume the interrupt directly.""" def __init__( self, From 5312edc830df9ad6a268aa626dcd2a1468d39d35 Mon Sep 17 00:00:00 2001 From: Sydney Runkle Date: Thu, 24 Jul 2025 17:28:58 -0400 Subject: [PATCH 5/8] more runtime details --- docs/docs/reference/runtime.md | 18 +++++++++ libs/langgraph/langgraph/runtime.py | 58 +++++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 docs/docs/reference/runtime.md diff --git a/docs/docs/reference/runtime.md b/docs/docs/reference/runtime.md new file mode 100644 index 000000000..f326e78b8 --- /dev/null +++ b/docs/docs/reference/runtime.md @@ -0,0 +1,18 @@ +# Runtime + +::: langgraph.runtime.Runtime + options: + show_root_heading: true + show_root_full_path: false + members: + - context + - store + - stream_writer + - previous + +::: langgraph.runtime + options: + members: + - get_runtime + + diff --git a/libs/langgraph/langgraph/runtime.py b/libs/langgraph/langgraph/runtime.py index 2d430ebcd..5c1053a78 100644 --- a/libs/langgraph/langgraph/runtime.py +++ b/libs/langgraph/langgraph/runtime.py @@ -11,9 +11,9 @@ from langgraph.store.base import BaseStore from langgraph.types import _DC_KWARGS, StreamWriter from langgraph.typing import ContextT - __all__ = ("Runtime", "get_runtime") + def _no_op_stream_writer(_: Any) -> None: ... @@ -26,11 +26,61 @@ class _RuntimeOverrides(TypedDict, Generic[ContextT], total=False): @dataclass(**_DC_KWARGS) class Runtime(Generic[ContextT]): - """Convenience class that bundles run-scoped context and graph configuration. + """Convenience class that bundles run-scoped context and other runtime utilities. !!! version-added "Added in version v0.6.0" - TODO: write a compelling example with the new API. + Example: + + ```python + from typing import TypedDict + from langgraph.graph import StateGraph + from dataclasses import dataclass + from langgraph.runtime import Runtime + from langgraph.store.memory import InMemoryStore + + + @dataclass + class Context: # (1)! + user_id: str + + + class State(TypedDict, total=False): + response: str + + + store = InMemoryStore() # (2)! + store.put(("users",), "user_123", {"name": "Alice"}) + + + def personalized_greeting(state: State, runtime: Runtime[Context]) -> State: + '''Generate personalized greeting using runtime context and store.''' + user_id = runtime.context.user_id # (3)! + name = "unknown_user" + if runtime.store: + if memory := runtime.store.get(("users",), user_id): + name = memory.value["name"] + + response = f"Hello {name}! Nice to see you again." + return {"response": response} + + + graph = ( + StateGraph(state_schema=State, context_schema=Context) + .add_node("personalized_greeting", personalized_greeting) + .set_entry_point("personalized_greeting") + .set_finish_point("personalized_greeting") + .compile(store=store) + ) + + result = graph.invoke({}, context=Context(user_id="user_123")) + print(result) + # > {'response': 'Hello Alice! Nice to see you again.'} + ``` + + 1. Define a schema for the runtime context. + 2. Create a store to persist memories and other information. + 3. Use the runtime context to access the user_id. """ context: ContextT = field(default=None) # type: ignore[assignment] @@ -81,7 +131,7 @@ DEFAULT_RUNTIME = Runtime( def get_runtime(context_schema: type[ContextT] | None = None) -> Runtime[ContextT]: """Get the runtime for the current graph run. - + Args: context_schema: Optional schema used for type hinting the return type of the runtime. From aaff46411583d8d2800d4916ba033eb55a51fc8f Mon Sep 17 00:00:00 2001 From: Sydney Runkle Date: Fri, 25 Jul 2025 09:23:59 -0400 Subject: [PATCH 6/8] move deprecation note for config_schema --- libs/langgraph/langgraph/func/__init__.py | 9 +++++---- libs/langgraph/langgraph/graph/state.py | 8 ++++---- libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py | 9 +++++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/libs/langgraph/langgraph/func/__init__.py b/libs/langgraph/langgraph/func/__init__.py index ec453fec2..5d60f2095 100644 --- a/libs/langgraph/langgraph/func/__init__.py +++ b/libs/langgraph/langgraph/func/__init__.py @@ -261,10 +261,11 @@ class entrypoint(Generic[ContextT]): passed to the workflow. cache_policy: A cache policy to use for caching the results of the workflow. retry_policy: A retry policy (or list of policies) to use for the workflow in case of a failure. - config_schema: Specifies the schema for the `configurable` key in the `RunnableConfig` object. - !!! warning "Deprecated" - This parameter is deprecated and support will be removed in v2.0.0. - Please use `context_schema` instead. + + !!! warning "`config_schema` Deprecated" + The `config_schema` parameter is deprecated in v0.6.0 and support will be removed in v2.0.0. + Please use `context_schema` instead to specify the schema run run-scoped context. + Example: Using entrypoint and tasks ```python diff --git a/libs/langgraph/langgraph/graph/state.py b/libs/langgraph/langgraph/graph/state.py index 0bee5c0dc..9c218bdc3 100644 --- a/libs/langgraph/langgraph/graph/state.py +++ b/libs/langgraph/langgraph/graph/state.py @@ -128,10 +128,10 @@ class StateGraph(Generic[StateT, ContextT, InputT, OutputT]): Use this to expose immutable context data to your nodes, like user_id, db_conn, etc. input_schema: The schema class that defines the input to the graph. output_schema: The schema class that defines the output from the graph. - config_schema: Specifies the schema for the `configurable` key in the `RunnableConfig` object. - !!! warning "Deprecated" - This parameter is deprecated and support will be removed in v2.0.0. - Please use `context_schema` instead. + + !!! warning "`config_schema` Deprecated" + The `config_schema` parameter is deprecated in v0.6.0 and support will be removed in v2.0.0. + Please use `context_schema` instead to specify the schema run run-scoped context. Example: ```python diff --git a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py index 34c1a930b..e5aa25010 100644 --- a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py +++ b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py @@ -363,10 +363,11 @@ def create_react_agent( name: An optional name for the CompiledStateGraph. This name will be automatically used when adding ReAct agent graph to another graph as a subgraph node - particularly useful for building multi-agent systems. - config_schema: Specifies the schema for the `configurable` key in the `RunnableConfig` object. - !!! warning "Deprecated" - This parameter is deprecated and support will be removed in v2.0.0. - Please use `context_schema` instead. + + !!! warning "`config_schema` Deprecated" + The `config_schema` parameter is deprecated in v0.6.0 and support will be removed in v2.0.0. + Please use `context_schema` instead to specify the schema run run-scoped context. + Returns: A compiled LangChain runnable that can be used for chat interactions. From 5b9021ff37e42792bc22d69034fd2abbf4ecaea4 Mon Sep 17 00:00:00 2001 From: Sydney Runkle Date: Fri, 25 Jul 2025 09:25:26 -0400 Subject: [PATCH 7/8] typo --- libs/langgraph/langgraph/func/__init__.py | 2 +- libs/langgraph/langgraph/graph/state.py | 2 +- libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/langgraph/langgraph/func/__init__.py b/libs/langgraph/langgraph/func/__init__.py index 5d60f2095..6ecebb9c3 100644 --- a/libs/langgraph/langgraph/func/__init__.py +++ b/libs/langgraph/langgraph/func/__init__.py @@ -264,7 +264,7 @@ class entrypoint(Generic[ContextT]): !!! warning "`config_schema` Deprecated" The `config_schema` parameter is deprecated in v0.6.0 and support will be removed in v2.0.0. - Please use `context_schema` instead to specify the schema run run-scoped context. + Please use `context_schema` instead to specify the schema for run-scoped context. Example: Using entrypoint and tasks diff --git a/libs/langgraph/langgraph/graph/state.py b/libs/langgraph/langgraph/graph/state.py index 9c218bdc3..e7854b900 100644 --- a/libs/langgraph/langgraph/graph/state.py +++ b/libs/langgraph/langgraph/graph/state.py @@ -131,7 +131,7 @@ class StateGraph(Generic[StateT, ContextT, InputT, OutputT]): !!! warning "`config_schema` Deprecated" The `config_schema` parameter is deprecated in v0.6.0 and support will be removed in v2.0.0. - Please use `context_schema` instead to specify the schema run run-scoped context. + Please use `context_schema` instead to specify the schema for run-scoped context. Example: ```python diff --git a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py index e5aa25010..2f07cabfc 100644 --- a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py +++ b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py @@ -366,7 +366,7 @@ def create_react_agent( !!! warning "`config_schema` Deprecated" The `config_schema` parameter is deprecated in v0.6.0 and support will be removed in v2.0.0. - Please use `context_schema` instead to specify the schema run run-scoped context. + Please use `context_schema` instead to specify the schema for run-scoped context. Returns: From 22411ba0fd1cff6e50aa8cff8230ff9510e27b18 Mon Sep 17 00:00:00 2001 From: Sydney Runkle Date: Fri, 25 Jul 2025 09:27:34 -0400 Subject: [PATCH 8/8] lint --- libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py index 2f07cabfc..f2c472fcf 100644 --- a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py +++ b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py @@ -363,7 +363,7 @@ def create_react_agent( name: An optional name for the CompiledStateGraph. This name will be automatically used when adding ReAct agent graph to another graph as a subgraph node - particularly useful for building multi-agent systems. - + !!! warning "`config_schema` Deprecated" The `config_schema` parameter is deprecated in v0.6.0 and support will be removed in v2.0.0. Please use `context_schema` instead to specify the schema for run-scoped context.