AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

`Disable_streaming="Tool_calling"` Crashes In Streaming Mode

When `streaming=True` and `disable_streaming="tool_calling"`, non-streaming calls still send `stream=True`, causing `_create_chat_result` to receive an `AsyncStream` and crash with `AttributeError`. Additionally, `_should_stream` disables streaming for all turns whenever tools are bound, contrary to the option's intent.

highConfidence 75%Langchain-CoreRetrieversMemoryAffected Vlangchain-Core 1.2.15Affected Vlangchain-Openai 1.1.10

Origin Analysis

Two distinct bugs: (1) In langchain-openai, `BaseChatOpenAI._default_params` hardcodes `"stream": self.streaming`, so when `_should_stream` disables streaming for tool calling, the subsequent non-streaming `_agenerate` still includes `stream=True` in the request payload, returning an `AsyncStream` that `_create_chat_result` cannot parse. (2) In langchain-core, `BaseChatModel._should_stream` checks only `kwargs.get("tools")`, which is true whenever tools are bound (e.g., in agents), so it disables streaming for all turns, including final text responses, instead of only when tool calling is expected.
1. Instantiate `ChatOpenAI` with `streaming=True` and `disable_streaming="tool_calling"`.\n2. Bind a tool (e.g., `get_weather`) and create a React agent using `create_react_agent`.\n3. Call `agent.astream_events` with a user message.\n4. Observe `AttributeError: 'AsyncStream' object has no attribute 'model_dump'`.

Fixing Code Block

Edge Case Audit

The `_should_stream` fix relies on the `tool_choice` parameter and may still stream when `tool_choice` is `auto` and the model spontaneously decides to call a tool, potentially reintroducing the malformed tool-call chunk issue. If this is unacceptable, a more robust solution would require buffering or post-processing of streamed chunks. Additionally, removing `stream` from `_default_params` requires that every streaming entrypoint explicitly sets `stream=True`; missing one could break streaming. Rollback recommendation: revert both changes; no data migration needed.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state