cloudwego / cloudwego/eino

react: streaming tool-call detection fails when model emits text before tool-call chunks

Open
#892 2 comments 0 reactions 0 assignees View on GitHub
C-bug D-adk
Dominant language
Go
Stars
13k
Forks
1.1k
Avg merge
4h 6m
Merged PRs (30d)
41

Description

**Describe the bug**

In streaming mode, the default `StreamToolCallChecker` (`firstChunkStreamToolCallChecker`) decides whether an assistant turn contains tool calls by inspecting only the **first non-empty chunk**. If that chunk contains text content, the checker immediately returns `false` — even if subsequent chunks in the same turn contain tool calls.

This breaks models (e.g. Claude) that routinely emit thinking/text content before tool-call chunks within a single streamed turn. The agent incorrectly treats the turn as a final text response and stops, never executing the tools.

**To Reproduce**

1. Use a `ToolCallingChatModel` that streams text before tool calls in the same turn, e.g.:
- Chunk 1: `{Role: Assistant, Content: "thinking "}`
- Chunk 2: `{Role: Assistant, ToolCalls: [{ID: "1", Function: {Name: "greet", Arguments: "..."}}]}`
2. Create a react agent with default config (no custom `StreamToolCallChecker`)
3. Call `agent.Stream(...)` — the agent treats the turn as a non-tool-call response and stops without executing tools

**Expected behavior**

The default checker should detect tool calls regardless of whether text content precedes them in the stream.

**Version:**

latest main

**Additional context**

The current workaround is to provide a custom `StreamToolCallChecker` in `AgentConfig` that drains the full stream before deciding.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.