@@ -443,7 +443,7 @@ class ChunkProcessingTestCase:
443443                id = "tool_123" ,
444444                name = "empty_function" ,
445445            ),
446-             llm .ToolCallEndChunk (),
446+             llm .ToolCallEndChunk (id = "tool_123" ),
447447        ],
448448        expected_contents = [
449449            [],
@@ -456,9 +456,11 @@ class ChunkProcessingTestCase:
456456                id = "tool_456" ,
457457                name = "test_function" ,
458458            ),
459-             llm .ToolCallChunk (type = "tool_call_chunk" , delta = '{"key": ' ),
460-             llm .ToolCallChunk (type = "tool_call_chunk" , delta = '"value"}' ),
461-             llm .ToolCallEndChunk (type = "tool_call_end_chunk" , content_type = "tool_call" ),
459+             llm .ToolCallChunk (id = "tool_456" , type = "tool_call_chunk" , delta = '{"key": ' ),
460+             llm .ToolCallChunk (id = "tool_456" , type = "tool_call_chunk" , delta = '"value"}' ),
461+             llm .ToolCallEndChunk (
462+                 id = "tool_456" , type = "tool_call_end_chunk" , content_type = "tool_call" 
463+             ),
462464        ],
463465        expected_contents = [
464466            [],
@@ -703,12 +705,12 @@ class InvalidChunkSequenceTestCase:
703705        expected_error = "Received thought_end_chunk while not processing thought" ,
704706    ),
705707    "tool_call_chunk_without_start" : InvalidChunkSequenceTestCase (
706-         chunks = [llm .ToolCallChunk (delta = '{"test": "value"}' )],
707-         expected_error = "Received tool_call_chunk while not processing  tool call" ,
708+         chunks = [llm .ToolCallChunk (id = "unknown_id" ,  delta = '{"test": "value"}' )],
709+         expected_error = "Received tool_call_chunk for unknown  tool call id " ,
708710    ),
709711    "tool_call_end_without_start" : InvalidChunkSequenceTestCase (
710-         chunks = [llm .ToolCallEndChunk ()],
711-         expected_error = "Received tool_call_end_chunk while not processing  tool call" ,
712+         chunks = [llm .ToolCallEndChunk (id = "unknown_id" )],
713+         expected_error = "Received tool_call_end_chunk for unknown  tool call id " ,
712714    ),
713715    "overlapping_text_then_tool_call" : InvalidChunkSequenceTestCase (
714716        chunks = [
@@ -734,9 +736,11 @@ class InvalidChunkSequenceTestCase:
734736        chunks = [
735737            llm .TextStartChunk (type = "text_start_chunk" ),
736738            llm .TextChunk (type = "text_chunk" , delta = "test" ),
737-             llm .ToolCallEndChunk (type = "tool_call_end_chunk" , content_type = "tool_call" ),
739+             llm .ToolCallEndChunk (
740+                 id = "unknown_id" , type = "tool_call_end_chunk" , content_type = "tool_call" 
741+             ),
738742        ],
739-         expected_error = "Received tool_call_end_chunk while not processing  tool call" ,
743+         expected_error = "Received tool_call_end_chunk for unknown  tool call id " ,
740744    ),
741745}
742746
@@ -1102,9 +1106,9 @@ def example_format_tool_chunks() -> list[llm.StreamResponseChunk]:
11021106            id = "call_format_123" ,
11031107            name = FORMAT_TOOL_NAME ,
11041108        ),
1105-         llm .ToolCallChunk (delta = '{"title": "The Hobbit"' ),
1106-         llm .ToolCallChunk (delta = ', "author": "Tolkien"}' ),
1107-         llm .ToolCallEndChunk (),
1109+         llm .ToolCallChunk (id = "call_format_123" ,  delta = '{"title": "The Hobbit"' ),
1110+         llm .ToolCallChunk (id = "call_format_123" ,  delta = ', "author": "Tolkien"}' ),
1111+         llm .ToolCallEndChunk (id = "call_format_123" ),
11081112    ]
11091113
11101114
@@ -1122,15 +1126,15 @@ def example_format_tool_chunks_processed() -> list[llm.AssistantContentChunk]:
11221126def  example_format_tool_chunks_mixed () ->  list [llm .StreamResponseChunk ]:
11231127    return  [
11241128        llm .ToolCallStartChunk (id = "call_007" , name = "ring_tool" ),
1125-         llm .ToolCallChunk (delta = '{"ring_purpose": "to_rule_them_all"}' ),
1126-         llm .ToolCallEndChunk (),
1129+         llm .ToolCallChunk (id = "call_007" ,  delta = '{"ring_purpose": "to_rule_them_all"}' ),
1130+         llm .ToolCallEndChunk (id = "call_007" ),
11271131        llm .ToolCallStartChunk (
11281132            id = "call_format_123" ,
11291133            name = FORMAT_TOOL_NAME ,
11301134        ),
1131-         llm .ToolCallChunk (delta = '{"title": "The Hobbit"' ),
1132-         llm .ToolCallChunk (delta = ', "author": "Tolkien"}' ),
1133-         llm .ToolCallEndChunk (),
1135+         llm .ToolCallChunk (id = "call_format_123" ,  delta = '{"title": "The Hobbit"' ),
1136+         llm .ToolCallChunk (id = "call_format_123" ,  delta = ', "author": "Tolkien"}' ),
1137+         llm .ToolCallEndChunk (id = "call_format_123" ),
11341138        llm .TextStartChunk (),
11351139        llm .TextChunk (delta = "A wizard is never late." ),
11361140        llm .TextEndChunk (),
@@ -1141,8 +1145,8 @@ def example_format_tool_chunks_mixed() -> list[llm.StreamResponseChunk]:
11411145def  example_format_tool_chunks_mixed_processed () ->  list [llm .AssistantContentChunk ]:
11421146    return  [
11431147        llm .ToolCallStartChunk (id = "call_007" , name = "ring_tool" ),
1144-         llm .ToolCallChunk (delta = '{"ring_purpose": "to_rule_them_all"}' ),
1145-         llm .ToolCallEndChunk (),
1148+         llm .ToolCallChunk (id = "call_007" ,  delta = '{"ring_purpose": "to_rule_them_all"}' ),
1149+         llm .ToolCallEndChunk (id = "call_007" ),
11461150        llm .TextStartChunk (),
11471151        llm .TextChunk (delta = '{"title": "The Hobbit"' ),
11481152        llm .TextChunk (delta = ', "author": "Tolkien"}' ),
@@ -1160,7 +1164,7 @@ def example_format_tool_chunks_max_tokens() -> list[llm.StreamResponseChunk]:
11601164            id = "call_format_123" ,
11611165            name = FORMAT_TOOL_NAME ,
11621166        ),
1163-         llm .ToolCallEndChunk (),
1167+         llm .ToolCallEndChunk (id = "call_format_123" ),
11641168        llm .responses .FinishReasonChunk (finish_reason = llm .FinishReason .MAX_TOKENS ),
11651169    ]
11661170
@@ -1314,11 +1318,11 @@ def tool_two(y: str) -> str:
13141318
13151319    tool_call_chunks  =  [
13161320        llm .ToolCallStartChunk (id = "call_1" , name = "tool_one" ),
1317-         llm .ToolCallChunk (delta = '{"x": 5}' ),
1318-         llm .ToolCallEndChunk (),
1321+         llm .ToolCallChunk (id = "call_1" ,  delta = '{"x": 5}' ),
1322+         llm .ToolCallEndChunk (id = "call_1" ),
13191323        llm .ToolCallStartChunk (id = "call_2" , name = "tool_two" ),
1320-         llm .ToolCallChunk (delta = '{"y": "hello"}' ),
1321-         llm .ToolCallEndChunk (),
1324+         llm .ToolCallChunk (id = "call_2" ,  delta = '{"y": "hello"}' ),
1325+         llm .ToolCallEndChunk (id = "call_2" ),
13221326    ]
13231327
13241328    stream_response  =  llm .StreamResponse (
@@ -1352,11 +1356,11 @@ async def tool_two(y: str) -> str:
13521356
13531357    tool_call_chunks  =  [
13541358        llm .ToolCallStartChunk (id = "call_1" , name = "tool_one" ),
1355-         llm .ToolCallChunk (delta = '{"x": 5}' ),
1356-         llm .ToolCallEndChunk (),
1359+         llm .ToolCallChunk (id = "call_1" ,  delta = '{"x": 5}' ),
1360+         llm .ToolCallEndChunk (id = "call_1" ),
13571361        llm .ToolCallStartChunk (id = "call_2" , name = "tool_two" ),
1358-         llm .ToolCallChunk (delta = '{"y": "hello"}' ),
1359-         llm .ToolCallEndChunk (),
1362+         llm .ToolCallChunk (id = "call_2" ,  delta = '{"y": "hello"}' ),
1363+         llm .ToolCallEndChunk (id = "call_2" ),
13601364    ]
13611365
13621366    async  def  async_chunk_iter () ->  AsyncIterator [llm .AssistantContentChunk ]:
0 commit comments