@@ -1197,65 +1197,3 @@ def test_convert_to_openai_image_block() -> None:
1197
1197
}
1198
1198
result = convert_to_openai_image_block (input_block )
1199
1199
assert result == expected
1200
-
1201
-
1202
- def test_tool_call_streaming_different_indices () -> None :
1203
- """Test that tool call chunks with different indices but logically part of the same
1204
- tool call are merged correctly. This addresses issues with models like Qwen3 that
1205
- send inconsistent indices during streaming.
1206
-
1207
- See #31511.
1208
-
1209
- """ # noqa: D205
1210
- # Create chunks that simulate Qwen3 behavior:
1211
- # First chunk has index=1, subsequent chunks have index=0 with name=None, id=None
1212
- chunk1 = AIMessageChunk (
1213
- content = "" ,
1214
- tool_call_chunks = [
1215
- create_tool_call_chunk (
1216
- name = "search_function" ,
1217
- args = '{"query": "langchain' ,
1218
- id = "call_123" ,
1219
- index = 1 , # Initial index
1220
- )
1221
- ],
1222
- )
1223
-
1224
- chunk2 = AIMessageChunk (
1225
- content = "" ,
1226
- tool_call_chunks = [
1227
- create_tool_call_chunk (
1228
- name = None , # Continuation chunk
1229
- args = ' tutorial"}' ,
1230
- id = None , # Continuation chunk
1231
- index = 0 , # Different index
1232
- )
1233
- ],
1234
- )
1235
-
1236
- # Merge chunks as happens during streaming
1237
- merged_chunk : AIMessageChunk = chunk1 + chunk2 # type: ignore[assignment]
1238
-
1239
- # Should result in a single merged tool call chunk
1240
- assert len (merged_chunk .tool_call_chunks ) == 1
1241
- assert merged_chunk .tool_call_chunks [0 ]["name" ] == "search_function"
1242
- assert merged_chunk .tool_call_chunks [0 ]["args" ] == '{"query": "langchain tutorial"}'
1243
- assert merged_chunk .tool_call_chunks [0 ]["id" ] == "call_123"
1244
-
1245
- # Should result in a single valid tool call
1246
- assert len (merged_chunk .tool_calls ) == 1
1247
- assert len (merged_chunk .invalid_tool_calls ) == 0
1248
-
1249
- # Verify the final tool call is correct
1250
- tool_call = merged_chunk .tool_calls [0 ]
1251
- assert tool_call ["name" ] == "search_function"
1252
- assert tool_call ["args" ] == {"query" : "langchain tutorial" }
1253
- assert tool_call ["id" ] == "call_123"
1254
-
1255
- # Test with message_chunk_to_message
1256
- message : AIMessage = message_chunk_to_message (merged_chunk ) # type: ignore[assignment]
1257
-
1258
- assert len (message .tool_calls ) == 1
1259
- assert len (message .invalid_tool_calls ) == 0
1260
- assert message .tool_calls [0 ]["name" ] == "search_function"
1261
- assert message .tool_calls [0 ]["args" ] == {"query" : "langchain tutorial" }
0 commit comments