Runnable<RunInput extends Object?, CallOptions extends RunnableOptions, RunOutput extends Object?> class
abstract
A Runnable is a generic unit of work that can be invoked, batched, streamed, and/or transformed. It is the basic building block of the LangChain Expression Language (LCEL).
It is implemented by most of the LangChain components (prompt templates, models, retrievers, output parsers, etc.) which makes it easy to define custom chains as well as making it possible to invoke them in a standard way.
The standard interface exposed includes:
- stream stream back chunks of the response.
- invoke call the chain on an input.
- batch call the chain on a list of inputs.
There are also several useful primitives for working with runnables:
- pipe allows you to chain runnables together (alternatively, you can use
the
|
operator or the fromList static method. - fromMap allows you to run multiple runnables concurrently on the same input returning a map of the results.
- passthrough takes the input it receives and passes it through as output.
- mapInput allows you to map the input to a different value.
- mapInputStream allows you to map the input stream to a different stream of values.
- getItemFromMap allows you to get a value from the input.
- getMapFromInput allows you to output a map with the given key and the input as value.
- fromFunction allows you to run a Dart function as part of a chain.
- fromRouter takes the input it receives and routes it to the runnable returned by the router function.
- bind allows you to bind the runnable to a set of options.
- Implementers
- Available extensions
Constructors
- Runnable({required CallOptions defaultOptions})
-
A Runnable is a generic unit of work that can be invoked, batched,
streamed, and/or transformed. It is the basic building block of the
LangChain Expression Language (LCEL).
const
Properties
- defaultOptions → CallOptions
-
The default options to use when invoking the Runnable.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
batch(
List< RunInput> inputs, {List<CallOptions> ? options}) → Future<List< RunOutput> > -
Batches the invocation of the Runnable on the given
inputs
. -
bind(
CallOptions options) → RunnableBinding< RunInput, CallOptions, RunOutput> -
Binds the Runnable to the given
options
. -
close(
) → void - Cleans up any resources associated with it the Runnable.
-
getCompatibleOptions(
RunnableOptions? options) → CallOptions? -
Returns the given
options
if they are compatible with the Runnable, otherwise returnsnull
. -
invoke(
RunInput input, {CallOptions? options}) → Future< RunOutput> -
Invokes the Runnable on the given
input
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pipe<
NewRunOutput extends Object?, NewCallOptions extends RunnableOptions> (Runnable< RunOutput, NewCallOptions, NewRunOutput> next) → RunnableSequence<RunInput, NewRunOutput> - Pipes the output of this Runnable into another Runnable using a RunnableSequence.
-
stream(
RunInput input, {CallOptions? options}) → Stream< RunOutput> -
Streams the output of invoking the Runnable on the given
input
. -
streamFromInputStream(
Stream< RunInput> inputStream, {CallOptions? options}) → Stream<RunOutput> -
Streams the output of invoking the Runnable on the given
inputStream
. -
toString(
) → String -
A string representation of this object.
inherited
-
withFallbacks(
List< Runnable< fallbacks) → RunnableWithFallback<RunInput, RunnableOptions, RunOutput> >RunInput, RunOutput> - Adds fallback runnables to be invoked if the primary runnable fails.
-
withRetry(
{int maxRetries = 3, FutureOr< bool> retryIf(Object e)?, List<Duration?> ? delayDurations, bool addJitter = false}) → RunnableRetry<RunInput, RunOutput> - Adds retry logic to an existing runnable.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator |(
Runnable< RunOutput, RunnableOptions, NewRunOutput> next) → RunnableSequence<RunInput, NewRunOutput> -
Available on Runnable<
Pipes the output of this Runnable into another Runnable.RunInput, CallOptions, RunOutput> , provided by the RunnableX extension
Static Methods
-
fromFunction<
RunInput extends Object, RunOutput extends Object> ({FutureOr< RunOutput> invoke(RunInput input, RunnableOptions? options)?, Stream<RunOutput> stream(Stream<RunInput> inputStream, RunnableOptions? options)?}) → Runnable<RunInput, RunnableOptions, RunOutput> - Creates a RunnableFunction from a Dart function.
-
fromList(
List< Runnable< runnables) → Runnable<Object?, RunnableOptions, Object?> >Object?, RunnableOptions, Object?> - Creates a RunnableSequence from a list of Runnable objects.
-
fromMap<
RunInput extends Object> (Map< String, Runnable< steps) → Runnable<RunInput, RunnableOptions, Object> >RunInput, RunnableOptions, Map< String, dynamic> > - Creates a RunnableMap from a map of Runnable objects.
-
fromRouter<
RunInput extends Object, RunOutput extends Object> (FutureOr< Runnable< router(RunInput input, RunnableOptions? options)) → Runnable<RunInput, RunnableOptions, RunOutput> >RunInput, RunnableOptions, RunOutput> - Creates a RunnableRouter from a Dart function.
-
getItemFromMap<
RunOutput extends Object> (String key) → Runnable< Map< String, dynamic> , RunnableOptions, RunOutput> - Convenience method to return a value from an input map.
-
getMapFromInput<
RunInput extends Object> ([String key = 'input']) → Runnable< RunInput, RunnableOptions, Map< String, dynamic> > - Convenience method to return a map with the given key and the input as value.
-
mapInput<
RunInput extends Object, RunOutput extends Object> (FutureOr< RunOutput> inputMapper(RunInput input)) → Runnable<RunInput, RunnableOptions, RunOutput> - Creates a RunnableMapInput from a function.
-
mapInputStream<
RunInput extends Object, RunOutput extends Object> (Stream< RunOutput> inputStreamMapper(Stream<RunInput> inputStream)) → Runnable<RunInput, RunnableOptions, RunOutput> - Creates a RunnableMapInputStream from an asynchronous generator.
-
passthrough<
RunInput extends Object> () → Runnable< RunInput, RunnableOptions, RunInput> - Creates a RunnablePassthrough.