Core concepts ยท 7 min read

Core concepts

Runnables, messages, prompts and the composition model.


Almost everything in LangChain implements a single interface called a runnable. Learn that interface once and every component behaves predictably.

Runnables

  • invoke takes one input and returns one output.
  • batch runs many inputs with provider level concurrency.
  • stream yields incremental chunks as the model produces them.
  • Each of the three has an async counterpart.

Messages

Chat models speak in messages rather than plain strings. A conversation is an ordered list of system, human, AI and tool messages.

python
from langchain_core.messages import SystemMessage, HumanMessage

messages = [
    SystemMessage("You are a terse technical writer."),
    HumanMessage("Summarise retrieval augmented generation."),
]
response = model.invoke(messages)

Prompt templates

Templates separate the stable instruction from the variable input, which keeps prompts reviewable and testable like any other code.

Composition

Because every piece shares one interface, the pipe operator builds a larger runnable out of smaller ones. The composed object is itself a runnable, so it can be nested, batched and streamed without special handling.