Primitives
In addition to various components that are usable with LCEL, LangChain also includes various primitives that help pass around and format data, bind arguments, invoke custom logic, and more.
This section goes into greater depth on where and how some of these components are useful.
ποΈ Sequences: Chaining runnables
One key advantage of the Runnable interface is that any two runnables can be "chained" together into sequences. The output of the previous runnable's .invoke() call is passed as input to the next runnable. This can be done using the pipe operator (|), or the more explicit .pipe() method, which does the same thing. The resulting RunnableSequence is itself a runnable, which means it can be invoked, streamed, or piped just like any other runnable.
ποΈ Parallel: Format data
The RunnableParallel primitive is essentially a dict whose values are runnables (or things that can be coerced to runnables, like functions). It runs all of its values in parallel, and each value is called with the overall input of the RunnableParallel. The final return value is a dict with the results of each value under its appropriate key.
ποΈ Binding: Attach runtime args
Sometimes we want to invoke a Runnable within a Runnable sequence with constant arguments that are not part of the output of the preceding Runnable in the sequence, and which are not part of the user input. We can use Runnable.bind() to pass these arguments in.
ποΈ Lambda: Run custom functions
You can use arbitrary functions in the pipeline.
ποΈ Passthrough: Pass through inputs
RunnablePassthrough on its own allows you to pass inputs unchanged. This typically is used in conjuction with RunnableParallel to pass data through to a new key in the map.
ποΈ Assign: Add values to state
The RunnablePassthrough.assign(...) static method takes an input value and adds the extra arguments passed to the assign function.
ποΈ Configure runtime chain internals
Oftentimes you may want to experiment with, or even expose to the end user, multiple different ways of doing things.
ποΈ Primitives
In addition to various components that are usable with LCEL, LangChain also includes various primitives