mcpField
K
karpathy-system-prompt-learning

karpathy-system-prompt-learning

github.com/learnpromptAgent 工作流118129 次安装16 周前更新
代码仓库

关于 karpathy-system-prompt-learning

karpathy-system-prompt-learning 是一项用于设计和改进系统提示的 Skill,通过背景知识、示例和策略指导任务执行。它还提供将 Agent 常见错误转化为可复用提示指令的方法。

主要功能

  1. 01三层提示设计框架
  2. 02编码、分析与写作模板
  3. 03提示失效诊断方法
  4. 04提示版本记录
  5. 05将错误转为指令的规范

适用场景

  1. 01为新任务起草系统提示
  2. 02针对 Agent 反复出错改进提示
  3. 03记录并复用经过验证的策略

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/learnprompt/andrej-karpathy-skills --skill karpathy-system-prompt-learning

安装后在 Claude Code 中输入/karpathy-system-prompt-learning确认已加载。

详细介绍

技能 13:系统提示学习范式

来源:https://x.com/karpathy/status/1921368644069765486 “系统提示学习——缺失的大模型学习范式”

核心原则

系统提示就是一本教科书。要像写教科书一样撰写它。

Karpathy 的见解:大模型有三种学习模式(预训练、微调、RL)——但还有第四种被严重低估:系统提示学习。将策略明确写入系统提示,比重新训练更节省样本,也比寄希望于模型自己摸索出策略更可靠。

可以把它想成在每次任务开始前为大模型编写一本教科书。它不只是指令——而是包含推理过程的策略。

系统提示学习框架

好的系统提示分为三个层次(对应人类的学习方式):

Layer 1: EXPOSITION (pretrain equivalent)
→ Background knowledge the model needs
→ Relevant concepts, terminology, context
→ "Here's what you need to know about [domain]"

Layer 2: WORKED EXAMPLES (SFT equivalent)  
→ Step-by-step demonstration of correct behavior
→ Explicit reasoning traces
→ "Here's exactly how to handle [situation]"

Layer 3: STRATEGY (RL equivalent)
→ Explicit decision rules
→ Error patterns to avoid
→ "When you see X, do Y because Z"

从零开始编写系统提示

Build a system prompt that teaches an LLM to [TASK] reliably.

Task description: [WHAT THE LLM SHOULD DO]
Current failure mode: [HOW IT CURRENTLY GOES WRONG]
Desired behavior: [EXACTLY WHAT GOOD LOOKS LIKE]

Structure the system prompt with all three learning layers:

Layer 1 — Exposition:
Write 2-3 paragraphs of background knowledge the LLM needs. 
Include: key concepts, relevant context, domain vocabulary.

Layer 2 — Worked Examples:
Write 2 complete examples of the task done correctly.
Format: INPUT → [step-by-step reasoning] → OUTPUT
Show the thinking, not just the answer.

Layer 3 — Strategy:
Write explicit decision rules as IF/THEN/BECAUSE statements.
Include: common mistakes to avoid, edge cases to handle, quality checks.

End with: "Before responding, verify: [checklist of 3-5 quality checks]"

改进现有系统提示

如果当前的系统提示效果不佳:

Diagnose and improve this system prompt.

Current system prompt:
[PASTE CURRENT PROMPT]

