From e86b7eacdde10d2b8659e6e71b528a3bc8fdfacd Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 8 Aug 2026 07:02:22 +0000 Subject: [PATCH] =?UTF-8?q?refactor(tool=5Fparser):=20CCCL=20agent=5Fradix?= =?UTF-8?q?=5Fsort=5Fdownsweep=20union=20TempStorage=20=E2=80=94=20phased?= =?UTF-8?q?=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Applies CCCL cub/agent/agent_radix_sort_downsweep.cuh design: - union TempStorage reuses same shared memory across load/rank/scatter phases - Translated: streaming parse state organized into 4 phases (DETECT/HEADER/PARAMS/CLOSE) matching the tool call parse lifecycle - Clear documentation of which state belongs to which parse phase - Reset clears all phases at once like union initialization on new tile --- qwen3_6_scripts/qwen3coder_tool_parser.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/qwen3_6_scripts/qwen3coder_tool_parser.py b/qwen3_6_scripts/qwen3coder_tool_parser.py index f1c71ad9..e1a14181 100644 --- a/qwen3_6_scripts/qwen3coder_tool_parser.py +++ b/qwen3_6_scripts/qwen3coder_tool_parser.py @@ -104,21 +104,33 @@ class Qwen3CoderToolParser(ToolParser): return f"call_{uuid.uuid4().hex[:24]}" def _reset_streaming_state(self) -> None: + """CCCL agent_radix_sort_downsweep union TempStorage pattern: + Streaming parse state is organized in phases like CUDA shared memory + that gets reused across load/rank/scatter phases. Each tool call + transitions through phases: DETECT → HEADER → PARAMS → CLOSE. + Reset all phase state at once (like clearing the union on new tile).""" + # Phase: DETECT (looking for ) self.current_tool_index = 0 self.is_tool_call_started = False + self.accumulated_text: str = "" + self.streaming_request: Optional[ChatCompletionRequest] = None + + # Phase: HEADER (parsing ) self.header_sent = False self.current_tool_id = None self.current_function_name: Optional[str] = None + + # Phase: PARAMS (parsing value) self.current_param_name: Optional[str] = None self.current_param_value: str = "" self.param_count = 0 self.in_param = False self.in_function = False - self.accumulated_text: str = "" + self.accumulated_params: Dict[str, Any] = {} + + # Phase: CLOSE (emitting JSON and transitioning to next tool) self.json_started = False self.json_closed = False - self.accumulated_params: Dict[str, Any] = {} - self.streaming_request: Optional[ChatCompletionRequest] = None def _get_arguments_config( self, func_name: str,