From e332869a0cecbb32db0a4d1df417c44d90ea2edb Mon Sep 17 00:00:00 2001 From: William FH <13333726+hinthornw@users.noreply.github.com> Date: Mon, 30 Sep 2024 09:54:47 -0700 Subject: [PATCH] Ensure configurable (#1912) --- libs/langgraph/langgraph/utils/config.py | 2 ++ libs/langgraph/tests/test_runnable.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/libs/langgraph/langgraph/utils/config.py b/libs/langgraph/langgraph/utils/config.py index 6f75c64ba..3993df9b2 100644 --- a/libs/langgraph/langgraph/utils/config.py +++ b/libs/langgraph/langgraph/utils/config.py @@ -120,6 +120,8 @@ def merge_configs(*configs: Optional[RunnableConfig]) -> RunnableConfig: base["recursion_limit"] = config["recursion_limit"] else: base[key] = config[key] # type: ignore[literal-required] + if CONF not in base: + base[CONF] = {} return base diff --git a/libs/langgraph/tests/test_runnable.py b/libs/langgraph/tests/test_runnable.py index 64d858fd4..2bd2e20d5 100644 --- a/libs/langgraph/tests/test_runnable.py +++ b/libs/langgraph/tests/test_runnable.py @@ -41,3 +41,21 @@ async def afunc_with_writer(x: Any, writer: StreamWriter) -> str: for name, runnable in runnables.items(): assert runnable.func_accepts["writer"] == expected_writer.get(name, False) assert runnable.func_accepts["store"] == expected_store.get(name, False) + + +async def test_runnable_callable_basic(): + def sync_func(x: Any) -> str: + return f"{x}" + + async def async_func(x: Any) -> str: + return f"{x}" + + runnable_sync = RunnableCallable(sync_func) + runnable_async = RunnableCallable(func=None, afunc=async_func) + + result_sync = runnable_sync.invoke("test") + assert result_sync == "test" + + # Test asynchronous ainvoke + result_async = await runnable_async.ainvoke("test") + assert result_async == "test"