AI coding agent lab: use opencode to explain and fix code, and check its work
This lab gives each student an AI coding agent of their own, opencode, beside a small tuck shop program with five tests and one bug. The agent can read the project, answer questions about it and change it, and it asks before it changes a file or runs a command.
The agent’s answers come from a model the platform runs on Amazon Bedrock in London, chosen by the platform. The copy has no other way out to the internet, and no key to any model is ever in it.
What students learn
What a coding agent is and how to use one well: ask it to explain before asking it to change anything, run the tests before and after, read each change before allowing it, and never believe an answer because it sounds sure. It suits an introduction to programming with AI tools, or a lesson on testing.
Run it in your browser
The lab starts one service, agent, with the tuck shop project in /home/node/project. The agent is installed each time the lab starts, which takes about a minute: the command docker exec agent cat /tmp/agent/status says ready when it is.
- Open the Container page. Open Build on the bar and choose Run a container. Anybody may open it, and the Git lab and the SQL lab start with no account. Every other lab needs a free account: create one, sign in, then press Start.
- Find the lab. The Sample labs card lists every sample. Find the AI coding agent.
- Press Start. Start runs it as it is, in one press. Edit the file first opens the compose file so you can change it before you start.
- Open it. On the lab’s page, press Open terminal. docker exec -w /home/node/project agent node --test runs the five tests, and one fails. docker exec -it -w /home/node/project agent opencode opens the agent, where a student types what they want done.
Who can use the agent
On a free personal account the agent works in this lab and the one where students install it themselves, up to 80 AI credits a day and 300 in all, which is a few lessons. In a college it works only once the college admin has turned on coding agents in labs, under AI assistance in Settings, and AI assistance for that person as well. Each person may then spend up to 400 AI credits a day. Until then the agent opens and says it has not been turned on.
What to ask students to hand in
The output of the tests before and after the fix, the line the agent changed, and a few sentences on how they checked the change themselves. The last part shows whether they read the change or simply accepted it.
A basic lesson on this lab
AI Coding Agent Basics is a small lesson worked in this lab. In it a student runs the tests, asks the agent to explain the code, lets it fix the bug after reading the change, and runs the tests and the till again to check.
Free personal accounts have it in the Basics module, which is on Home, every college can copy it from the Library’s Basics folder, and a new college opens with it in a module called DevOps Labs (Sample). Copy it into a module of your own to change it.
The code on GitHub
The compose file has no Dockerfile: it runs the official node image, pinned to a version, as an unprivileged user, and installs opencode from npm, also pinned, on each start. opencode is MIT licensed and is not distributed by us. The project is kept in a named volume; the agent is not, because it is too large to save.
Set it as work
Say in the task what to hand in.
- Make the lab. In your module add a task and choose the Container lab card, then In a GitHub repository. Give https://github.com/mitsurutech/lab-ai-agent with the branch main. The compose file is the default, compose.yaml. Fork the repository first if you want to change it.
- Publish and try it. Publish pins the commit you were shown, so a later change in the repository does not alter a lab you have already set. Start your own copy first.
- Hand it out. Assign it like any task, with a due date if you want one, and say in the task what to do and what to hand in.
- Mark what is handed in. Open a student’s copy and the work they handed in, mark it, and send it back with a reason if it needs more.
Questions people ask
- Which model answers the agent, and where does the code go?
- A model the platform chooses, run on Amazon Bedrock in London. Each step sends what the agent has read of the project and what the student typed, with no name or email address, and it is not used to train models. The privacy policy says more.
- Can a student use the agent for anything else?
- The agent works inside the student’s own copy and reaches nothing but the model and the npm registry. It answers whatever is typed, so set the task clearly and mark what they hand in.
- Why does the agent ask before it changes a file?
- The lab’s config tells it to, so that a student reads each change before it is made. That is the habit the lesson teaches.