Skip to content

The agent engineering platform.

core[patch]: add caching to get_function_nonlocals (#28131)

Vadym Bardaed4952e475f8
diff --git a/libs/core/langchain_core/runnables/utils.py b/libs/core/langchain_core/runnables/utils.py
index 06168a176d..a81ca7615a 100644
--- a/libs/core/langchain_core/runnables/utils.py
+++ b/libs/core/langchain_core/runnables/utils.py
@@ -388,6 +388,7 @@ def get_lambda_source(func: Callable) -> Optional[str]:
return name
+@lru_cache(maxsize=256)
def get_function_nonlocals(func: Callable) -> list[Any]:
"""Get the nonlocal variables accessed by a function.