From 95091f7a66cced58c13110223e9bc336237518eb Mon Sep 17 00:00:00 2001 From: "open-swe[bot]" Date: Tue, 29 Jul 2025 17:28:35 +0000 Subject: [PATCH] Apply patch --- .../langgraph/_internal/_runnable.py | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/libs/langgraph/langgraph/_internal/_runnable.py b/libs/langgraph/langgraph/_internal/_runnable.py index a541a92d8..dff49a4ab 100644 --- a/libs/langgraph/langgraph/_internal/_runnable.py +++ b/libs/langgraph/langgraph/_internal/_runnable.py @@ -489,46 +489,46 @@ def is_async_generator( class _PregelWrapper(Runnable): """Wrapper for PregelProtocol instances to handle runtime context propagation. - + When a compiled subgraph (PregelProtocol) is added as a node, this wrapper extracts the runtime context from the config and passes it explicitly to the subgraph's invoke method. """ - + def __init__(self, pregel: "PregelProtocol", name: str | None = None): self.pregel = pregel self._name = name or getattr(pregel, "name", None) or pregel.__class__.__name__ - + def get_name(self, suffix: str | None = None, *, name: str | None = None) -> str: """Get the name of the runnable.""" name = name or self._name return f"{name}{suffix}" if suffix else name - + def invoke( self, input: Any, config: RunnableConfig | None = None, **kwargs: Any ) -> Any: """Invoke the wrapped PregelProtocol with runtime context extracted from config.""" if config is None: config = ensure_config() - + # Extract runtime context from config runtime = config.get(CONF, {}).get(CONFIG_KEY_RUNTIME) context = runtime.context if runtime else None - + # Invoke the subgraph with the extracted context return self.pregel.invoke(input, config, context=context, **kwargs) - + async def ainvoke( self, input: Any, config: RunnableConfig | None = None, **kwargs: Any ) -> Any: """Async invoke the wrapped PregelProtocol with runtime context extracted from config.""" if config is None: config = ensure_config() - + # Extract runtime context from config runtime = config.get(CONF, {}).get(CONFIG_KEY_RUNTIME) context = runtime.context if runtime else None - + # Invoke the subgraph with the extracted context return await self.pregel.ainvoke(input, config, context=context, **kwargs) @@ -951,6 +951,3 @@ async def _consume_aiter(it: AsyncIterator[Any]) -> Any: else: output = chunk return output - - -