From 62fb62f981acd6be0dbe1ae60ae738101a78d749 Mon Sep 17 00:00:00 2001 From: cfdaily Date: Tue, 26 May 2026 23:28:23 +0800 Subject: [PATCH] auto-sync: 2026-05-26 23:28:23 --- docs/research/distill-scan-pangtong.py | 49 +++++++++++++++----------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/docs/research/distill-scan-pangtong.py b/docs/research/distill-scan-pangtong.py index 3eb5bbb..f1cca21 100644 --- a/docs/research/distill-scan-pangtong.py +++ b/docs/research/distill-scan-pangtong.py @@ -75,29 +75,36 @@ def extract_text_from_content(content) -> str: return ' '.join(parts) -def extract_tool_info(content) -> tuple: - """Extract tool names and whether there are tool_results with errors.""" - if not isinstance(content, list): - return [], False +def extract_tool_info(role: str, content) -> tuple: + """Extract tool names and whether there are tool_results with errors. + + v3 format: toolCall blocks in assistant messages, toolResult as separate role. + """ tool_uses = [] has_error = False - for block in content: - if not isinstance(block, dict): - continue - btype = block.get('type', '') - if btype == 'tool_use': - tool_uses.append(block.get('name', '')) - elif btype == 'tool_result': - result_text = '' - rc = block.get('content', '') - if isinstance(rc, str): - result_text = rc - elif isinstance(rc, list): - for sub in rc: - if isinstance(sub, dict) and sub.get('type') == 'text': - result_text += sub.get('text', '') - if any(e in result_text for e in ERROR_INDICATORS): - has_error = True + + # Extract tool calls from assistant messages + if isinstance(content, list): + for block in content: + if not isinstance(block, dict): + continue + btype = block.get('type', '') + # v3 uses 'toolCall', some formats use 'tool_use' + if btype in ('toolCall', 'tool_use'): + tool_uses.append(block.get('name', '')) + + # Check for errors in toolResult role messages + if role == 'toolResult': + result_text = '' + if isinstance(content, str): + result_text = content + elif isinstance(content, list): + for sub in content: + if isinstance(sub, dict) and sub.get('type') == 'text': + result_text += sub.get('text', '') + if any(e in result_text for e in ERROR_INDICATORS): + has_error = True + return tool_uses, has_error