diff --git a/langchain-core/src/runnables/base.ts b/langchain-core/src/runnables/base.ts index 1cab402513ec..f6c6a387585d 100644 --- a/langchain-core/src/runnables/base.ts +++ b/langchain-core/src/runnables/base.ts @@ -1989,7 +1989,7 @@ export class RunnableSequence< otherOptions?.runName ); const steps = [this.first, ...this.middle, this.last]; - let concatSupported = true; + let concatSupported = options?.concatSupported ?? true; let finalOutput; async function* inputGenerator() { yield input; @@ -2029,6 +2029,8 @@ export class RunnableSequence< concatSupported = false; } } + } else { + finalOutput = chunk; } } } catch (e) { diff --git a/langchain-core/src/runnables/types.ts b/langchain-core/src/runnables/types.ts index f40d80ee3831..499c5d046f28 100644 --- a/langchain-core/src/runnables/types.ts +++ b/langchain-core/src/runnables/types.ts @@ -107,4 +107,9 @@ export interface RunnableConfig< * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal */ signal?: AbortSignal; + + /** + * Whether to concatenate the stream of outputs into a single output or not. + */ + concatSupported?: boolean; }