Home / Class/ RunnableLambda Class — langchain Architecture

RunnableLambda Class — langchain Architecture

Architecture documentation for the RunnableLambda class in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea["RunnableLambda"]
  4a62481c_02cb_a5de_1833_50669d5351a6["Runnable"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea -->|extends| 4a62481c_02cb_a5de_1833_50669d5351a6
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea["RunnableLambda"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea -->|extends| c6a370e4_a02a_c56a_38eb_7ca734dcbfea
  a9ff2022_42eb_faa1_f8cd_8484064f7a1b["base.py"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea -->|defined in| a9ff2022_42eb_faa1_f8cd_8484064f7a1b
  4dbf1113_4565_2b17_c718_51e6a4211bf6["__init__()"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea -->|method| 4dbf1113_4565_2b17_c718_51e6a4211bf6
  9e7ec506_ed2e_07c1_6a26_e06c37c6134c["InputType()"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea -->|method| 9e7ec506_ed2e_07c1_6a26_e06c37c6134c
  7866ea60_3af0_a9b8_ebab_618c759e89c8["get_input_schema()"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea -->|method| 7866ea60_3af0_a9b8_ebab_618c759e89c8
  fe5e92ef_6b27_0e9e_cba6_4e5b13a118db["OutputType()"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea -->|method| fe5e92ef_6b27_0e9e_cba6_4e5b13a118db
  1ca1316b_add2_5905_2c2a_ffd20e4c42c7["get_output_schema()"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea -->|method| 1ca1316b_add2_5905_2c2a_ffd20e4c42c7
  07af836b_2e26_2328_e13d_fb34607b1afa["deps()"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea -->|method| 07af836b_2e26_2328_e13d_fb34607b1afa
  dbac083a_98b6_73da_89f1_7460713d32e0["config_specs()"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea -->|method| dbac083a_98b6_73da_89f1_7460713d32e0
  4b92cace_dc70_6808_9c96_2880d0125ea4["get_graph()"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea -->|method| 4b92cace_dc70_6808_9c96_2880d0125ea4
  6ed03c82_a522_b483_a1ef_2c7af8eb53c2["__eq__()"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea -->|method| 6ed03c82_a522_b483_a1ef_2c7af8eb53c2
  3af9ca9d_6450_8a28_13aa_4fabcb0dfdab["__repr__()"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea -->|method| 3af9ca9d_6450_8a28_13aa_4fabcb0dfdab
  15bcbb64_a12d_e5ab_35ce_209867a93c74["_invoke()"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea -->|method| 15bcbb64_a12d_e5ab_35ce_209867a93c74
  4343d7c8_f1ee_8c72_b4a3_a26cae12cc7c["_ainvoke()"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea -->|method| 4343d7c8_f1ee_8c72_b4a3_a26cae12cc7c

Relationship Graph

Source Code

libs/core/langchain_core/runnables/base.py lines 4399–5269

class RunnableLambda(Runnable[Input, Output]):
    """`RunnableLambda` converts a python callable into a `Runnable`.

    Wrapping a callable in a `RunnableLambda` makes the callable usable
    within either a sync or async context.

    `RunnableLambda` can be composed as any other `Runnable` and provides
    seamless integration with LangChain tracing.

    `RunnableLambda` is best suited for code that does not need to support
    streaming. If you need to support streaming (i.e., be able to operate
    on chunks of inputs and yield chunks of outputs), use `RunnableGenerator`
    instead.

    Note that if a `RunnableLambda` returns an instance of `Runnable`, that
    instance is invoked (or streamed) during execution.

    Examples:
        ```python
        # This is a RunnableLambda
        from langchain_core.runnables import RunnableLambda


        def add_one(x: int) -> int:
            return x + 1


        runnable = RunnableLambda(add_one)

        runnable.invoke(1)  # returns 2
        runnable.batch([1, 2, 3])  # returns [2, 3, 4]

        # Async is supported by default by delegating to the sync implementation
        await runnable.ainvoke(1)  # returns 2
        await runnable.abatch([1, 2, 3])  # returns [2, 3, 4]


        # Alternatively, can provide both synd and sync implementations
        async def add_one_async(x: int) -> int:
            return x + 1


        runnable = RunnableLambda(add_one, afunc=add_one_async)
        runnable.invoke(1)  # Uses add_one
        await runnable.ainvoke(1)  # Uses add_one_async
        ```
    """

    @overload
    def __init__(
        self,
        func: Callable[[Input, RunnableConfig], Awaitable[Output]],
        afunc: None = None,
        name: str | None = None,
    ) -> None: ...

    @overload
    def __init__(
        self,
        func: Callable[[Input], Awaitable[Output]],
        afunc: None = None,
        name: str | None = None,
    ) -> None: ...

    @overload
    def __init__(
        self,
        func: Callable[[Input], AsyncIterator[Output]],
        afunc: None = None,
        name: str | None = None,
    ) -> None: ...

    @overload
    def __init__(
        self,
        func: Callable[[Input, AsyncCallbackManagerForChainRun], Awaitable[Output]],
        afunc: None = None,
        name: str | None = None,
    ) -> None: ...

    @overload

Frequently Asked Questions

What is the RunnableLambda class?
RunnableLambda is a class in the langchain codebase, defined in libs/core/langchain_core/runnables/base.py.
Where is RunnableLambda defined?
RunnableLambda is defined in libs/core/langchain_core/runnables/base.py at line 4399.
What does RunnableLambda extend?
RunnableLambda extends Runnable, RunnableLambda.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free