LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Llms
  • Profile
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Tools
  • Base
  • Console
  • Log Stream
  • Run Collector
  • Tracer Langchain
  • Stream
  • Async Caller
  • Chunk Array
  • Context
  • Env
  • Event Source Parse
  • Format
  • Function Calling
  • Hash
  • Json Patch
  • Json Schema
  • Math
  • Ssrf
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangChain
UniversalHubNodeLoadSerializableEncoder BackedFile SystemIn Memory
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsLlmsProfileLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingHashJson PatchJson SchemaMathSsrfStreamTestingTiktokenTypesVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScript@langchain/corerunnables
Module●Since v1.0

runnables

Copy
import { ... } from "@langchain/core/runnables";

Functions

function
_coerceToRunnable→ Runnable<RunInput, Exclude<RunOutput, Error>, CallOptions>
function
ensureConfig→ CallOptions

Ensure that a passed config is an object with all required keys present.

function
getCallbackManagerForConfig→ Promise<CallbackManager | undefined>
function
mergeConfigs→ Partial<CallOptions>
function
patchConfig→ Partial<CallOptions>

Helper function that patches runnable configs with updated properties.

function
pickRunnableConfigKeys→ Partial<RunnableConfig<Record<string, any>>> | undefined
function
raceWithSignal→ Promise<T>

Race a promise with an abort signal. If the signal is aborted, the promise will be rejected with the error from the signal. If the promise is rejected, the signal will be aborted.

Classes

class
RouterRunnable

A runnable that routes to a set of runnables based on Input['key']. Returns the output of the selected runnable.

class
Runnable

A Runnable is a generic unit of work that can be invoked, batched, streamed, and/or transformed.

class
RunnableAssign

A runnable that assigns key-value pairs to inputs of type Record<string, unknown>.

class
RunnableBinding

Wraps a runnable and applies partial config upon invocation.

class
RunnableBranch

Class that represents a runnable branch. The RunnableBranch is initialized with an array of branches and a default branch. When invoked, it evaluates the condition of each branch in order and executes the corresponding branch if the condition is true. If none of the conditions are true, it executes the default branch.

class
RunnableEach

A runnable that delegates calls to another runnable with each element of the input sequence.

class
RunnableLambda

A runnable that wraps an arbitrary function that takes a single argument.

class
RunnableMap

A runnable that runs a mapping of runnables in parallel, and returns a mapping of their outputs.

class
RunnableParallel

A runnable that runs a mapping of runnables in parallel, and returns a mapping of their outputs.

class
RunnablePassthrough

A runnable to passthrough inputs unchanged or with additional keys.

This runnable behaves almost like the identity function, except that it can be configured to add additional keys to the output, if the input is an object.

The example below demonstrates how to use RunnablePassthrough to passthrough the input from the .invoke()`

class
RunnablePick

A runnable that assigns key-value pairs to inputs of type Record<string, unknown>. Useful for streaming, can be automatically created and chained by calling runnable.pick();.

class
RunnableRetry

Base class for runnables that can be retried a specified number of times.

class
RunnableSequence

A sequence of runnables, where the output of each is the input of the next.

class
RunnableToolLike

Wraps a runnable and applies partial config upon invocation.

class
RunnableWithFallbacks

A Runnable that can fallback to other Runnables if it fails. External APIs (e.g., APIs for a language model) may at times experience degraded performance or even downtime.

In these cases, it can be useful to have a fallback Runnable that can be used in place of the original Runnable (e.g., fallback to another LLM provider).

Fallbacks can be defined at the level of a single Runnable, or at the level of a chain of Runnables. Fallbacks are tried in order until one succeeds or all fail.

While you can instantiate a RunnableWithFallbacks directly, it is usually more convenient to use the withFallbacks method on an existing Runnable.

When streaming, fallbacks will only be called on failures during the initial stream creation. Errors that occur after a stream starts will not fallback to the next Runnable.

class
RunnableWithMessageHistory

Wraps a LCEL chain and manages history. It appends input messages and chain outputs as history, and adds the current history messages to the chain input.

Interfaces

interface
RunnableConfig
interface
RunnableInterface

Base interface implemented by all runnables. Used for cross-compatibility between different versions of LangChain core.

Should not change on patch releases.

interface
RunnableToolLikeArgs
interface
RunnableWithMessageHistoryInputs

Type Aliases

typeAlias
Branch: [Runnable<RunInput, boolean>, Runnable<RunInput, RunOutput>]

Type for a branch in the RunnableBranch. It consists of a condition runnable and a branch runnable. The condition runnable is used to determine whether the branch should be executed, and the branch runnable is executed if the condition is true.

typeAlias
BranchLike: [RunnableLike<RunInput, boolean>, RunnableLike<RunInput, RunOutput>]
typeAlias
RouterInput
typeAlias
RunnableBatchOptions
typeAlias
RunnableBindingArgs
typeAlias
RunnableFunc: (input: RunInput, options: CallOptions | Record<string, any> | Record<string, any> & CallOptions)
typeAlias
RunnableIOSchema
typeAlias
RunnableLike: RunnableInterface<RunInput, RunOutput, CallOptions> | RunnableFunc<RunInput, RunOutput, CallOptions> | RunnableMapLike<RunInput, RunOutput>
typeAlias
RunnableRetryFailedAttemptHandler: (error: any, input: any)
View source on GitHub