Recipe: guard a search loop
The three guards in order: a final answer, a repeated query, the step limit.
A table that maps a measured symptom to a pattern, with recipes to copy for parent expansion within a budget, a stuck-loop guard, and where a real tool-calling search loop plugs in.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write pick_pattern(symptom) that looks the symptom up in a dictionary and returns the pattern, or "measure first" for an unknown symptom. Include three symptoms of your own. Print the result for one known and one unknown symptom.
Write unique_in_order(items) that removes repeats and keeps the first occurrence of each item. Print it for ["D52", "D50", "D52", "D51", "D50"].
Explain it without notes
How would you choose between parent-child retrieval and summaries?
What do you do before adding any advanced pattern?
Why keep a baseline after adding a pattern?
Which guards belong in any model-driven search loop?
Expected output
script A: answered at step 2 after 1 search(es)
script B: stopped at step 2: repeated query
script C: stopped: step limit 3