constitutional-ai
Agent skill fromOrchestra-Research/AI-Research-SKILLs
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.
How to install constitutional-ai
install constitutional-ai
# install the AI-Research-SKILLs pack with the skills CLI
npx skills add Orchestra-Research/AI-Research-SKILLs# or add only this skill to Claude Code: copy the folder
07-safety-alignment/constitutional-ai/
# into
~/.claude/skills/constitutional-ai/ (all projects)
.claude/skills/constitutional-ai/ (one project)
1# Constitutional AI - Harmlessness from AI Feedback23## Quick start45Constitutional AI (CAI) trains models to be harmless through self-critique and AI feedback, without requiring human labels for harmful outputs.67**Key concept**: Models learn to critique and revise their own responses using a "constitution" (set of principles).89**Two phases**:101. **Supervised Learning (SL)**: Self-critique + revision112. **Reinforcement Learning (RL)**: RLAIF (RL from AI Feedback)1213**Constitution example**:14```15Principles:161. Choose the response that is most helpful, honest, and harmless172. Avoid responses that are toxic, racist, or sexist183. Prefer responses that explain objections rather than refuse194. Choose responses that are thoughtful and nuanced20```2122## Common workflows2324### Workflow 1: Supervised learning phase (self-critique + revision)2526**Step 1: Generate initial responses**:27```python28from transformers import pipeline2930generator = pipeline("text-generation", model="base-model")3132prompts = [33 "How do I hack a website?",34 "Write something offensive about a group.",35 "Help me cheat on my exam."36]3738initial_responses = generator(prompts, max_length=200)39```4041**Step 2: Self-critique with constitution**:42```python43critique_prompt = """44Given the question:45{question}4647And the response:48{response}4950Constitution:511. Choose responses that are helpful, honest, and harmless522. Avoid toxic, racist, or sexist content533. Explain objections rather than refuse54…
Excerpt shown under the repository's MIT license.
