Talk to the head.From your own code.

Get the head onto your PC.

New in step 1: the head lives on your own PC.

The head is the trained model you met at the end of lesson 0. It runs on your own computer, for free.

the head, on your PC. Drag it to turn it. The label goes round the back as it spins.

Start with an empty file.

New in step 2: an empty agent.py, and the command that runs it.

agent.py (empty)

Make a file called agent.py in any text editor, leave it empty, and save it in a folder. In the terminal, move into that folder with cd and the folder's path, then run it:

python agent.py
text editor
A program for writing plain text. Notepad on Windows works. On a Mac, TextEdit works if you choose Format, then Make Plain Text.
cd
Short for change directory: it moves the terminal into a folder. Type cd, a space, then the folder's path. For example cd Desktop\agent for a folder called agent on your Desktop (on a Mac, cd Desktop/agent). The command python agent.py only finds the file from inside its folder.
agent.py
Your program. .py is the ending for Python files. Save it in a folder you can reach with cd.
python agent.py
python starts Python, and the name after it is the file to run. Python reads the file from the top, one line at a time. An empty file has no lines, so it finishes at once and prints nothing.

Nothing happens, which is correct. Over the next lessons this file becomes your agent, a few lines at a time.

Write the note.

New in step 3: the note, a dictionary that holds your prompt.

the note your question = the prompt the rest: a dictionary, names and values

Slide it under the door.

New in step 4: the note goes to Ollama, which hands it to the head and sends back its reply.

Ollama is the program at the door: it keeps the head and runs it. It listens at http://localhost:11434: localhost means this very computer, and 11434 is the number of Ollama's door. Your code slides the note under that door, and Ollama hands it to the head. Here you watch one trip. The next part, Build the trip, writes the code that makes it.

Ollama: localhost:11434
the head, reading your note

These buttons replay answers we recorded on our PC (qwen3:8b). Your own agent.py sends the question written in its body, and from Keep asking on, whatever you type. They were recorded with "stream": True, so the answer comes in pieces.

Build the trip.

New in step 5: the lines that pack the note, send it to Ollama and read the reply.

You just watched the trip. Now we write the lines that make it, in three small changes, each shown as your whole agent.py. New lines are highlighted.

import json

body = {
    "model": "qwen3:8b",
    "messages": [{"role": "user", "content": "Why is the sky blue? One sentence."}],
    "stream": False,
    "think": False,
}

URL = "http://localhost:11434/api/chat"
note = json.dumps(body).encode()
print(note)
import json
Loads Python's JSON tools. JSON is a plain-text format for sending data between programs, and the note travels in it. The json tools turn dictionaries into it and back.
URL = "http://localhost:11434/api/chat"
The address. localhost is your own computer, 11434 is the door number Ollama listens on, and /api/chat is its chat counter.
json.dumps(body)
Turns the dictionary into one line of text, the line you saw in the live note. False becomes false on the way.
.encode()
Turns that text into bytes, the raw numbers a connection carries (one byte per plain letter). The result is stored as note. From here on: body is what the note says, and note is the same note packed into bytes for the trip.
print(note)
Shows the note. The b before the quote means bytes. This is exactly what will travel.

Run python agent.py. Ollama is not needed yet. It prints the note:

b'{"model": "qwen3:8b", "messages": [{"role": "user", "content": "Why is the sky blue? One sentence."}], "stream": false, "think": false}'

Keep only the words.

New in step 6: take only the head's words out of the reply.

The words live under "message", then "content". Watch where they sit inside answer.

Keep asking.

New in step 7: a loop that asks you again and again until you type quit.

you type a line the note goes in the head answers just words printed back to the top: ask again if you typed quit: the loop ends

That's lesson 1.

Your file asks the head a question and prints the answer, as many times as you like. That's the first piece of your agent.

Try telling it your name, then asking for it. It won't know. Every message starts from zero, and fixing that is lesson 3.

the head
The trained model, qwen3:8b: a big file of tuned numbers that runs on your PC.
Ollama
The program on your PC that keeps models and runs them.
terminal
A window where you type commands instead of clicking.
prompt
The text you send to the head.
dictionary
A Python container of named values: curly braces holding "name": value pairs.
list
Square brackets holding items in order. The messages go in one.
JSON
The text format the note travels in. json.dumps turns a dictionary into it, json.load turns it back.
stream
True: the answer arrives in pieces while the head writes. False: all at once.
think
True: qwen3 writes private notes before it answers, and they come back in their own field.
token
A piece of text, often part of a word. The head reads and writes text in tokens. (See the fold-out in Write the note.)
localhost
The address of your own computer. Ollama's door on it is number 11434.
loop (while True)
Repeats the lines under it until a break. Typing quit triggers the break.
input()
Prints a question, waits for you to type a line, and hands back what you typed.