-- GEPA negative-sample feedback loop: avoid-pattern synthesis + mutate skill guardrails
-- Run after lobster_engine_prompt_init.sql; tenant DB (lobster_system_prompt)

INSERT IGNORE INTO lobster_system_prompt (
  prompt_key, prompt_name, prompt_category, prompt_content,
  model_name, system_role, company_id, industry_type, enabled, sort_order, create_by
) VALUES (
  'gepa_synthesize_avoid',
  'GEPA负样本反例提炼',
  'evolution',
  '节点 [{nodeCode}] 的低质量对话样本（需避免重蹈覆辙）：\n{negativeBlock}\n\n请提炼 3~5 条「禁止做法 / 反例要点」，供后续 Skill 变异时规避。\n只输出 JSON：{"avoidances":["...","..."]}',
  NULL,
  NULL,
  NULL, NULL, 1, 42, 'system'
);

UPDATE lobster_system_prompt SET
  prompt_content = CONCAT(
    '你正在优化节点 [{nodeCode}] 的销售对话 Skill。\n',
    '高质量样本：\n{samplesBlock}\n\n',
    '{avoidBlock}',
    '请变异生成 1 个改进版 Skill：步骤简洁 + 2~3 条可复用回复模板。\n',
    '必须规避上述低质量反例中的问题。\n',
    '只输出 JSON：{"title":"...","content":"..."}'
  )
WHERE prompt_key = 'gepa_mutate_skill'
  AND company_id IS NULL
  AND prompt_content NOT LIKE '%{avoidBlock}%';
