karpathy-loop
Iterative prompt optimization — write, measure, cut, repeat with progressive compression
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-10
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- karpathy-loop
- triggers
- Karpathy loop, optimize prompt, measure tokens
- changelog
- docs/ciclos/cycle28-20260815.md
- description
- Iterative prompt optimization — write, measure, cut, repeat with progressive compression
- token_budget
- 3050
02 资源文件 2
- 参考文档cut-tactics.md1.1 KB
- 参考文档iteration-examples.md2.3 KB
03 SKILL.md 正文
When to Use
Prompt bloated/slow/expensive · need consistent quality at lower cost · production/automation prompts · skill authoring — every skill should pass karpathy-loop.
STYLE (5 Rules)
- ID+TASK=ENOUGH — identity+task. 2. MINIMAL — no 10+ item lists. 3. FORMAT=INSTRUCT — "Respond ONLY in JSON:{...}". 4. CONSTRAINTS=FORMAT — max X chars / code only. 5. IMPLICIT CoT — no "step by step"; "Reason ONLY if ambiguous".
LOOP: Write→Measure→Cut→Repeat
- WRITE: role + task + 1-2 examples + output. Don't optimize yet. 2. MEASURE: chars/4 ≈ tokens; score correctness/conciseness/robustness. 3. CUT: remove redundant→merge→simplify; no output change→cut. 4. REPEAT: improves+tokens down→continue; drops→revert; stagnant→new tactic.
Example: Write 680/170tok→6.3 | Cut T1 480/120→7.3 | T2 340/85→7.3 | T3 260/65→5.3 ✗ → REVERT T2. Final 340ch/85tok 7.3/10.
Compression Levels
| Level | Target | What to cut |
|---|---|---|
| T1 | 20-30% | filler, transitions, "step by step" |
| T2 | 30-50% | merge redundant→bullets, remove context |
| T3 | 50-70% | template structures, shortcuts, minimal identity |
Budget
ID+TASK: 20-50 | +example: +100-200 | +constraints: +50-100 | OPTIMAL: 50-300
Decision — Remove?
Output changes?→keep · else concision?→remove · else clarity?→keep · else→remove
STOP
Tokens <50 + works · 3 iterations no improvement · Fits in 1 line. NEVER: sacrifice correctness for tokens, or leave edge cases uncovered.
Anti-Rationalization
| Rationalization | Red Flag | Verification |
|---|---|---|
| "3 iteraciones bastan, corto en T2" | Stopping at T2 in THOROUGH/complex prompt | Measure T3 — revert only if score drops (e.g., 7.3→5.3), must measure first |
| "Tokens ya <300, no medir" | Skipping MEASURE after CUT | tokens≈chars/4 + correctness/conciseness/robustness score each loop |
| "Quito constraints para ahorrar" | Removing FORMAT=INSTRUCT to save tokens | Verify output still matches JSON/schema without constraint — keep if drift |
Red Flags
- Doing work without checking output format → STOP, re-read skill
- Second occurrence of same rationalization → force RED zone
Verification
- Output matches skill ## Output contract + file:line citaton
- cross-ref-check.ps1 → SKILL.md OK
Refs
lean-context · skill-improver · metricas · code-review-agent · context-watchdog · execution-mode
Absorbed (2026-09-18): prompt-engineering archived — its prompt-optimization/template workflows are covered by this skill.
Reference
Worked examples, testing patterns, edge cases, anti-patterns → docs/skills/karpathy-loop/reference.md
04 同仓库更多 Skills
web-quality-audit
Comprehensive web audit: performance, a11y, SEO, responsive, animation, design tokens.
ui-engine
UI system — Grid/Flexbox/@layer/:has(), container queries, compositor-only animation, OKLCH tokens, component patterns
baseline-ui
Anti-slop UI — layout, typography, responsive, animation, tokens. Use for cleanup or polish.
skill-creator
Create new AI agent skills following Agent Skills spec -- auto-bootstrap unknown tasks, define structure, register in AGENTS.md
senior-engineer
Apply senior engineering competencies — system design, trade-off analysis, delegation, mentoring, and tech debt strategy
prompt-engineering
Design effective prompts using SPEARS framework — scope, principles, examples, assertions, refinements, with ReAct and multi-agent patterns