diff --git a/libs/core/langchain_core/runnables/router.py b/libs/core/langchain_core/runnables/router.py index 846e0a677b0..82587b3e207 100644 --- a/libs/core/langchain_core/runnables/router.py +++ b/libs/core/langchain_core/runnables/router.py @@ -49,6 +49,19 @@ class RouterRunnable(RunnableSerializable[RouterInput, Output]): """ Runnable that routes to a set of Runnables based on Input['key']. Returns the output of the selected Runnable. + + For example, + + .. code-block:: python + + from langchain_core.runnables.router import RouterRunnable + from langchain_core.runnables import RunnableLambda + + add = RunnableLambda(func=lambda x: x + 1) + square = RunnableLambda(func=lambda x: x**2) + + router = RouterRunnable(runnables={"add": add, "square": square}) + router.invoke({"key": "square", "input": 3}) """ runnables: Mapping[str, Runnable[Any, Output]]