Capstone · capstone
Capstone project: Capstone: The Study Assistant
Each stage of study_assistant.py has been checked on its own, with the grader’s versions of the other stages standing in for yours. This lesson checks the program as a whole, the way a person meets it, with nothing replaced. There is no new function to write. If every earlier lesson passed, the program should already pass; this is where you make sure, and fix what the combination shows.
The checklist
Work through it in the Shell. Each item is part of the brief from Lesson 1.
ask. Run
python study_assistant.py ask "How do I make an independent copy of a list?". You should see the answer, a blank line andSources: 03-lists#4. Then tryWhat is the capital of France?, which printsSources: none, andWhy should a default argument never be a list?, which cites05-functions#5.quiz. Run
python study_assistant.py quiz 03-lists, then with--count 1and--count 5. The scripted model has a quiz ready for each count of03-lists. Any other note gets the same list questions from the scripted model; that is the model, not your code.chat. Run
python study_assistant.py chat, typeWhat does len() return?, press Enter, read the answer, and end with an empty line.Each exit code. Run
python stages.py: Lesson 6’s block makes the program end with each code, under the scripted failurestool-loop,broken-streamandrate-limit:2. Then try a too-small budget and a missing note, withecho $?after each:$ python study_assistant.py --budget 500 ask "How do I make an independent copy of a list?" Error: The budget ran out before agent step 1. $ echo $? 3Usage.
python study_assistant.py --helpandpython study_assistant.py quiz --helpshow the commands and options.python study_assistant.py quiz 03-lists --count 9is a usage error, code2.The tests. Run
python -m pytest -q. Chapter 10’s tests still pass, because the capstone imports the same modules they test and changes none of them:$ python -m pytest -q ........................... [100%] 27 passed in 0.79sThe time will differ a little.
Any other question you type into ask gets the scripted model’s echo, which is not JSON, so ask asks once more, gets the echo again, and ends with exit code 1. That is the program working: the scripted model only knows the three questions in SCRIPTED_MODEL.md. A live model, which Chapter 12 connects, answers anything.
What checking adds
Checking your work runs every rule from Lessons 2 to 6 again, with three differences:
Your own functions are used throughout. Nothing is replaced except what the file started with: the imports, the constants at the top and the five supplied functions, which come from the grader’s own copy.
The notes and questions are new to you: a temporary notes folder with notes about sets, tuples and ranges, passed to
mainasnotes_dir, and questions your code has never seen.Failures are combined in one run, the way they happen with a real service: a rate limit in the middle of an agent step; an invalid answer whose corrective retry does not fit the budget, which ends with exit code
3; a quiz whose first reply is invalid, asked with--count 2; and a chat whose first request fails before any text arrives, which must be retried and print its answer once.
When a check fails, its message names the command or function and the rule from the brief that did not hold, with one next step.
Run it
Run python stages.py for every block from Lesson 2 to Lesson 8, then check your work.
You ask the study assistant a question that is not in SCRIPTED_MODEL.md, and it ends with exit code 1. What does that tell you?
In one combined check, ask's first answer is invalid and its corrective retry does not fit what is left of the budget. How does the program end?
Task
Finish study_assistant.py so the whole program meets the brief from Lesson 1, with the exact messages and output formats of Lessons 2 to 6, and with your own functions throughout. Work through the checklist in the lesson: each command once in the chat typed, --help, and python -m pytest -q still green. Then check your work. The check runs every rule of Lessons 2 to 6 again on notes and questions you have not seen, plus failures combined in one run.