LangChain primitives – chains and runnables
As we have discussed, LangChain is a framework for orchestrating your generative AI applications. Let’s look at two key LangChain primitives: runnables and chains.
The most basic LangChain abstract interface is langchain_core/runnables/base.Runnable
, and it makes it easy to compose different pieces together for the orchestration [4]. A Runnable
defines three main methods (there are some more, mainly for asynchronous applications; you can take a look at the full documentation if you’re interested [4]):
invoke
callsRunnable
on an input. It’s an abstract method that should be defined by the specific implementation.stream
callsRunnable
on an input and streams chunks of the response. With a default implementation, it just calls theinvoke
method and yields the output, but if you need proper streaming support, yourRunnable
should implement this method.batch
callsRunnable
on a list of inputs ...