Skip to content

Commit a5f2b4d

Browse files
committed
adds new skills
1 parent 93781a8 commit a5f2b4d

18 files changed

Lines changed: 877 additions & 0 deletions

ai-assisted-dev/SKILL.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
name: ai-assisted-dev
3+
description: Use as an always-on baseline when assisting the user with ANY task. Contains rules for efficient AI-assisted development — how to prompt well, provide context, evaluate output, manage tokens, and avoid common pitfalls. Nudge the user when they violate these rules.
4+
---
5+
6+
# Efficient AI-Assisted Development
7+
8+
Distilled from Chip Huyen's *AI Engineering* (2024). Rules for getting the most out of AI coding assistants. **Nudge the user when they violate any of these.**
9+
10+
**Deep reference:** When the user needs chapter-level detail (e.g., setting up RAG, fine-tuning, evaluation design, production architecture), read the relevant file from this skill's directory:
11+
- `book-reference-prompting-and-models.md` — sampling, context window, prompt engineering, security, hallucinations (ch. 1-2, 5)
12+
- `book-reference-rag-agents.md` — RAG, agents, tool design, reflection, memory (ch. 6)
13+
- `book-reference-finetuning-data.md` — fine-tuning, LoRA, dataset engineering, synthetic data (ch. 7-8)
14+
- `book-reference-evaluation.md` — eval design, AI-as-judge, benchmarks, model selection (ch. 3-4)
15+
- `book-reference-production.md` — inference optimization, architecture, guardrails, routing, feedback (ch. 9-10)
16+
17+
## 1. Give Clear, Structured Instructions
18+
19+
- **Be unambiguous.** If you want a specific format, say so. Every unwanted behavior is a missing constraint.
20+
- **Assign a role** when it matters ("review this as a security auditor" vs "as a junior dev" produce different results).
21+
- **Provide 2-5 examples** (few-shot) — they reduce ambiguity more than lengthy descriptions. Put the most relevant example last (recency bias).
22+
- **Specify output format explicitly.** Ask for concise answers — longer output = more latency, more cost, more hallucination risk.
23+
- **Decompose complex tasks** into subtasks with separate prompts. One monolithic request = fragile. Simpler sub-tasks can use cheaper/faster models.
24+
25+
**Anti-pattern:** Vague instructions followed by "that's not what I meant." Invest 30 seconds in precision upfront.
26+
27+
## 2. Provide the Right Context, Not All Context
28+
29+
- **Critical info at the beginning and end** of your message. Models retrieve middle content worst ("lost in the middle" — Liu et al., 2023).
30+
- **Clean your context.** Strip HTML tags, formatting artifacts, boilerplate. Databricks: removing HTML improved accuracy 20% and reduced input length 60%.
31+
- **Don't just paste a function** — include imports, the class it belongs to, and a brief note on purpose. Context for code chunks matters.
32+
- **More context is not always better.** Each additional token costs money, increases latency, and may dilute attention. Be selective.
33+
- **Rewrite ambiguous references.** "What about that function?" -> "How does the `parseConfig` function in `src/config.ts` handle missing fields?" Self-contained queries retrieve better context.
34+
35+
**Rule of thumb (Anthropic):** Knowledge bases under ~200k tokens (~500 pages) can go in the prompt. Above that, use RAG/file search.
36+
37+
## 3. Understand Why Output Varies
38+
39+
- **Models are probabilistic.** Same input can produce different output due to temperature, sampling, and server-side nondeterminism.
40+
- **Temperature 0** = most deterministic ("safest" answers). **~0.7** = balanced creativity. Higher = more creative but less reliable.
41+
- **Stop conditions matter.** Without max tokens or stop sequences, the model may ramble. Too low = truncated output, broken JSON.
42+
- **Changing sampling params is the cheapest lever.** Try this BEFORE rewriting the prompt.
43+
- **If the output is inconsistent**, generate multiple responses and pick the best. Retrying 3 times often fixes extraction/formatting errors.
44+
45+
## 4. Evaluate Output — Don't Just "Looks Right" It
46+
47+
- **Define what "good" looks like BEFORE asking.** This is evaluation-driven development — the AI equivalent of TDD.
48+
- **Spot-check systematically** — diverse inputs, edge cases, adversarial inputs. Don't just glance at one example.
49+
- **Diagnose the type of failure:**
50+
- Wrong facts? -> Provide better source material / context.
51+
- Wrong format/style? -> Provide better instructions / examples.
52+
- Both? -> Fix them separately — they have different solutions.
53+
- **The model's output quality depends on three things:** instructions, context, and the model itself. When results are bad, identify which one is the problem.
54+
- **Poor results may be your prompt's fault, not the model's.** Improve the prompt before blaming the model.
55+
56+
## 5. Manage Multi-Step Tasks Carefully
57+
58+
- **95% accuracy per step = 60% after 10 steps, 0.6% after 100.** Compound errors are the main risk of autonomous agents.
59+
- **Separate planning from execution.** Ask for a plan first, review it, then proceed. Don't let the agent run a 20-step chain unreviewed.
60+
- **Verify intermediate results.** Don't trust a long chain of autonomous actions — check at natural milestones.
61+
- **Models hallucinate tool parameters.** They may call the right function with wrong arguments, or call a non-existent function. Review tool calls.
62+
- **Plans generated by LLMs may seem reasonable yet fail during execution.** The model generates plausible sequences but doesn't truly evaluate consequences. Verify plans before executing.
63+
- **Ask the model to reflect on failures.** Don't just re-prompt — ask WHY the previous answer was wrong. The Reflexion pattern (analyze failure -> new strategy) significantly improves results.
64+
65+
## 6. Be Token-Efficient
66+
67+
- **1 output token impacts latency as much as ~100 input tokens.** To reduce latency, focus on making output shorter (ask for concise answers, no preambles) rather than trimming input.
68+
- **Prompt caching:** structure prompts so stable parts (system prompt, reference docs, examples) come first, variable part (your question) last. Anthropic reports up to 90% cost reduction and 75% latency reduction.
69+
- **If you paste the same examples into every prompt**, that's a signal to use CLAUDE.md / system prompt / cached prefix instead of repeating them.
70+
- **Clean input context** (strip noise, boilerplate) reduces token count and improves results simultaneously.
71+
- **Choose the right model for the task.** Use the strongest model to assess feasibility, then test if a cheaper/faster one suffices. Don't use Opus for trivial lookups.
72+
73+
## 7. Know Model Limitations
74+
75+
- **Models are bad at math.** Ask them to write code that calculates, then run the code. Don't ask them to calculate directly.
76+
- **Context window size ≠ context utilization ability.** A model accepting 1M tokens doesn't effectively use 1M tokens. Attention degrades with length.
77+
- **Hallucinations are more likely on:** niche topics with less training data, questions about things that don't exist, and when the model generates long responses.
78+
- **Models can't reliably distinguish system instructions from injected instructions.** Don't put secrets in prompts. Assume any prompt can be extracted.
79+
- **Embedding/semantic search loses specific identifiers** (error codes, function names, product IDs). Use keyword search for exact matches.
80+
- **A model optimized for one domain may be worse at others.** Be aware of this when choosing specialized vs general models.
81+
82+
## 8. Your Corrections Are Valuable
83+
84+
- **Every time you edit AI output, you create a preference signal** (original = rejected, your edit = preferred). Be deliberate about corrections.
85+
- **Reformulating the same question 3 times** means the initial framing was the problem. Step back and provide more context or constraints instead of rewording.
86+
- **Don't just accept longer output as better.** Users are biased toward longer responses even when shorter ones are more accurate (length bias). Evaluate on correctness, not volume.
87+
- **Chain-of-thought examples are disproportionately powerful.** When you need the AI to reason, show it HOW to reason with a worked example, not just the final answer.
88+
89+
## Red Flags — Nudge the User
90+
91+
| Signal | Nudge |
92+
|--------|-------|
93+
| Vague request, then "that's not what I meant" | "Be specific upfront: format, constraints, edge cases. 30 seconds of precision saves iterations." |
94+
| Pasting huge files without cleaning | "Strip noise first. Clean context improves accuracy 20% and reduces tokens 60%." |
95+
| Not reviewing AI output before using it | "Spot-check systematically. 95% accuracy compounds to 60% over 10 steps." |
96+
| Re-prompting the same question differently 3+ times | "The framing is the problem. Step back — provide more context or constraints." |
97+
| Asking the model to calculate math | "Ask it to write code that calculates, then run the code." |
98+
| Letting a long multi-step chain run unreviewed | "Verify at milestones. Compound errors are the #1 agent failure mode." |
99+
| Using Opus for a trivial lookup | "Right model for the task. Start strong, then optimize down." |
100+
| Dumping everything into context | "More ≠ better. Critical info at start and end. Be selective." |
101+
| Not providing examples for a nuanced task | "Few-shot examples reduce ambiguity more than lengthy descriptions." |
102+
| Accepting longer output as better without checking | "Length bias: longer ≠ more accurate. Evaluate on correctness." |
103+
| Blaming the model before improving the prompt | "Poor results may be your prompt's fault. Improve instructions first." |
104+
| Skipping plan review before execution | "Separate planning from execution. Review the plan, then proceed." |
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Chip Huyen — Evaluation & Model Selection (Chapters 3-4)
2+
3+
## The Golden Rule
4+
**If you cannot evaluate it, do not build it.** Define eval criteria BEFORE writing code. This is TDD for AI.
5+
6+
## Evaluation Anti-Patterns
7+
- Relying on others' opinions ("someone said model X is good") instead of testing yourself.
8+
- "Eyeballing" outputs — checking a handful of examples and declaring it works.
9+
- Using favorite prompts from personal experience rather than actual user needs.
10+
- Trusting public benchmarks uncritically (many contaminated with training data).
11+
12+
## Evaluation Design Process
13+
14+
### Step 1: Evaluate Components Separately
15+
If a pipeline fails, test each stage independently. Also evaluate at turn level AND task level.
16+
17+
### Step 2: Create Evaluation Guidelines
18+
- Define what a "good" answer looks like AND what is out of scope.
19+
- Correct ≠ good (e.g., "You're not qualified" may be correct but unhelpful).
20+
- Prepare scored examples for every rating level. Test guidelines with humans first.
21+
- Link eval metrics to business metrics: "80% accuracy = automate 30% of tickets; 98% = automate 90%."
22+
23+
### Step 3: Choose Methods and Data
24+
- Combine cheap classifiers (broad coverage) + expensive judges (high quality on sample).
25+
- Use log-probabilities for confidence estimation when available.
26+
- Manual evaluation remains important even in production (LinkedIn: up to 500 interactions daily).
27+
- Bootstrapping for sample size: each 3x reduction in detectable difference requires 10x more samples (~10 for 30%, ~1000 for 3%, ~10000 for 1%).
28+
29+
### Step 4: Evaluate Your Evaluation
30+
- Repeatable? Run twice, check variance.
31+
- Better scores correlate with better business outcomes?
32+
- Metrics correlated? If perfectly correlated, drop one. If uncorrelated, either measuring different things (good) or one is broken.
33+
- Track all eval variables (data, scoring schema, judge prompts) when iterating.
34+
35+
## AI-as-Judge
36+
- Most common eval method in production (58% on LangChain's platform).
37+
- The judge = model + prompt + sampling params. Changing any = different judge.
38+
- Include few-shot examples in judge prompt (consistency: 65% → 77.5%).
39+
- Prefer classification ("good"/"bad") over numeric scores. If numeric, use discrete 1-5, not continuous. Wider scales = worse.
40+
- **Known biases**: self-preference (GPT-4: 10%, Claude-v1: 25%), position bias (prefers first answer — randomize order), length bias (prefers longer even if wrong; 2x length difference → almost always picks longer).
41+
- Never trust an AI judge without seeing its model and prompt.
42+
- Cost: strong model for generation + evaluation ≈ doubles API costs. Use cheap classifier for 100% + expensive judge for 1%.
43+
44+
## Benchmark Contamination
45+
- Public benchmarks quickly saturated (GLUE ~1 year, MMLU → MMLU-Pro).
46+
- At least 40% of 13 popular benchmarks was in GPT-3's training set.
47+
- A 1M-parameter model trained only on benchmark data achieved near-perfect scores.
48+
- **Rule**: benchmarks good for eliminating weak models, not finding best for YOUR task.
49+
- Use perplexity analysis and n-gram overlap to detect contamination.
50+
51+
## Model Selection Process
52+
1. Filter by hard constraints (license, data privacy, deployment requirements).
53+
2. Use public benchmarks/rankings to narrow shortlist.
54+
3. Run your own eval with your own data and criteria.
55+
4. Monitor continuously in production.
56+
57+
### Hard vs Soft Attributes
58+
- **Hard** (can't easily change): license, training data, model size, privacy requirements.
59+
- **Soft** (can improve): accuracy, toxicity, factual consistency — via prompting, fine-tuning.
60+
61+
### Open-Source vs API — Seven Factors
62+
1. **Data privacy** — can't send data externally → API disqualified.
63+
2. **Data provenance** — open-weight models often lack training data transparency.
64+
3. **Performance** — gap shrinking, but best open models likely remain slightly behind top commercial.
65+
4. **Functionality** — APIs offer ready-made features; self-hosting requires building them.
66+
5. **Cost** — API = pay per token; self-hosting = fixed infra (cheaper at scale). Reassess regularly.
67+
6. **Control** — commercial models may over-censor, change without notice, be discontinued.
68+
7. **On-device** — offline/user hardware → open-source only.
69+
70+
### Practical Tips
71+
- Start with strongest model to assess feasibility, then test if smaller suffice.
72+
- For fine-tuning, start simple model then scale up to largest that fits hardware.
73+
- Prefer standard API formats (OpenAI-compatible) for easier migration.
74+
- Prefer models with strong community support.
75+
76+
## Perplexity as Practical Tool
77+
- **Detecting contamination**: unusually low perplexity on test data = likely saw it during training.
78+
- **Data deduplication**: only add data if model's perplexity on it is high (genuinely new).
79+
- **Anomaly detection**: very high perplexity = text model finds difficult/nonsensical.
80+
- Caveat: may not be best metric for post-trained models (SFT/RLHF can increase perplexity while improving task performance).

0 commit comments

Comments
 (0)