Failure mode I'm seeing:
[DESCRIBE HOW IT'S GOING WRONG]

Example of bad output:
[PASTE BAD EXAMPLE]

Example of good output:
[PASTE GOOD EXAMPLE]

Analysis:
1. What's missing from the exposition layer? (background knowledge gaps)
2. What worked examples should I add?
3. What explicit rules would prevent this failure mode?
4. Is the prompt too restrictive? Too vague? Wrong framing?

Output: improved version of the system prompt with changes annotated.

策略编写模板

用于编码任务
SYSTEM PROMPT: [CODING TASK]

You are an expert [LANGUAGE] developer. Follow this exact strategy:

UNDERSTANDING PHASE (always do this first):
- Restate the task in your own words
- List all edge cases you can think of
- Identify the one tricky part

IMPLEMENTATION PHASE:
- Start with the simplest working version
- Add complexity only when simple version fails
- Comment every non-obvious line with WHY

VERIFICATION PHASE (always do this last):
- Trace through your code with one concrete example
- Check: does it handle empty input? Large input? Wrong type?
- Confirm: could a junior dev maintain this?

NEVER:
- Assume the input is well-formed without checking
- Add dependencies without saying why
- Write clever code when simple code works
用于分析任务
SYSTEM PROMPT: [ANALYSIS TASK]

You are an analytical expert. Follow this strategy:

GROUNDING:
- Always cite specific evidence before making claims
- Confidence levels: CERTAIN / LIKELY / SPECULATIVE — always label which
- If you don't know something, say so explicitly

STRUCTURE:
- Lead with the conclusion, then the evidence
- One claim per paragraph
- Maximum 3 levels of nesting

QUALITY CHECKS before responding:
- [ ] Every claim has evidence?
- [ ] Confidence levels labeled?
- [ ] Would an expert in this field agree with this framing?
- [ ] Am I answering the actual question or a related easier one?
用于创作/写作任务
SYSTEM PROMPT: [WRITING TASK]

Writing strategy for this task:

VOICE:
[Describe the tone, style, what to avoid]

STRUCTURE:
[Describe the expected output format]

QUALITY STANDARD:
A response is good when [describe what success looks like].
A response is bad when [describe common failure modes].

EXAMPLE OF GOOD OUTPUT:
[Paste one example]

EXAMPLE OF BAD OUTPUT (and why):
[Paste one example with annotation]

提示版本控制

像管理代码一样跟踪系统提示的迭代:

# [PROMPT NAME] — Version History

## v3 (current) — [DATE]
Change: Added explicit "verification phase" checklist
Reason: v2 was skipping edge case checking
Result: Failure rate dropped from ~30% to ~5%

## v2 — [DATE]
Change: Added worked examples section
Reason: v1 was too abstract; model wasn't following the strategy
Result: Moderate improvement

## v1 — [DATE]
Initial version: [PASTE]

元提示词(用大模型编写提示词)

Help me write a system prompt for this agent.

Agent task: [WHAT IT SHOULD DO]
I'll be using this with: [CLAUDE / GPT-4 / etc.]
Critical behavior: [WHAT MUST ALWAYS HAPPEN]
Failure modes to prevent: [WHAT GOES WRONG WITHOUT GOOD PROMPTING]

Apply the three-layer system prompt learning framework:
1. Exposition (what the model needs to know)
2. Worked examples (demonstrate correct behavior)
3. Strategy rules (explicit IF/THEN/BECAUSE)

Then: suggest 3 variations I could test to find the best version.

工作流

属于工作流:反偏见决策(第 3 步/终点)

位置上游下游
第 3 步(沉淀)karpathy-understanding-first(验证后)沉淀完成,可复用

完整链路:llm-simulator → understanding-first → system-prompt-learning

也可在日常开发中独立使用——任何时候 Agent 反复犯同一类错误,都应该触发本技能。

提示契约

Extract a system prompt lesson from this failure/pattern: <DESCRIBE_THE_RECURRING_ERROR>. Produce: 1) Trigger condition — when does this error occur, 2) Correct strategy — step-by-step what the agent should do instead, 3) Anti-patterns — what specifically to avoid, 4) Worked example — a before/after showing the improvement, 5) Concise instruction block (< 200 words) ready to paste into system prompt or SKILL.md.

验证清单

  • 触发条件描述具体(不是「有时候」)
  • 策略是逐步说明的(不是模糊建议)
  • 反模式列出了具体的错误做法
  • 有前后对比示例
  • 指令块 < 200 words,可直接粘贴
  • 已在新的测试用例上验证指令块有效

评论

支持 Markdown