fix(deepseekv3): Fix DeepSeekV3Detector tool_index assignment and multi-tool call streaming support#6655
fix(deepseekv3): Fix DeepSeekV3Detector tool_index assignment and multi-tool call streaming support#6655
Conversation
…ti-tool call streaming support - Fix tool_index to use call sequence position instead of tool array position - Add support for detecting subsequent tool calls without bot_token prefix - Implement smart buffer management to preserve multiple tool calls - Maintain adapter.py integration state arrays for streaming compatibility This resolves issues where: 1. Tool calls were assigned incorrect indices based on tool definition order 2. Second and subsequent tool calls were treated as normal text 3. Buffer was cleared completely, losing subsequent tool call data
|
/gemini summary |
Summary of ChangesHello! Gemini here, providing a summary of this pull request. This PR focuses on addressing two key issues within the Highlights
Changelog
Activity
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request effectively addresses two key issues in DeepSeekV3Detector: the incorrect tool_index assignment and the lack of support for parsing multiple tool calls in a streaming fashion. The introduction of current_tool_id for sequential indexing and the refined buffer management to preserve subsequent tool calls are significant improvements. The changes to handle subsequent tool calls without the bot_token prefix also look good. Overall, these modifications enhance the robustness and correctness of tool call parsing for DeepSeekV3.
I have one point for clarification regarding buffer clearing in a specific edge case, detailed below.
Summary of Findings
- Tool Index Correction: The PR successfully corrects the
tool_indexassignment by using a sequentialcurrent_tool_idincremented for each tool call, rather than relying on the tool definition order. This aligns with the expected behavior. - Multi-Tool Call Streaming Support: The changes significantly improve support for streaming multiple tool calls. Detecting subsequent tool calls via
<|tool call begin|>and the smart buffer management (self._buffer = current_text[match.end() :]) are key to this. - Buffer Clearing Edge Case: There's a potential edge case in buffer management: if a tool call's JSON arguments are complete but its final end-tag (
<|tool call end|>) is missing from the buffer, the entire buffer is cleared. This might lead to loss of subsequent tool call data if the stream is malformed or tokens arrive in a specific order. This was noted as a review comment. - State Management for Adapter: The state arrays
prev_tool_call_arrandstreamed_args_for_toolare now correctly managed for multiple tool calls, ensuring compatibility withadapter.py.
Merge Readiness
The pull request makes substantial improvements to DeepSeekV3 tool call detection. However, there's one medium-severity concern regarding buffer clearing in an edge case (detailed in the review comment) that could potentially lead to data loss for subsequent tool calls under specific circumstances. It would be beneficial to clarify or address this point before merging. I am unable to approve pull requests, so please ensure further review and approval from authorized maintainers after addressing any feedback.
…ti-tool call streaming support (sgl-project#6655)
…ti-tool call streaming support (sgl-project#6655)
…e function call @20250708-1524 \n associate with this pr. sgl-project#6655
…e function call @20250708-1524 \n associate with this pr. sgl-project#6655 in this version: 0.4.6.post1
…le function call @20250708-1524 \n associate with this pr. sgl-project#6655 in this version: 0.4.6.post1


Motivation
This PR focuses to fix the current two issues in
DeepSeekV3Detector.requiredand specific function mode #6550 (comment)The correct behavior should be the index of the current tool call in the response tool_calls list.
Modifications
This resolves issues where:
Checklist