Skip to main content

Module runnables

Module runnables 

Source
Expand description

Runnable module - LangChain Expression Language (LCEL) core

The Runnable trait is the foundation of LangChain’s composability. Every component (LLM, Prompt, Tool, etc.) implements Runnable, enabling them to be chained together seamlessly.

§LCEL Composition

Use pipe() to chain runnables:

let chain = prompt.pipe(llm).pipe(parser);
let result = chain.invoke("What is Rust?".to_string(), None).await?;

§Core Types

  • Runnable<I, O>: Base execution trait
  • RunnableExt: Extension providing pipe() composition
  • RunnableSequence<I, O>: Pipeline of chained runnables
  • RunnableLambda<I, O>: Closure wrapper
  • RunnablePassthrough<I>: Identity pass-through
  • RunnableParallel<I>: Fan-out/fan-in
  • RunnableBranch<I, O>: Conditional routing
  • RunnableBinding<I, O>: Config/kwargs binding
  • LcelError: Unified error type for pipelines

Structs§

CancellationToken
A token that can be used to signal cancellation of a long-running operation.
RetryConfig
Configuration for retry behavior.
RunnableAnyWrapper
Wrapper that implements RunnableAny for any Runnable<I, O>.
RunnableAssign
A Runnable that adds new key-value pairs to a HashMap<String, Value>.
RunnableBinding
A Runnable that binds runtime parameters and config to an inner runnable.
RunnableBranch
A Runnable that routes input to different branches based on conditions.
RunnableConfig
Runnable execution configuration.
RunnableConfigurable
Routes between a default runnable and named alternatives at invoke time.
RunnableConfigurableFields
Overrides recognized config fields at invoke time from config.configurable (Python’s Runnable.configurable_fields).
RunnableLambda
A Runnable that wraps a closure.
RunnableParallel
A Runnable that runs multiple steps in parallel on the same input.
RunnablePassthrough
A Runnable that passes its input through unchanged.
RunnableRetry
A Runnable wrapper that retries the inner Runnable on failure.
RunnableSequence
A sequence of Runnable steps composed into a pipeline.
RunnableWithFallbacks
A Runnable that tries fallbacks when the primary fails.

Enums§

LcelError
Unified error type for LCEL pipelines.
RetryOn
Determines which errors should trigger a retry.

Constants§

RUN_META_PARENT_RUN_ID
Reserved metadata key (UUID string): id of the parent run.
RUN_META_TRACE_ID
Reserved metadata key (UUID string): id of the trace root run.

Traits§

Runnable
Base trait for all LangChain components.
RunnableAny
Type-erased Runnable with unified LcelError.
RunnableExt
Extension trait that provides LCEL composition methods for Runnable.
RunnablePick
Extracts keys / values from a Runnable whose output is a HashMap<String, Value>.

Functions§

into_runnable_any
Helper function to convert any Runnable into Box<dyn RunnableAny>.
run_tree_from_config
Builds the RunTree a component dispatches its lifecycle callbacks against, applying the config every provider is expected to honor.