Skip to content

Conversation

@davidkna-sap
Copy link
Member

@davidkna-sap davidkna-sap commented Nov 11, 2025

Context

Closes SAP/ai-sdk-js-backlog#344.

What this PR does and why it is needed

This PR adds basic support for passing streaming: true to the constructors and saving it as an attribute. Results are collected via .concat(). In addition this PR updates the unit tests, sample code and e2e tests.

@davidkna-sap davidkna-sap force-pushed the davidkna-sap_lc-auto-stream branch from b556127 to 3b40abe Compare November 11, 2025 09:57
Comment on lines 60 to 62
// Todo: Extend BaseChatModelParams?
this.streaming =
(langchainOptions as { streaming?: boolean })?.streaming ?? false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The streaming-option is supported here, but I felt like extending or replacing BaseChatModelParams might be considered a breaking change which leads to any use needing to avoid type-checks.

finalOutput =
finalOutput !== undefined ? finalOutput.concat(chunk) : chunk;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A snapshot test directly on the final output is not possible here, because langgraph will add uuids to the response object, but other tests should already be verifying the general execution with auto-streaming enabled.

Base automatically changed from push-toqoormrvxpy to main November 25, 2025 10:27
@davidkna-sap davidkna-sap force-pushed the davidkna-sap_lc-auto-stream branch 2 times, most recently from df681d3 to 259f0da Compare December 2, 2025 10:25
@davidkna-sap davidkna-sap force-pushed the davidkna-sap_lc-auto-stream branch from 758eb8f to cf39b95 Compare December 18, 2025 14:16
@davidkna-sap davidkna-sap force-pushed the davidkna-sap_lc-auto-stream branch from cf39b95 to fd45bf3 Compare December 18, 2025 14:27
Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a first look at the openai client. Please check my comments and if needed adapt the changes also to the orchestration client.

@ZhongpinWang
Copy link
Contributor

@KavithaSiva Please also have a look at this PR since there are some behaviour changes about streaming and you might wanna know. 😀

Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. 👍 I added some more comments.

// - `streaming`: true enables auto-streaming in `invoke()` calls
// - `disableStreaming`: true overrides streaming flag
// - `streaming`: `false` causes `disableStreaming` to be set to `true` for framework compatibility
this.disableStreaming = fields.disableStreaming ?? this.disableStreaming;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[req] The difference between your implementation and https://github.com/langchain-ai/langchainjs/blob/cc502e1b67dbadcd123a7ea2964c791c2bbad581/libs/providers/langchain-openai/src/chat_models/base.ts#L479 is that openai always set the value to false if not strictly equal true. Your solution using ?? might be problematic if user writes plain JS and anything such as '', 0 other than undefined is assigned to the left.

Also your left can potentially be undefined if it was previously undefined. And later in line 82, if the if condition does not apply, this.disableStreaming will be undefined forever, which is different from the OpenAI behaviour. (Although https://github.com/langchain-ai/langchainjs/blob/cc502e1b67dbadcd123a7ea2964c791c2bbad581/libs/langchain-core/src/language_models/chat_models.ts#L220 here it is set to false by default by LangChain, so not a real issue but hope you see my point about yours and OpenAI's implementation technically being different. Be careful about ?? in TS and I personally find bar = foo === true a smart way for making sure bar will either be true or false and also excluding all other truthy values).

Copy link
Member Author

@davidkna-sap davidkna-sap Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced all ?? instances in the relevant code with boolean equality checks.

Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestions

Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing this nice feature. Let's merge it!

Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh before we merge, can you add a changeset for the changes?

@davidkna-sap
Copy link
Member Author

I've added two changesets. A previous changeset was lost during squashing/rebasing, but I've expanded it to match the extended scope of the PR.

@davidkna-sap davidkna-sap force-pushed the davidkna-sap_lc-auto-stream branch from 23d4db5 to aa167c5 Compare January 5, 2026 13:35
Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@ZhongpinWang ZhongpinWang merged commit b91e0a7 into main Jan 5, 2026
14 checks passed
@ZhongpinWang ZhongpinWang deleted the davidkna-sap_lc-auto-stream branch January 5, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants