Command Palette

Search for a command to run...

Hectal
Phase 12: Advanced Patterns
RAG and Vector Search · Exercise 5 of 5 Previous
Intermediate

Stop a search loop

actions is a list of strings: "search: <query>" or "answer: <text>". Write run_loop(actions, max_steps) that goes through at most max_steps actions and returns a string.

If an action starts with answer: , return "answered: " followed by the text. If a search query was already used, return "stopped: repeated query". If max_steps actions are used up without an answer, return "stopped: step limit".

What Check tests

  1. An answer ends the loop
  2. A repeated query stops the loop
  3. The step limit stops the loop
  4. An answer at the last step still counts

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.