From 5b44886da009bed1304e22222e129378be5571f8 Mon Sep 17 00:00:00 2001 From: Vadym Barda Date: Wed, 30 Apr 2025 14:07:19 -0400 Subject: [PATCH] docs(agents): add disable_streaming (#4475) --- docs/docs/agents/models.md | 30 ++++++++++++++++++++++++++++++ docs/docs/agents/streaming.md | 6 ++++++ 2 files changed, 36 insertions(+) diff --git a/docs/docs/agents/models.md b/docs/docs/agents/models.md index 7c6e773c1..16b4de243 100644 --- a/docs/docs/agents/models.md +++ b/docs/docs/agents/models.md @@ -74,6 +74,36 @@ agent = create_react_agent( The example above uses `ChatAnthropic`, which is already supported by `init_chat_model`. This pattern is shown to illustrate how to manually instantiate a model not available through init_chat_model. +## Disable streaming + +To disable streaming of the individual LLM tokens, set `disable_streaming=True` when initializing the model: + +=== "`init_chat_model`" + + ```python + from langchain.chat_models import init_chat_model + + model = init_chat_model( + "anthropic:claude-3-7-sonnet-latest", + # highlight-next-line + disable_streaming=True + ) + ``` + +=== "`ChatModel`" + + ```python + from langchain_anthropic import ChatAnthropic + + model = ChatAnthropic( + model="claude-3-7-sonnet-latest", + # highlight-next-line + disable_streaming=True + ) + ``` + +Refer to the [API reference](https://python.langchain.com/api_reference/core/language_models/langchain_core.language_models.chat_models.BaseChatModel.html#langchain_core.language_models.chat_models.BaseChatModel.disable_streaming) for more information on `disable_streaming` + ## Adding model fallbacks You can add a fallback to a different model or a different LLM provider using `model.with_fallbacks([...])`: diff --git a/docs/docs/agents/streaming.md b/docs/docs/agents/streaming.md index 7dd3451d3..7c0b1265b 100644 --- a/docs/docs/agents/streaming.md +++ b/docs/docs/agents/streaming.md @@ -212,6 +212,12 @@ You can specify multiple streaming modes by passing stream mode as a list: `stre print("\n") ``` +## Disable streaming + +In some applications you might need to disable streaming of individual tokens for a given model. This is useful in [multi-agent](./multi-agent.md) systems to control which agents stream their output. + +See the [Models](./models.md#disable-streaming) guide to learn how to disable streaming. + ## Additional resources * [Streaming in LangGraph](https://langchain-ai.github.io/langgraph/how-tos/streaming)