Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

How AI coding assistants work

After this lesson: I can say what a coding assistant is and is not.

55 min lesson3 commandsAI coding agent lab: use opencode to explain and fix code, and check its work

A coding assistant writes code from a request

An AI coding assistant is a program that reads your code and writes new code from a request you type in plain words. It matters because it is fast and always sounds sure. So you need to know what it is, and what it is not, before you trust it.

A student asks for a function and gets twenty tidy lines in five seconds. Nothing in those lines says whether they are right.

By the end of this lesson

Note

I can say what a coding assistant is and is not.

Key words

WordWhat it means
Coding assistanta program that reads and writes code from your request
Modelthe trained system that produces the assistant's words
Promptthe request you type
Contexteverything the model can see when it answers
Hallucinationa confident answer that is false

The cells students fill in are left blank in this preview.

A model predicts words, it does not know

A model is trained on a very large amount of text and code. Given your prompt, it writes the words that are most likely to come next.

It does not run your program to see what happens. Unless the tool is built to, it does not look anything up. So an answer can be wrong and still read as sure.

Worked example: what assistants can and cannot do

It can usuallyIt cannot
Write a function from a descriptionKnow the rule in your head if you did not say it
Explain what a piece of code doesPromise that the code is correct
Suggest tests and edge casesSee files you did not show it
Edit files and run commands, in an agentDecide whether the result is right for you

The cells students fill in are left blank in this preview.

Is the assistant ready?

Command
docker exec agent cat /tmp/agent/status

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

The lab installs its assistant at start

The lab is a small tuck shop program with an assistant beside it. The command above prints installing while the assistant is being set up and ready when it is done. Run it again until it says ready.

Next you ask a question, then you check the answer yourself. That order is the habit this module teaches.

Ask it to list the functions

Command
docker exec -w /home/node/project agent opencode run "List the names of the functions in shop.js, one per line. Do not change any file."

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Check the answer with a plain search

Command
docker exec -w /home/node/project agent grep -n function shop.js

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Compare the answer with the search

The search prints three lines, one for each function in the file. Put the assistant's list beside them. Do the names match? Did it add one, or leave one out?

The assistant's words change from one run to the next, so your list may differ from a classmate's. The search never changes. That is why you check against it.

The model only sees its context

The model answers from its context: your prompt, the files the assistant has read and the earlier messages in the chat. Nothing else.

If the rule you care about is not in the context, the model guesses. If the context is long, an early detail can be missed.

A common mistake

Warning

Many people think an answer that sounds sure must be right. A model writes likely words, and likely words can be false. Trust an answer only after you have checked it, by reading it, running it or testing it.

Four kinds of mistake to look for

An assistant can invent a function or a setting that does not exist. It can use an old way of doing something. It can write code that looks right and fails on one input. And it can give a different answer to the same prompt next time.

All four are quiet. The code does not announce them.

About this lab and its source: AI coding agent lab: use opencode to explain and fix code, and check its work

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.