A new computer, nothing on it
In the last lesson the agent was ready and waiting. At work you often start with a computer that has nothing on it. Today you install the agent yourself, tell it where its model is, and use it on the tuck shop program again.
By the end of this lesson
Note
I can install a coding agent and connect it to a model.
Key words
- Package: a program packed up so it can be installed.
- npm: the tool that installs JavaScript packages.
- Config file: a file of settings a program reads when it starts.
- Endpoint: the web address a program sends its requests to.
- Proxy: a go-between that decides which addresses can be reached.
Before you start
Note
Press Start the lab on the bar at the top of this lesson and wait until it says it is running. The lab is one service called agent, and the terminal reaches it by that name. Each Run button below types its command into your lab's terminal, one after another in the same session. To watch them, or to type your own, press Open terminal on the bar.
1. Nothing is installed
npm ls -g lists the packages installed for every project on this computer. The list is empty: there is no agent yet.
docker exec agent npm ls -gShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
2. Install the agent
The @1.19.3 on the end pins one exact release, so everybody in the class gets the same agent. The install takes about a minute. If it stops with the word Killed, the lab ran short of memory while npm wrote the files: run it again. Then ask the agent which release it is.
docker exec agent npm install -g --no-fund --no-audit [email protected]Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
docker exec agent opencode --versionShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
How npm got out of the lab
Note
This lab has no way out to the internet. npm got the package through a proxy at http://ai:3128, which lets the npm registry through and nothing else. Every other address is refused.
3. Tell the agent where its model is
The agent does not know which model to use until a config file tells it. Read the example. baseURL is the endpoint, the platform's model at ai:4000. model picks it by name, lab/lab. permission makes the agent ask before it edits a file or runs a command. Then make the folder and copy the file into it.
docker exec agent cat /home/node/opencode.example.jsonShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
docker exec agent mkdir -p /home/node/.config/opencodeShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
docker exec agent cp /home/node/opencode.example.json /home/node/.config/opencode/opencode.jsonShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
A common mistake
Warning
Many people think an agent needs a secret key in its config to reach a model. Here the key is lab, a placeholder. The lab adds the real one on the way out, so it is never in a file you could share by mistake. Never paste a real key into a config you hand in.
4. Use your agent
First one question, to show the config works. Then open the agent's screen and ask it to fix the bug in total, as in the last lesson: read each change before you allow it, and press Ctrl+C twice to close it. Then run the tests.
docker exec -w /home/node/project agent opencode run "In one sentence, what does shop.js do?"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
docker exec -it -w /home/node/project agent opencodeShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
docker exec -w /home/node/project agent node --testShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Questions to answer
- Why does the install name an exact release,
@1.19.3? - Which line of the config says where the model is?
- How did npm reach the registry when the lab has no way out?
- Why is there no real key in your config?
- After a stop and a start, what must you do again, and why?
For teachers
Tip
This lesson is a small example of a lesson worked in a lab: the steps and the Run buttons are the lesson, and the lab is each student's own copy. The lab is the first lesson's, with nothing installed: the student installs opencode from npm through an allow-list proxy and copies a config into place. Key learning points: 1. A program is installed as a package, pinned to a release. 2. A config file tells an agent where its model is. 3. A key never goes in a file you hand in. Listen for a pupil who thinks the agent works without a config, and ask them to run it before the copy. The student hands in their opencode.json, the tests before and after, and their answers. Copy it into your own module and change it, or build one from scratch with the Lab menu in the lesson builder.