LangChain & LangGraph for AI Agents
Back to Agent Foundations & LCEL Composition

Building Reactive Chains with LCEL

The pipe-based composition pattern. Once you see it, every LangChain example becomes readable. FIND_VIDEO: search 'LCEL LangChain Expression Language tutorial' — recommended channel: LangChain / Sam Witteveen. Aim for 10 min or under.

22 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.
Loading progress...

Key moments

  1. Basic LCEL Chain Construction — Chains prompt templates, chat models, and output parsers sequentially using LCEL pipe syntax.
  2. The Runnable Interface — Demonstrates sequential intermediate data flow across HumanMessage, AIMessage, and string formats.
  3. Custom Engine via Operator Overloading — Builds a custom runnable sequence engine by overriding Python's bitwise OR dunder method.
  4. Testing Custom Runnables — Subclasses custom runnables to execute arithmetic operations inside a custom pipe sequence.
  5. Identity Mapping with Passthrough — Implements RunnablePassthrough to transmit raw inputs unchanged to downstream chain components.
  6. Wrapping Functions with RunnableLambda — Converts plain Python functions into LCEL-compatible runnables exposing an invoke method.
  7. Multi-Branch RunnableParallel — Creates dictionary-based branching pipelines to transform identical input payloads concurrently.
PDF notes

Frequently asked questions

Why does the pipe operator work between LangChain objects?

LangChain overrides Python's __or__ dunder method on Runnable objects to return a RunnableSequence instance instead of evaluating a bitwise operation.

Can I use standard Python functions directly in an LCEL chain?

No, standard Python functions lack the invoke method and Runnable interface, requiring them to be wrapped inside RunnableLambda.

When should I use RunnablePassthrough?

Use RunnablePassthrough when downstream components or prompt templates need access to the original, untransformed input payload alongside processed outputs.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.