|
| 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." | |
0 commit comments