Prompt and Context Engineering
Who it is for
What you will achieve
Prerequisites
Curriculum
- Step 1: Temperature, Top-p and Sampling: Why the Same Prompt Gives a Different Answer
A model scores every next word, softmax turns the scores into probabilities and one word is drawn. See what temperature and top-p do to that draw with six words, plain numpy and 1000 draws.
- Step 2: Explicit Criteria vs Vague Prompts: Turn Every Adjective Into a Check a Script Can Run
Swap words like "better" and "professional" for criteria a script can mark pass or fail: 120 words, every number kept, no hedge words, three bullets. Then rewrite a vague meeting-notes prompt until all five rubric checks pass.
- Step 3: Few-Shot Prompting Done Right: How Many Examples, How Different, What Order, and the Leak That Lies
Sort support tickets into billing, bug, feature or other by showing the model four worked examples: an easy case, a hard case, an edge case and a near miss. Then pick the count, the order and the shape, and keep the examples out of your test set.
- Step 4: Structured LLM Output with Pydantic: Describe the Shape Once, Check Every Reply
An LLM replies with a string. Pydantic turns that string into a typed object or a clear error. Validate a User, generate its JSON Schema, then follow one customer e-mail through a Ticket model where the first reply says refund, fails the check, and the retry fits.
- Step 5: Prompt Caching: Keep the Start of Every Request Identical and Pay for the Long Part Once
A shop help desk sends the same 1,373-token policy with every question. Keep that start byte-for-byte identical, mark it for caching, and the second call's input drops from $0.005608 to $0.000391. One timestamp at the top breaks it.
- Step 6: Prompt Versioning and Testing in a Repo: Prompt Files, a Registry, a Hash per Answer and Tests That Gate
Treat prompts like code: one file per version, a registry.json that names the live one, a hash logged with every answer, a 12-ticket golden set (v1 0/12, v2 12/12) and 8 pytest tests that catch a careless label edit before review.
- Step 7: Context Engineering: What Belongs in the Context Window, Turn by Turn
A support agent on turn twelve sends 1,679 tokens to the model, and the question is only 20 of them. Measure each part of the window, give it a budget, put it in the right order, and compact it to 1,089 tokens without losing the facts the next step needs.
- Step 8: Context Engineering for a Long-Running Agent: Clear, Compact, Take Notes, Prove It
A support agent forgets the customer's name, order and contact choice after twenty turns and fails 0 of 4 checks. Measure the window, clear old tool output, compact old turns and keep a notes file, and the same chat passes 4 of 4 with 470 tokens instead of 2,945.