Skip to content

Conversation

ccurme
Copy link
Collaborator

@ccurme ccurme commented Oct 8, 2025

Currently the presence of a streaming callback handler enables streaming, even when a chat model has a streaming attribute that is explicitly set to False:

llm = MyChatModel(streaming=False)

await model.ainvoke(..., config={"callbacks": [_AstreamEventsCallbackHandler()]})  # streams

The streaming attribute is not on BaseChatModel but it is on most major chat models, including OpenAI, Anthropic, and Google GenAI. Its intended purpose is to enable streaming under the hood when calling .invoke.

OpenAI and Anthropic implement streaming as a boolean attribute with no sentinel value, so here we disable streaming if that attribute is explicitly set to False.

N.B. BaseChatModel does implement disable_streaming for the complementary case, and this currently works:

llm = MyChatModel(disable_streaming=True)

await model.ainvoke(..., config={"callbacks": [_AstreamEventsCallbackHandler()]})  # does not stream

but the behavior with streaming is unintuitive, so we update it here.

Ideally we would have a single bool | None = None attribute instead of these two booleans.

@ccurme ccurme requested a review from eyurtsev as a code owner October 8, 2025 15:25
@github-actions github-actions bot added core Related to the package `langchain-core` fix labels Oct 8, 2025
Copy link

codspeed-hq bot commented Oct 8, 2025

CodSpeed Performance Report

Merging #33351 will not alter performance

Comparing cc/streaming_callback (cdebe2d) with master (4c38157)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched
⏩ 21 skipped1

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions github-actions bot added fix and removed fix labels Oct 8, 2025
@ccurme ccurme merged commit a3e4f4c into master Oct 9, 2025
74 checks passed
@ccurme ccurme deleted the cc/streaming_callback branch October 9, 2025 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Related to the package `langchain-core` fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant