diff --git a/docs/research/distill-scan-pangtong.py b/docs/research/distill-scan-pangtong.py index 25f67d9..3eb5bbb 100644 --- a/docs/research/distill-scan-pangtong.py +++ b/docs/research/distill-scan-pangtong.py @@ -363,6 +363,10 @@ def scan_trial_error(messages: list) -> list: def scan_success(messages: list) -> list: """Pattern ③: Complex task (5+ tool_use in a session) with no correction.""" + # Need at least 4 messages to be meaningful + if len(messages) < 4: + return [] + # First check if the session has any corrections has_correction = any( m.role == 'user' and match_signals(m.text, CORRECTION_SIGNALS) @@ -379,29 +383,27 @@ def scan_success(messages: list) -> list: if len(all_tools) < 5: return [] - # Find the richest assistant message (most tool_use) - best_msg = None - best_count = 0 - for m in messages: - if m.role == 'assistant' and len(m.tool_names) > best_count: - best_count = len(m.tool_names) - best_msg = m - - if not best_msg: + # Use the last assistant message as the completion point + last_asst = None + for m in reversed(messages): + if m.role == 'assistant': + last_asst = m + break + if not last_asst: return [] - ctx_before, ctx_after = get_context(messages, best_msg.idx) - tools = get_tools_in_context(messages, best_msg.idx) + ctx_before, ctx_after = get_context(messages, last_asst.idx) + tools = get_tools_in_context(messages, last_asst.idx) return [{ 'mode': 'success', - 'timestamp': best_msg.timestamp, - 'trigger_message': best_msg.raw_text_snippet, + 'timestamp': last_asst.timestamp, + 'trigger_message': last_asst.raw_text_snippet, 'trigger_role': 'assistant', 'context_before': ctx_before, 'context_after': ctx_after, 'tool_calls_in_context': tools, - 'summary': f"复杂任务成功完成,共使用 {len(all_tools)} 次 tool_call" + 'summary': f"复杂任务成功完成,共使用 {len(all_tools)} 次 tool_call,无用户纠正" }]