arrow keys · F fullscreen · P read as page
COSC 10001 · Week 5 · Wed, Sep 23, 2026

Agentic Coding
with Karel

Today a robot writes the code for the robot. You decide if it's right.

Before you start

Get the two files

Save both in your Karel folder, next to MyKarel.java. Keep the names exactly as they are.

Download AGENTS.md   Download CleanRowKarel.java

Already got them from Slack in class? You're set.

What's inside

AGENTS.md

# AGENTS.md

This is a Karel the Robot project for COSC 10001, a first-year course at TCU. The person asking you for help may never have programmed before.

## Rules for code you write

- Every program extends `Karel`, not `SuperKarel`. There is no `turnRight()` or `turnAround()`; if you need one, write it as a private method built from `turnLeft()`.
- Use only what the class has learned: `move()`, `turnLeft()`, `pickBeeper()`, `putBeeper()`, the conditions `frontIsClear()`, `frontIsBlocked()`, `leftIsClear()`, `leftIsBlocked()`, `rightIsClear()`, `rightIsBlocked()`, `beepersPresent()`, `noBeepersPresent()`, and `while`, `if`, `else`.
- Break every program into small methods with names that say what they do. `run()` should read like a to-do list.
- A program must work for every world of the same kind, not only the one in `worlds/`. Never count beepers or steps from a world file.
- Put each new program in its own file named after what it does, like `DoubleBeepers.java`. Do not change `MyKarel.java`.

## Checking your work

- Compile with `javac -cp lib/karel.jar *.java`. Do not run the program: it opens a window, and the student runs it themselves.
- When you finish, explain what you did in two or three plain sentences a beginner can follow.

CleanRowKarel.java

import stanford.karel.*;

/*
 * CleanRowKarel.java
 *
 * Karel should walk along the row and pick up every beeper in it.
 * Load the world long-row.w and press Run. Count what is left.
 */
public class CleanRowKarel extends Karel {

    public void run() {
        while (frontIsClear()) {
            pickUpBeeperIfThere();
            move();
        }
    }

    private void pickUpBeeperIfThere() {
        if (beepersPresent()) {
            pickBeeper();
        }
    }
}
What is a coding agent?

A chatbot talks.
An agent acts.

The workflow · this stays on the board all semester

commit → prompt → review → run → commit

Each step, in one line
Save your work first, so you can always get it backcommit
Say what you want, in plain English, one step at a timeprompt
Read what it wrote. Every line is yours nowreview
Run it, on more than one worldrun
Save again, so the history shows what the agent didcommit

Last week's git restore . is your undo button for anything an agent does.

Before the first prompt

The charter file

Standing instructions the agent reads before every task, so you don't repeat yourself in every prompt.

GitHub Copilot, CodexAGENTS.md
Claude CodeCLAUDE.md, or AGENTS.md if there isn't one

So one AGENTS.md works for all three.

Our AGENTS.md, the short version
Try the demos yourself

Same prompts,
your laptop

  1. Commit first, so you can always get back
  2. In a terminal in your Karel folder, start copilot or codex
  3. Paste a prompt from the next slides. Read what it plans before you say yes
  4. Run the new file in IntelliJ, then Load World the world the prompt names
  5. Happy with it? Commit

Each prompt takes the agent a minute or two. That's normal.

Demo 1 · you solved this by hand on Sep 9

Double the beepers

Write DoubleBeepers.java. Karel doubles the pile of beepers one step east of him, then comes back to where he started. See worlds/pile.w.

Is it what we wrote? Then: change the pile to seven and run it again.

Demo 2 · a new one

Collect the newspaper

Write NewspaperKarel.java. Karel walks out of his house to the newspaper, picks it up, and comes back to where he started, facing the same way. See worlds/CollectNewspaperWorld.w.

Read run() first. Can you tell what it does without reading anything else?

Demo 3

Climb the staircase

Write StaircaseKarel.java. Karel climbs the staircase, putting one beeper on each step, and stops at the top. It should work for a staircase of any height. See worlds/staircase.w.

Before we run it:
how many steps? So how many beepers?

It made a decision without asking you

Is the floor
a step?

You only catch that if you knew what you expected before you pressed Run. That's the review step.

Don't put a beeper on the floor. Only on the steps.
Your turn · 1 of 2

Find the bug

1. Both files from Slack are in your Karel folder. Commit:

git add .
git commit -m "Add the charter and a buggy program"

2. Run CleanRowKarel, then Load World long-row.w. It should pick up every beeper. Count what's left.

Your turn · 2 of 2

3. In a terminal in your Karel folder, start copilot or codex and type:

CleanRowKarel.java should pick up every beeper in the row, but it leaves one behind. Find the bug and fix it.

4. Review: git diff. How many lines changed?

5. Run it on long-row.w and short-row.w

6. Commit and push:

git add .
git commit -m "Agent fixes the last beeper"
git push
What was wrong

Off by one

The loop stops when the wall is in front of Karel, and that's before he checks the last square.

No error. No complaint. Just one beeper left behind.
The most common bug in programming, and now you've fixed one.

If something goes wrong
Before you go
CS Engagement, first reflection. One event, 250 wordsWed, Sep 30
Professional Foundations. Step-by-step on the site; email it to your peer mentorWed, Sep 30
Tell your pod which Ship-It project you pickedWed, Sep 30
Build Checkpoint 1. Your Karel repo, a world you built, an agent commit (today's counts), NOTES.mdWed, Oct 7

The agent wrote the code today.
You decided whether it was right.

That part doesn't get automated.