Session 8. Loops and graphs — Wed 23 Sep

Quick quiz (ungraded)

Q1: Retrieval returns nothing. Which of the three implementations can refuse before spending a model call?

  • It is free, and the chain has nowhere to do it. There is no branch between its retrieve step and its prompt.

  • Correct. Both have a branch after retrieval. The chain sends whatever came back straight into the prompt.

  • The critic runs after a draft exists, so the call is already spent. That is one call too late.

Q2: The event answered arrives while the machine is in retrieving. What does step return?

  • That is the fall-through an if/elif gives you for free. The run continues in a state the design never allowed, and the bug surfaces somewhere else.

  • Every caller then has to remember a try, and the one that forgets takes the process down over a late retry. An out-of-order event is ordinary.

  • Correct. Nothing moves, nothing raises, and the reason is in the return value where the caller reads it.

Q3: What makes done terminal?

  • That works and it is code somebody can delete in a refactor. Terminality then disappears with it, silently.

  • Correct. It is a fact about the data, and adding an outgoing edge would be a deliberate line in a diff.

  • There is no library here. Five states and six edges are a dict, and the dict is what decides.

Q4: Why must visited only ever grow?

  • The machine does read it. Without the history there is nothing to count, and a retry cap is a count.

  • Correct. visited.count('retrieving') is what stops a retry storm, and rewriting the list to the current state erases exactly that.

  • It is the order they were entered, which is the only order that tells you what the run did.

Q5: You add one edge, retrieving --retry--> retrieving. The graph is still legal. What did you just ship?

  • A retry is normal. An edge back to the same state with nothing counting on it is a run that never ends.

  • Correct. The storm is not in the retry, it is in the missing counter. Cap it with visited.count(...) before the move.

  • That rule lives in answer_question and bounds model calls. It says nothing about a self-edge in your graph.