Session 3 — The first agent
Goals
- Separate what is sent to the model, what comes back, and what the code carries out.
- Run an agent loop without a key and without payment.
- Save the work in Git so a partner can pull it.
What is sent and what comes back
To an existing model you send instructions, the user's request, and sometimes tool results. Text comes back, or a tool request. This is using a model that has already been trained. Training changes weights from examples. In this course we do not train a model.
If there is no access to a model yet, a policy written in code is enough to learn the loop. Once you connect a model, the same skeleton stays: proposal, check, execution, result, stop.
The loop
The file code/lab01/agent.py implements a fixed policy:
- If there is no calculator result yet, request a subtraction.
- If the result arrived, answer with a number.
- If the budget ran out, stop. The stop is not a numeric answer.
After pulling the repository, from inside the lab folder:
python agent.py
The expected output includes the difference 5 and the status answered. Then change the budget to 0 in the call to run and check that the status becomes stopped.
The simulation above is broader than lab 1: it also has a hostile document. It is still not a model.
Build an agent in VS Code
The same loop, with a real model. The video "Build an AI agent in VS Code" walks the whole way: a free model running on your own computer, developing the agent, an evaluation that measures and improves it, and sharing its tools over MCP. It is on the videos page, with a full transcript. The code from the video is in code/vscode-agent/.
Git, briefly
Create a private repository on GitHub and invite your partner.
git status
git add agent.py
git commit -m "Add the first deterministic agent loop"
git push
A partner's small change goes through a branch and a Pull Request, not straight into the main branch. A .gitignore file keeps out the virtual environment, keys, and model weights. A key does not go into the code even if the repository is private.
Exercise
Change the calculator action from subtraction to division by zero. Write down what the status is, how many times the tool ran, and whether you may report that the task was completed.
Check your understanding
Summary
Found a mistake on this page? Email the lecturer