Source: langchain-core Runnable implementation (runnables/base.py)
The source code and docstrings of the Runnable base class that defines LCEL composition, batching, streaming, retry and fallback semantics.
Contents
- What: source code of the
langchain-corepackage, plus the API reference index for runnables - Publisher: LangChain (GitHub
langchain-ai/langchain,libs/core/langchain_core/runnables/base.py) - Date: master branch, read 2026-11-14
- Original: base.py on GitHub, Runnables API reference
Summary
Runnable is the single interface every LangChain component implements, and LCEL is operator overloading on it. Reading the source shows what the “free” features really are: default implementations that subclasses may or may not override.
Key claims
invokeis the only abstract method. Defaultainvokerunsinvokein an executor; defaultstreamyields the singleinvokeresult (no real token streaming unless overridden).- Default
batchrunsinvokeon a thread pool; defaultabatchuses asyncio gather bounded bymax_concurrency. Subclasses should override when the backend has native batching. a | bbuilds aRunnableSequence; a dict operand is coerced toRunnableParallel;.pipe()is equivalent.with_retrydefaults: retry on anyException, exponential jitter, 3 attempts.with_fallbackstries alternatives in order;exception_keycan pass the error into the fallback’s input.bind,with_config,with_listeners,assign,pick,map,with_typesreturn wrapper runnables.get_graph,input_schema/output_schemaexpose structure and Pydantic schemas.- Config (tags, metadata, callbacks,
max_concurrency) is copied to each child with the parent’s child callbacks, which is how tracing nests. astream_eventsdefaults toversion="v2";"v1"is deprecated;"v3"exists only on chat models and compiled graphs.