Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Set-up · 15 minutes

Set up your lab for How LLMs and agents work

After this lesson you can
  • Create the lab folder of the course
  • Check that your computer meets the needs of a small local model
  • Prove with a check script that the lab is ready
Lab files of this lesson (1)

The lab folder as it stands after this lesson. Unzip it in ~/krlab.

More

The zip holds every file that the course has printed up to here. Type the code yourself first: you learn more.

What you need

  • A Linux, macOS or Windows (WSL) computer. You need no GPU and no account.
  • Python 3.12 or later. Every program of the course uses the standard library only, so you install no package.
  • The skill to read a short Python program: variables, lists, dictionaries, for loops and functions. If you cannot yet, do the course "Python for security work" first.
  • About 4 GB of available memory. The model of the course is a 2 GB file, and the server loads it into memory. If your computer has less than 8 GB in total, use the smaller model that lesson 3 names.
  • About 2 GB of free disk space for that file, plus a little for your own files.
  • An internet connection for one download in lesson 3. After that, every lesson runs offline.

Everything runs on your own machine, in one folder: ~/krlab/llms-and-agents. The model server listens on your own computer only (127.0.0.1). Nothing here touches a system that is not yours.

The lab on your computer
InternetYour computerollama.comModel fileModel serverPython scripts123InternetYour computerollama.comModel fileModel serverPython scripts123
  1. ollama.com → Model file: one download, in lesson 3
  2. Python scripts → Model server: HTTP to 127.0.0.1:11434, this computer only
  3. Model server → Model file: loads the 2 GB model into memory

Set it up

1. Make the lab folder

mkdir -p (make directory, with its parents) creates the folder. cd (change directory) moves you into it. pwd (print working directory) shows where you are.

mkdir -p ~/krlab/llms-and-agents
cd ~/krlab/llms-and-agents
pwd
/home/you/krlab/llms-and-agents

2. Check your Python

python3 --version prints the version of Python.

python3 --version
Python 3.14.4

If the number is below 3.12, install a newer Python first (see "If it fails").

3. Check memory and disk

On Linux, free -h shows the memory (-h means human-readable sizes) and df -h ~ shows the free space of the disk that holds your home folder. Look at the column available of the first command and the column Avail of the second. On macOS and Windows, open the system monitor and the disk settings instead.

free -h
df -h ~
               total        used        free      shared  buff/cache   available
Mem:            15Gi       5.2Gi       2.1Gi       410Mi       8.1Gi       9.1Gi
Swap:          2.0Gi          0B       2.0Gi
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2  466G  210G  233G  48% /

This is an example from a laptop. Your numbers will be different. You need at least 4 GB available and 2 GB free. With less than 8 GB of memory in total, use the smaller model that lesson 3 names.

Check your lab

The script labcheck.py proves that the lab works. It uses the standard library only. It checks the Python version and that the lab folder exists. It also asks whether a model server answers at 127.0.0.1:11434. At this point you have no server, because lesson 3 installs it. So the server lines are information, and they do not count. The last line gives the number of real requirements that are met.

Some words in the script are new. sys.version_info holds the version of Python as numbers, so (3, 12) means 3.12. Path.home() is your home folder. urllib.request.urlopen sends a web request: here, to your own computer. try and except run a step that can fail, and catch the failure instead of stopping. "--model" in sys.argv is true when you start the script with the flag --model; lesson 3 does this. name.ljust(8) pads a name to 8 characters. sum(results) counts the True values of a list. /api/tags is the address on which a model server lists its models.

Create labcheck.py in the lab folder.

labcheck.py

"""labcheck.py: prove that the lab of "How LLMs and agents work" works. Standard library only.

    python3 labcheck.py            before lesson 3: two requirements
    python3 labcheck.py --model    from lesson 3: the model server and the model are required too
"""
import json
import os
import sys
import urllib.request
from pathlib import Path

SERVER = os.environ.get("KR_OLLAMA", "http://127.0.0.1:11434")
MODEL = os.environ.get("KR_MODEL", "llama3.2:3b")
need_model = "--model" in sys.argv
results = []


def line(name, ok, detail, required=True):
    """Print one line. A requirement counts in the total; the other lines are information."""
    if required:
        results.append(ok)
    if ok:
        tag = "ok   "
    elif required:
        tag = "FAIL "
    else:
        tag = "info "
    print(tag + name.ljust(8) + detail)


v = sys.version_info
line("python", v >= (3, 12), f"{v.major}.{v.minor}.{v.micro}")

folder = Path.home() / "krlab" / "llms-and-agents"
line("folder", folder.is_dir(), str(folder))

try:
    with urllib.request.urlopen(SERVER + "/api/tags", timeout=3) as reply:
        installed = [m["name"] for m in json.load(reply)["models"]]
    server = True
except (OSError, ValueError, KeyError):
    installed, server = [], False
if server:
    detail = "a model server answers"
elif need_model:
    detail = "no model server answers"
else:
    detail = "no model server answers yet (lesson 3 installs it)"
line("server", server, detail, need_model)

if MODEL in installed:
    detail = f"{MODEL} is installed"
else:
    detail = f"{MODEL} is not installed yet"
line("model", MODEL in installed, detail, need_model)

print(f"lab ready: {sum(results)} of {len(results)}")
python3 labcheck.py
ok   python  3.14.4
ok   folder  /home/you/krlab/llms-and-agents
info server  no model server answers yet (lesson 3 installs it)
info model   llama3.2:3b is not installed yet
lab ready: 2 of 2

Your Python version and your folder can differ. The last line must be the same. If you installed Ollama before, the two info lines say ok, and the last line is still the same. Type the last line of your own output.

If you start in a later lesson, unzip the "Lab files" zip of the course, go into the unzipped folder and run sh kr-lab.sh <lesson folder> ~/krlab/llms-and-agents, for example sh kr-lab.sh 03-run-a-model-on-your-machine ~/krlab/llms-and-agents. It builds the lab folder as it stands after that lesson.

If it fails

Read the first line that starts with FAIL. Fix that one, then run python3 labcheck.py again.

The script saysWhat it meansWhat to do
FAIL pythonPython is older than 3.12.Install Python 3.12 or later from your system package manager or from python.org. Then run the script with that python3.
FAIL folderThe folder does not exist, or you made it in another place.Run mkdir -p ~/krlab/llms-and-agents again. The script looks in your home folder.
python3: command not foundPython is not installed, or has another name.On Windows, work inside WSL. Try python in place of python3.
lab ready: 1 of 2One of the two real requirements failed.Read the FAIL line above it.

You do not need to fix the two info lines now. In lesson 3 you run python3 labcheck.py --model. With that flag the server and the model are requirements, and the last line must be lab ready: 4 of 4.