Skip to content

Runnables

In LangChain, the Runnable interface serves as a foundational abstraction for various components, enabling consistent and flexible interactions. A Runnable is defined as a unit of work that can be invoked, batched, streamed, transformed, and composed.

The Runnable interface provides several key methods:

  • .invoke(): Transforms a single input into an output.
  • .batch(): Efficiently processes multiple inputs into outputs.
  • .stream(): Streams output from a single input as it's produced.

In prompt templates, the .invoke() method is used to populate dynamic parts of the prompt at runtime.

Similarly, in chat models / LLMs, .invoke() processes a list of messages to generate a response.

This consistent interface simplifies the development of complex chains and workflows by allowing developers to interact with various components in a predictable manner.