Learning objectives
So far you have used Gemini through Gems: you paste in code, it answers in text. This week you get an agent: an LLM wrapped in a harness that lets it read and write files in a folder, run commands, and keep working until it decides it is done. That changes what you can ask of it, and it changes what can go wrong.
This lab will:
- show you what an agent and its harness actually do when you give it a task;
- show you how many decisions an agent quietly makes when a request is vague;
- let you watch those decisions disappear as you strengthen the specification.
Setting up Claude and VSCode
For the rest of the course, we will be programming in a tool called Visual Studio Code (or VSCode). This is a popular programming tool that supports both Pyret and Python. Claude runs within VS Code, for a much smoother programming experience than you have had copying and pasting code between Gemini and code.pyret.org.
The first part of lab is for getting these tools set up.
- Get Claude: If you haven't already created a Claude account, do so now. Reminder that the department will reimburse you for two months of Claude Pro at their monthly rate of $20 per month.
- Get VSCode: Install Visual Studio Code on your machine. If you are new to installing software, the TAs can help you.
- Setup Pyret within VSCode: In VSCode, go to the Extensions tool in the left sidebar (looks like a square of blocks with the top-right one tilted). Type "Pyret" into the search box at the top left. Select "Pyret Interactive Editor for VSCode". It should install without you needing to do anything else.
- Connect VSCode with your Claude account: Using the same Extensions tool, install the Claude Code extension
Limiting Claude's access to your machine
By default, Claude will be able to access and operate on all parts of your laptop. That means it could read any document on your device, and once a document is read, it can be pulled into training later models. Limiting Claude to working within a specific folder on your machine is a good idea for privacy and safety.
Create a folder or directory on your machine and put any work you want to do with Claude within that folder. For example, Kathi uses a Mac and has a directory called "AgentVisible" that sits next to the "Documents" folder. You'll create a folder in there for each lab or assignment that you do with Claude, starting with this lab.
Now, let's get to learning how Claude works!
Setup
- Find a partner. Labs are pair work.
- Make a new empty folder for this lab and open it in VS Code. (Your VS Code, the Pyret extension and the Claude extension should already be installed from the setup block at the start of lab.)
- Make a copy of the written answer worksheet, share it with your partner(s), and submit the link to it in the worksheet submission form (you can do this before filling anything in).
Part 1What Decisions do Agents Make?
You will ask an agent for the same program four times, giving it a stronger specification each time. The program is a virtual pet: a Pyret reactor where you can feed your pet and play with it, and where the pet dies if you neglect it. For each run, you will record what you expected the agent to decide, what it actually decided, and which missing piece of the spec explains the difference.
Note: Start a fresh agent session for every stage. Otherwise the agent remembers its earlier work and the comparison won't be meaningful.
Step 1Stage 1: the vague request
For this first stage, we'll use the following vague prompt. Don't enter it just yet!
Write a Pyret program, using a reactor, for a virtual pet that I can feed
and play with. Save it in pet1.arr. Start the file with these two lines:
use context dcic2024
include reactors
Before you prompt Claude, write down in your worksheet three decisions you expect the agent will have to make to handle the prompt.
Now, give Claude the prompt. While it works, watch the messages it is showing as well as the answer. Note in your worksheet:
- Did it ask you any questions? Which?
- What did it do besides writing text: files it read or created, commands it ran, permissions it asked you for? Did it run the program it wrote?
- Which decisions did it make that you did not ask for? (Think: what does the pet track, and is a high number good or bad? What do the keys do? How fast do things change? Can the pet die?)
Then run pet1.arr with the Pyret extension and play it. If Pyret reports an error, paste the error message to the agent and ask it to fix the problem. Note how many rounds that takes.
Identify one decision the agent made that you disagree with, and one that you never thought about until you saw it. Note these in your worksheet.
Checkpoint
Compare your agent's pet with another pair's. What differs?
Step 2Stage 2: say what a pet is
The agent chose its own data representation for the pet. Now you choose.
Start a fresh session and give the agent this prompt:
Write a Pyret program, using a reactor, for a virtual pet that I can feed
and play with. Save it in pet2.arr. Start the file with these two lines:
use context dcic2024
include reactors
Represent the pet with this data definition, and start the game with the
example value:
data Pet:
| pet(hunger :: Number, happiness :: Number, alive :: Boolean)
end
start-pet = pet(2, 8, true)
Run it. In your worksheet, note which of the decisions from Stage 1 are now settled and which are still the agent's call. Look for at least two that remain open (for example: what exactly makes the pet die?).
Step 3Stage 3: say what the operations do
The remaining gaps are about behavior. Now we want to tell Claude how we want the pet to behave.
Hunger and happiness are each between 0 and 10. A pet is alive exactly when its hunger is below 10. A dead pet never changes.
tick: hunger goes up by 1, happiness goes down by 1.feed: hunger goes down by 3.play: happiness goes up by 2, hunger goes up by 1.- Levels never leave the 0 to 10 range.
Start a fresh session. Give the agent the Stage 2 prompt (modified to save to the file pet3.arr). Add the behavior rules and tell Claude to generate code that passes the following checks:
check "tick":
tick(pet(2, 8, true)) is pet(3, 7, true)
tick(pet(2, 0, true)) is pet(3, 0, true)
tick(pet(9, 5, true)) is pet(10, 4, false)
end
check "feed":
feed(pet(5, 5, true)) is pet(2, 5, true)
feed(pet(1, 5, true)) is pet(0, 5, true)
end
check "play":
play(pet(2, 9, true)) is pet(3, 10, true)
play(pet(9, 5, true)) is pet(10, 7, false)
end
check "dead pets don't change":
feed(pet(10, 4, false)) is pet(10, 4, false)
end
Did the agent run the tests? Did they pass? Play the game. In your worksheet: what is still up to the agent now? Which of those decisions would a test have settled, and which could no test settle?
Hint: Think about what you see on the screen versus what the tests can check.
Checkpoint
Show a TA your worksheet for Stages 1 to 3.
Step 4Reflect
Describe what you've learned from this sequence of prompts. Also comment on the extent to which you trusted what Claude generated, and what led you to trust or distrust Claude across the entire sequence so far.
Turn the tables: let the agent ask you!
Start a new Claude session. Give it the first prompt again, this time adding the instruction "Before writing any code, ask me questions until you have no ambiguities" to the Stage 1 prompt. In your worksheet, note what it asked about and whether you think it was asking useful questions.
More pets!
Imagine that you wanted to let a virtual pet owner choose whether their pet was a dog or a cat. Not only should each of these pets appear differently, but dogs and cats also behave differently:
- Dogs gain three points of happiness from being played with
- Cats get hungry twice as fast as a generic pet
We're going to explore what has to change in your code.
Look at the code for pet3.arr. Locate the spots in the code where you think you would need to make edits in order to distinguish between cats and dogs as described. Put a copy of your pet3.arr code in the Code tab of your worksheet, and use Google Doc comments to indicate where changes are needed (and generally what kind of changes those would be; not the code, just a short, general description).
If you have time, tell Claude to copy your code to pet4.arr and work together to make pet4 support both kinds of pets. Note anything interesting that you observed about what Claude does or how it works in your worksheet.
Handin
Hand in these files, together, in one submission:
pet1.arrpet2.arrpet3.arrpet4.arr
Submit to Gradescope. You may submit as many times as you like before the deadline; we grade the last submission.
Comments or concerns?
If you have comments or concerns, submit them on the anonymous feedback form. Sign in with your Brown Google account to open it; your email address is not recorded.