safety-alignment-constitutional-ai 是什么?
Anthropic's method for training harmless AI through self-improvement. Two-phase approach - supervised learning with self-critique/revision, then RLAIF (RL from AI Feedback). Use for safety alignment, reducing harmful outputs without human labels. Powers Claude's safety system.
以上为来源原文,中文用途说明尚待整理。
怎么接入你的 Agent?
- 定位完整 Skill 目录
打开本项目来源,核对
SKILL.md及其引用的脚本和资料。 - 交给你正在用的 Agent
在下面选择客户端,展开并复制安装指令,让 Agent 读取来源后选择安装方式。
- 确认识别,再做具体任务
让 Agent 回报安装目录和识别到的名称
safety-alignment-constitutional-ai,然后告诉 Agent 你的任务和实际输入,让它先核对触发条件。
展开并复制给 Codex 的安装指令
安装并检查 safety-alignment-constitutional-ai
请在 Codex 的当前工作环境中安装并检查 safety-alignment-constitutional-ai 这个 Skill。
项目身份:davila7/claude-code-templates / safety-alignment-constitutional-ai
来源:https://github.com/davila7/claude-code-templates/blob/c1bc5c1df4ff0bffb9a04d8f7790543681232423/cli-tool/components/skills/ai-research/safety-alignment-constitutional-ai/SKILL.md
已定位的源文件:cli-tool/components/skills/ai-research/safety-alignment-constitutional-ai/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。展开并复制给 Claude Code 的安装指令
安装并检查 safety-alignment-constitutional-ai
请在 Claude Code 的当前工作环境中安装并检查 safety-alignment-constitutional-ai 这个 Skill。
项目身份:davila7/claude-code-templates / safety-alignment-constitutional-ai
来源:https://github.com/davila7/claude-code-templates/blob/c1bc5c1df4ff0bffb9a04d8f7790543681232423/cli-tool/components/skills/ai-research/safety-alignment-constitutional-ai/SKILL.md
已定位的源文件:cli-tool/components/skills/ai-research/safety-alignment-constitutional-ai/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。展开并复制给 Cursor 的安装指令
安装并检查 safety-alignment-constitutional-ai
请在 Cursor Agent 的当前工作环境中安装并检查 safety-alignment-constitutional-ai 这个 Skill。
项目身份:davila7/claude-code-templates / safety-alignment-constitutional-ai
来源:https://github.com/davila7/claude-code-templates/blob/c1bc5c1df4ff0bffb9a04d8f7790543681232423/cli-tool/components/skills/ai-research/safety-alignment-constitutional-ai/SKILL.md
已定位的源文件:cli-tool/components/skills/ai-research/safety-alignment-constitutional-ai/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。展开并复制给 当前 Agent 的安装指令
安装并检查 safety-alignment-constitutional-ai
请在 当前 Agent 的当前工作环境中安装并检查 safety-alignment-constitutional-ai 这个 Skill。
项目身份:davila7/claude-code-templates / safety-alignment-constitutional-ai
来源:https://github.com/davila7/claude-code-templates/blob/c1bc5c1df4ff0bffb9a04d8f7790543681232423/cli-tool/components/skills/ai-research/safety-alignment-constitutional-ai/SKILL.md
已定位的源文件:cli-tool/components/skills/ai-research/safety-alignment-constitutional-ai/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。来源原文与资料状态
- 源文件
- 已保存 SKILL.md,抓取于 2026-11-23T04:29:48.865Z
- 中文使用说明
- 尚待整理,保留英文来源内容
- 安装与任务测试
- 本站未执行安装或任务测试
- 来源复核
- 已保留来源记录;当前完整用法未逐项人工复核
展开 SKILL.md 原文、章节与历史收录资料
cli-tool/components/skills/ai-research/safety-alignment-constitutional-ai/SKILL.md · 抓取时间 2026-11-23T04:29:48.865Z
以下保留源文件的 description、章节及摘录,供核对中文说明;完整文件通过上方链接打开。
抓取成功不代表已完成安装或任务测试。
Anthropic's method for training harmless AI through self-improvement. Two-phase approach - supervised learning with self-critique/revision, then RLAIF (RL from AI Feedback). Use for safety alignment, reducing harmful outputs without human labels. Powers Claude's safety system.
查看源文件章节 / Source sections
- 原文:Constitutional AI - Harmlessness from AI Feedback
- 快速开始 / Quick start
- 原文:Common workflows
- 原文:Workflow 1: Supervised learning phase (self-critique + revision)
- 原文:Workflow 2: RL phase (RLAIF - RL from AI Feedback)
- 原文:Workflow 3: Chain-of-thought critique
- 原文:When to use vs alternatives
- 原文:Common issues
- 原文:Advanced topics
- 原文:Hardware requirements
- 原文:Resources
快速开始 / Quick start
Constitutional AI (CAI) trains models to be harmless through self-critique and AI feedback, without requiring human labels for harmful outputs. **Key concept**: Models learn to critique and revise their own responses using a "constitution" (set of principles). **Two phases**: 1. **Supervised Learning (SL)**: Self-critique + revision 2. **Reinforcement Learning (RL)**: RLAIF (RL from AI Feedback) **Constitution example**: ``` Principles: 1. Choose the response that is most helpful, honest, and harmless 2. Avoid responses that are toxic, racist, or sexist 3. Prefer responses that explain objections rather than refuse 4. Choose responses that are thoughtful and nuanced ```
原文:Workflow 1: Supervised learning phase (self-critique + revision)
**Step 1: Generate initial responses**: ```python from transformers import pipeline generator = pipeline("text-generation", model="base-model") prompts = [ "How do I hack a website?", "Write something offensive about a group.", "Help me cheat on my exam." ] initial_responses = generator(prompts, max_length=200) ``` **Step 2: Self-critique with constitution**: ```python critique_prompt = """ Given the question: {question} And the response: {response} Constitution: 1. Choose responses that are helpful, honest, and harmless 2. Avoid toxic, racist, or sexist content 3. Explain objections rather than refuse Identify any ways this response violates the constitution: """ critiques = generator( [critique_prompt.format(q=q, r=r) for q, r in zip(prompts, initial_responses)] ) ``` **Step 3: Revision based on critique**: ```python revision_prompt = """ Question: {question} Original response: {response} Critique: {critique} Please revise the response to better align with the constitution: """ revised_responses = generator( [revision_prompt.format(q=q, r=r, c=c) for q, r, c in zip(prompts, initial_responses, critiques)] ) ``` **Step 4: Fine-tune on revised responses**: ```python from trl import SFTTrainer # Create dataset of (prompt, revised_response) pairs dataset = create_dataset(prompts, revised_responses) trainer = SFTTrainer( model=model, train_dataset=dataset, max_seq_length=1024 ) trainer.train() ```
原文:Workflow 2: RL phase (RLAIF - RL from AI Feedback)
**Step 1: Generate comparison pairs**: ```python # Sample multiple responses per prompt responses_a = generator(prompts, num_return_sequences=2, do_sample=True, temperature=0.8) responses_b = generator(prompts, num_return_sequences=2, do_sample=True, temperature=0.8) ``` **Step 2: AI preference evaluation**: ```python preference_prompt = """ Question: {question} Response A: {response_a} Response B: {response_b} Constitution: {constitution} Which response better follows the constitution? Explain your reasoning, then choose A or B. """ # Get AI preferences (no human labels needed!) preferences = generator( [preference_prompt.format(q=q, ra=ra, rb=rb, constitution=CONSTITUTION) for q, ra, rb in zip(prompts, responses_a, responses_b)] ) # Parse preferences (A or B) chosen, rejected = parse_preferences(preferences, responses_a, responses_b) ``` **Step 3: Train preference model (reward model)**: ```python from trl import RewardTrainer, RewardConfig preference_dataset = create_preference_dataset(prompts, chosen, rejected) reward_config = RewardConfig( output_dir="constitutional-reward-model", learning_rate=1e-5, num_train_epochs=1 ) reward_trainer = RewardTrainer( model=model, args=reward_config, train_dataset=preference_dataset, processing_class=tokenizer ) reward_trainer.train() ``` **Step 4: RL training with RLAIF**: ```python from trl import PPOTrainer, PPOConfig ppo_config = PPOConfig( reward_model_path="constitutional-reward-model", learning_rate=1e-6, kl_coef=0.05 ) ppo_trainer = PPOTrainer( model=model, config=ppo_config, reward_model=reward_model ) ppo_trainer.train() ```
原文:Workflow 3: Chain-of-thought critique
**Enable reasoning transparency**: ```python cot_critique_prompt = """ Question: {question} Response: {response} Let's think step-by-step about whether this response follows our principles: 1. Is it helpful? [Yes/No and reasoning] 2. Is it honest? [Yes/No and reasoning] 3. Is it harmless? [Yes/No and reasoning] 4. Does it avoid toxicity? [Yes/No and reasoning] Based on this analysis, suggest a revision if needed. """ cot_critiques = generator( [cot_critique_prompt.format(q=q, r=r) for q, r in zip(prompts, responses)] ) ```
原文:When to use vs alternatives
**Use Constitutional AI when**: - Want safety alignment without human labels - Need explainable AI decisions - Want to avoid evasive refusals - Have a clear set of principles/constitution - Need scalable safety training **Principles**: - **RLAIF**: AI-generated preferences (scalable, no human labels) - **RLHF**: Human preferences (more accurate, expensive) - **Self-critique**: Iterative improvement - **Chain-of-thought**: Reasoning transparency **Use alternatives instead**: - **RLHF (PPO)**: Need human-validated safety - **DPO/SimPO**: Have human preference data - **NeMo Guardrails**: Need runtime content filtering - **LlamaGuard**: Need pre-trained moderation model
原文:Common issues
**Issue: Model refuses too much (evasive)** Add constitution principle: ``` Prefer responses that engage thoughtfully with questions rather than refusing to answer. Explain concerns while still being helpful. ``` **Issue: Self-critiques are weak** Use stronger critique prompts: ``` Critically analyze this response for ANY potential issues, however minor. Be thorough and specific in identifying problems. ``` **Issue: Revisions don't improve quality** Iterate multiple times: ```python for _ in range(3): # 3 rounds of critique/revision critique = generate_critique(response) response = generate_revision(response, critique) ``` **Issue: RLAIF preferences are noisy** Use multiple AI evaluators: ```python # Get preferences from 3 different models prefs_1 = model_1.evaluate(responses) prefs_2 = model_2.evaluate(responses) prefs_3 = model_3.evaluate(responses) # Majority vote final_preference = majority_vote(prefs_1, prefs_2, prefs_3) ```
文件 SHA256:e2a9b1e5f343c214c0094abcbbe61777e0ccd5e406f46f7ab0fd8fbfa633b926
仓库许可证记录:MIT;skill-declaration-captured-not-interpreted,查看来源。
Anthropic's method for training harmless AI through self-improvement. Two-phase approach - supervised learning with self-critique/revision, then RLAIF (RL from AI Feedback). Use for safety alignment, reducing harmful outputs without human labels. Powers Claude's safety system.
历史收录数据
| 来源仓库 | davila7/claude-code-templates |
|---|---|
| Skill源路径 | cli-tool/components/skills/ai-research/safety-alignment-constitutional-ai/SKILL.md |
安装前请让使用的Agent先读取这个SKILL.md及其所在目录,确认依赖和所需权限。此页不生成未经来源验证的安装命令。
