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

Tool-Call Continuation Deltas Can Overwrite Valid Id/Name With Empty Strings

When merging streamed tool-call chunks, an empty-string id or name in a continuation delta replaces the previously accumulated valid id/name, causing tool-call metadata to become malformed and downstream handling to fail.

highConfidence 85%LangchainAffected V1.5.3

Origin Analysis

The merge logic for ToolCallChunk in langchain-core treats an empty string ('') as a valid value and applies it over the existing value, either by direct assignment or by only checking for None. This violates the expectation that empty fields in deltas should be ignored.
```python from langchain_core.messages import AIMessageChunk, ToolCallChunk first = AIMessageChunk(content='', tool_call_chunks=[ToolCallChunk(name='get_weather', args='', id='call_123', index=0)]) cont = AIMessageChunk(content='', tool_call_chunks=[ToolCallChunk(name='', args='{"city":"SF"}', id='', index=0)]) merged = first + cont print(merged.tool_call_chunks[0].name, merged.tool_call_chunks[0].id) # Expected: get_weather call_123 # Actual: empty strings ```

Fixing Code Block

Edge Case Audit

The change alters merge semantics for empty strings: if any downstream code intentionally sends an empty string to clear a previously set id/name, that clearing will now be ignored. Rollback is straightforward by reverting to the previous merge logic. Test with stream providers that emit empty strings for id/name in continuation deltas to confirm the fix does not break other fields.

Ecosystem Topology