Machine state records which phase an application is in, so each phase can perform its own actions and show the appropriate interface. In a sequential game, states prevent unrelated operations from running and help ensure each language-model request happens once per question. section 9.4
A question-and-answer game can move through four states:
- GET_QUESTION retrieves a question and displays a waiting indicator. section 9.4
- ASK_QUESTION displays the question and accepts the player's answer. section 9.4
- EVALUATE_ANSWER sends the answer for evaluation and displays progress. section 9.4
- STATE_RESULT reports whether the answer was correct and may reveal the correct answer. section 9.4
A status-controlled Streamlit game
Store status on a central Game object, then let methods change it: obtain_question moves to ASK_QUESTION, accept_answer moves to EVALUATE_ANSWER, and evaluation moves to STATE_RESULT. The frontend branches on game.status, renders the matching widgets, and calls st.rerun() after transitions. section 9.4
Figure 9.7 Conditional branching in the frontend based on the game’s state
Use the state-branching diagram to connect each status with its corresponding frontend display. section 9.4
