Skip to main content

RunnableSequence

Struct RunnableSequence 

Source
pub struct RunnableSequence<I: Send + Sync + 'static, O: Send + Sync + 'static> { /* private fields */ }
Expand description

A sequence of Runnable steps composed into a pipeline.

Created via the pipe() method on RunnableExt, or directly with from_single / from_pair.

§Type Safety

The I and O type parameters represent the pipeline’s overall input and output types. Intermediate types are erased at runtime via RunnableAny, but the compiler guarantees type compatibility at each pipe() call site.

§Flattening

When two RunnableSequence values are piped together, their internal steps are merged (flattened) rather than nested, avoiding unnecessary indirection.

Implementations§

Source§

impl<I: Send + Sync + 'static, O: Send + Sync + 'static> RunnableSequence<I, O>

Source

pub fn from_single<R>(runnable: R) -> Self
where R: Runnable<I, O> + 'static, R::Error: Into<LcelError>,

Create a sequence from a single runnable step.

Source

pub fn from_pair<R1, R2, M>(first: R1, second: R2) -> RunnableSequence<I, O>
where M: Send + Sync + 'static, R1: Runnable<I, M> + 'static, R1::Error: Into<LcelError>, R2: Runnable<M, O> + 'static, R2::Error: Into<LcelError>,

Create a sequence from two runnable steps.

The output type of the first must match the input type of the second.

Source

pub fn pipe<O2, R>(self, other: R) -> RunnableSequence<I, O2>
where O2: Send + Sync + 'static, R: Runnable<O, O2> + Send + Sync + 'static, R::Error: Into<LcelError>,

Append a step to this sequence, returning a new sequence with the updated output type.

Source

pub fn len(&self) -> usize

Number of steps in this sequence.

Source

pub fn is_empty(&self) -> bool

Whether this sequence has no steps.

Source

pub fn steps(&self) -> &[Box<dyn RunnableAny>]

Access the steps as a slice.

Trait Implementations§

Source§

impl<I: Send + Sync + 'static, O: Send + Sync + 'static> Debug for RunnableSequence<I, O>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I: Send + Sync + 'static, O: Send + Sync + 'static> Runnable<I, O> for RunnableSequence<I, O>

Source§

fn invoke<'life0, 'async_trait>( &'life0 self, input: I, config: Option<RunnableConfig>, ) -> Pin<Box<dyn Future<Output = Result<O, LcelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the pipeline: feed input through each step sequentially.

Source§

fn batch<'life0, 'async_trait>( &'life0 self, inputs: Vec<I>, config: Option<RunnableConfig>, ) -> Pin<Box<dyn Future<Output = Result<Vec<O>, LcelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Batch processing: each step processes all inputs before passing to the next step. This allows LLM providers to optimize batch requests.

Source§

fn stream<'life0, 'async_trait>( &'life0 self, input: I, config: Option<RunnableConfig>, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<O, LcelError>> + Send>>, LcelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Streaming: the first step runs through stream_any (single input → item stream) and every following step runs through transform_any. Steps that override stream (e.g. LLMs) therefore emit a real token stream instead of being collapsed to a single invoke.

Source§

fn transform<'life0, 'async_trait>( &'life0 self, input: Pin<Box<dyn Stream<Item = Result<I, LcelError>> + Send>>, config: Option<RunnableConfig>, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<O, LcelError>> + Send>>, LcelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Transform: chain each step’s transform to enable stream-to-stream pipeline processing.

Source§

type Error = LcelError

Error type.

Auto Trait Implementations§

§

impl<I, O> !RefUnwindSafe for RunnableSequence<I, O>

§

impl<I, O> !UnwindSafe for RunnableSequence<I, O>

§

impl<I, O> Freeze for RunnableSequence<I, O>

§

impl<I, O> Send for RunnableSequence<I, O>

§

impl<I, O> Sync for RunnableSequence<I, O>

§

impl<I, O> Unpin for RunnableSequence<I, O>
where I: Unpin, O: Unpin,

§

impl<I, O> UnsafeUnpin for RunnableSequence<I, O>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<I, O, R> RunnableExt<I, O> for R
where I: Send + Sync + 'static, O: Send + Sync + 'static, R: Runnable<I, O> + 'static, <R as Runnable<I, O>>::Error: Into<LcelError>,

Source§

fn pipe<O2, R2>(self, other: R2) -> RunnableSequence<Input, O2>
where O2: Send + Sync + 'static, R2: Runnable<Output, O2> + Send + Sync + 'static, R2::Error: Into<LcelError>,

Pipe the output of this runnable into another runnable. Read more
Source§

fn into_sequence(self) -> RunnableSequence<Input, Output>

Create a RunnableSequence from this runnable as a single step. Read more
Source§

fn with_fallbacks<R>( self, fallbacks: Vec<R>, ) -> RunnableWithFallbacks<Input, Output>
where Input: Clone, R: Runnable<Input, Output> + Send + Sync + 'static, R::Error: Into<LcelError>,

Add fallback runnables that are tried if this one fails. Read more
Source§

fn with_retry(self, retry_config: RetryConfig) -> RunnableRetry<Input, Output>
where Input: Clone,

Wrap this runnable with retry logic using exponential backoff. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more