From a1b26dd9b653c5fec1a98d25a1e938c55ff52e6c Mon Sep 17 00:00:00 2001 From: Nikhil Kumar <64120577+nikhilkmr300@users.noreply.github.com> Date: Sat, 16 Mar 2024 17:48:00 -0700 Subject: [PATCH] docs: Add docs for RouterRunnable (#19191) - [x] **Docs for `RouterRunnable`**: core: Add docs for `RouterRunnable` - [x] **Add docs for `RouterRunnable`**: - **Description:** Add docs for `RouterRunnable`, which was previously missing documentation - **Issue:** #18803 - **Dependencies:** N/A - **Twitter handle:** None --- libs/core/langchain_core/runnables/router.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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]]