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 traitRunnableExt: Extension providingpipe()compositionRunnableSequence<I, O>: Pipeline of chained runnablesRunnableLambda<I, O>: Closure wrapperRunnablePassthrough<I>: Identity pass-throughRunnableParallel<I>: Fan-out/fan-inRunnableBranch<I, O>: Conditional routingRunnableBinding<I, O>: Config/kwargs bindingLcelError: Unified error type for pipelines
Structs§
- Cancellation
Token - A token that can be used to signal cancellation of a long-running operation.
- Retry
Config - Configuration for retry behavior.
- Runnable
AnyWrapper - Wrapper that implements
RunnableAnyfor anyRunnable<I, O>. - Runnable
Assign - A
Runnablethat adds new key-value pairs to aHashMap<String, Value>. - Runnable
Binding - A
Runnablethat binds runtime parameters and config to an inner runnable. - Runnable
Branch - A
Runnablethat routes input to different branches based on conditions. - Runnable
Config - Runnable execution configuration.
- Runnable
Configurable - Routes between a default runnable and named alternatives at invoke time.
- Runnable
Configurable Fields - Overrides recognized config fields at invoke time from
config.configurable(Python’sRunnable.configurable_fields). - Runnable
Lambda - A
Runnablethat wraps a closure. - Runnable
Parallel - A
Runnablethat runs multiple steps in parallel on the same input. - Runnable
Passthrough - A
Runnablethat passes its input through unchanged. - Runnable
Retry - A Runnable wrapper that retries the inner Runnable on failure.
- Runnable
Sequence - A sequence of
Runnablesteps composed into a pipeline. - Runnable
With Fallbacks - A
Runnablethat tries fallbacks when the primary fails.
Enums§
- Lcel
Error - 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.
- Runnable
Any - Type-erased Runnable with unified
LcelError. - Runnable
Ext - Extension trait that provides LCEL composition methods for
Runnable. - Runnable
Pick - Extracts keys / values from a Runnable whose output is a
HashMap<String, Value>.
Functions§
- into_
runnable_ any - Helper function to convert any
RunnableintoBox<dyn RunnableAny>. - run_
tree_ from_ config - Builds the
RunTreea component dispatches its lifecycle callbacks against, applying the config every provider is expected to honor.