liveBook · Manning

Runnable interface

As explained in Build AI-Enhanced Web Apps

A runnable is a composable LangChain unit of work that accepts input, performs processing, and produces output, with support for invocation, batching, and streaming.

A runnable is a LangChain.js unit of work that accepts input, processes it, and produces output. It can be invoked, batched, or streamed. Connect runnables when an AI workflow needs several steps rather than one model call. section 6.1.1

LangChain Expression Language (LCEL) composes runnables in three useful ways:

  • RunnableSequence passes each output to the next runnable. section 6.5.1
  • RunnableParallel gives multiple runnables the same input and collects their outputs in a keyed object. section 6.5.1
  • RunnableLambda wraps a JavaScript function so custom processing can join a chain. section 6.5.1

From input text to a model response

Wrap an uppercase function and a vowel-counting function with RunnableLambda, then place them before a ChatPromptTemplate, ChatOpenAI model, and StringOutputParser. The first function reads the input text; the second produces vowelCount for the prompt. One demonstrated run returns `3 3`. The same ordered components can be assembled with RunnableSequence.from([...]). Model-backed runs require a provider API key. section 6.1.1

An LCEL chain is itself a runnable, so it can be composed into a larger workflow. Agents also fit into chain compositions as Runnable instances. This shared interface helps keep surrounding application code intact when implementation details change, including in a Vercel AI SDK integration. section 6.5.1 section 6.4.3

How Build AI-Enhanced Web Apps covers it

How deep it goes
Defines the interface and demonstrates composition primitives and a JavaScript chain, but does not work through batching or streaming.
Examples
Demonstrates uppercase and vowel-count functions feeding a prompt, model, and StringOutputParser, with a `3 3` result.
What it assumes
Assumes JavaScript project setup and a provider API key for model-backed runs while introducing runnable composition.
What you can do after
Build it from scratch using RunnableLambda and RunnableSequence to compose custom JavaScript processing with a model-backed chain.
How it connects
Links LCEL, RunnableSequence, RunnableParallel, RunnableLambda, prompt templates, output parsers, and agents.

Also explained in

Compare how 2 books explain Runnable interface →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI-Enhanced Web Apps. The section links point to the parts of the book it draws on.