refactor(tool_parser): CCCL agent_radix_sort_downsweep union TempStorage — phased state

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
This commit is contained in:
Claude
2026-08-08 07:02:22 +00:00
parent 5a3831e977
commit e86b7eacdd

View File

@@ -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 <tool_call>)
self.current_tool_index = 0
self.is_tool_call_started = False
self.accumulated_text: str = ""
self.streaming_request: Optional[ChatCompletionRequest] = None
# Phase: HEADER (parsing <function=name>)
self.header_sent = False
self.current_tool_id = None
self.current_function_name: Optional[str] = None
# Phase: PARAMS (parsing <parameter=key>value</parameter>)
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,