“Program testing can be used to show the presence of bugs, but never to show their absence.” — Edsger W. Dijkstra


Prerequisites


Why AI for coding?

A motivating example

Say you want to read a NetCDF file (one month of ERA5 temperature, for example) and draw a filled map with xarray and cartopy. The hard part is usually not the science. It is remembering the exact xarray/cartopy functions, getting the projection right, and fixing a dimension-order mistake. With an AI coding assistant, you can describe what you want in one sentence and get a first working draft in seconds. AI does not do the thinking for you. It takes away the busywork, including looking things up, remembering syntax, writing the first draft, so you can spend your time on the science, and on checking the results. AI can write, but you must verify.


How large language models work

An LLM is a neural network trained on a huge amount of text and code to predict the next token. Almost everything else follows from that one fact: it is a probabilistic text generator. It is not a database, and it is not a reasoning engine that is guaranteed to be correct.

Tokens

The model does not read characters or words. It reads tokens, which are short chunks of text. In English, a common word like “ozone” is one token; a longer word like “concentration” may split into two. In Chinese, a token is usually one or two characters. Cost and the context window are both counted in tokens, which is why tokens matter in practice.

drawing

Figure source, adapted from Jay Alammar, The Illustrated GPT-2 (redrawn).

The context window

The model can only “see” a fixed number of tokens at once. That limit is its context window. Everything you give it, like the instruction, the files, the conversation history, has to fit inside the window. Whatever does not fit is dropped or compressed. This one limit is the reason context engineering exists.

drawing

Figure source, adapted from Jay Alammar, The Illustrated GPT-2 (redrawn).

Next-token prediction

Generating text is a loop: given the tokens it has seen so far, the model assigns a probability to each possible next token, picks one, appends it, and starts again. Two things follow:

  • the model is very fluent, because it has seen an enormous amount of text and code;
  • it can be fluently wrong, because at each step it is only guessing, and a plausible guess is not necessarily a true one.

drawing

Figure source, adapted from Jay Alammar, The Illustrated GPT-2 (redrawn).

Generation parameters

That picking step is why the same prompt can give different answers each time. Temperature controls how random the picking is. A low temperature concentrates the probability on the most likely tokens, so the output is stable and “safe”. A high temperature spreads the probability out, so the output is more varied, more creative, and more likely to drift into nonsense.

drawing

Figure source, adapted from Jay Alammar, The Illustrated GPT-2 (redrawn).

Base models vs. instruct models

A base model only knows how to keep writing whatever text it is given; it is not trying to be helpful. An instruct/chat model has been fine-tuned (with a method like Reinforcement learning from human feedback (RLHF)) to follow instructions. The assistants and coding agents you use are instruct/chat models, and many of them add a reasoning (chain-of-thought) step on top.

Knowledge cutoff and hallucination

A model’s knowledge stops at the cutoff date of its training data. Past that point, it will sometimes hallucinate: it confidently invents functions, parameters, or facts that do not exist. This is not a bug; it is a direct result of next-token prediction. The model is trying to write a plausible continuation, not a true one. That is why the rule of this module is verify.

Under the hood, an LLM is just a function: you pass text in and get text back.


A brief history

Here we want to answer one question: why did AI for coding become useful and cheap only in the last few years? The answer is a series of jumps in what these systems can do, driven by four turning points.

drawing

Before deep learning (1950s–2000s)

Everything was rules written by hand. Symbolic AI and expert systems stored knowledge as explicit rules. In the editor, “AI” meant rule-based autocompletion (e.g., IntelliSense), syntax checking, and code templates. It was pattern matching, not understanding. This is the era of the IntelliSense you still use today.

Neural networks and pre-training (2010s)

Statistical language models gave way to neural networks. In 2017, the paper Attention Is All You Need introduced the Transformer, which made it practical to train models on long pieces of text (this is where the context window from the last section comes from). In 2018, Generative pre-trained transformer (GPT) and Bidirectional Encoder Representations from Transformers (BERT) established the pre-train, then fine-tune recipe that most models still follow.

Turning point 1 and 2: Large models and code generation (2020–2022)

In 2020, GPT-3 showed what are now called scaling laws: the more parameters and data, the more capable the model. The loss keeps dropping as compute grows, with no plateau in sight.

drawing

Figure source, adapted from Kaplan et al., Scaling Laws for Neural Language Models (2020).

In 2021, OpenAI Codex powered GitHub Copilot, the first mainstream AI pair programmer. But Copilot could only complete code; it could not change your project. In late 2022, ChatGPT showed the second turning point, alignment: a model tuned to follow instructions, not just to keep writing text.

Turning point 3: From autocomplete to agents (2023–2024)

GPT-4 (2023) made multi-step reasoning practical. Early agent experiments (AutoGPT, BabyAGI) showed how much an agent can do on its own, and how easily it can go off the rails. The field then matured on the engineering side: Cursor put agents inside the editor, SWE-bench became a serious benchmark, and in 2024 Claude Code shipped a coding agent that runs in the terminal. Anthropic also proposed Model Context Protocol (MCP) as a way to connect agents to outside tools. This is when coding AI crossed from completing to doing, like reading files, editing, running tests, and fixing bugs.

Turning point 4: Open weights and reasoning models (2025–present)

Open-weight models such as DeepSeek R1/V3 closed much of the quality gap and cut the cost dramatically. They are now cheap enough that you can bring your own API key, as we will in the labs. Reasoning models (which write out a chain of thought before answering) got better at hard tasks. And the ecosystem around agent harnesses (skills, plugins, and workflows) became the normal way to customize these tools. Today’s tools sit in this last stage.

To sum up, scale made models smart, alignment made them follow instructions, engineering let them act, and open weights made it cheap.


Core concepts

The mental model

Here is the whole vocabulary in one picture, from the bottom up:

drawing

A way to remember:

  • LLM is the brain
  • harness is the body and workshop
  • agent is the worker
  • tools are its hands
  • skill is a how-to manual
  • workflow is an assembly line
  • plugin is extra equipment

Three pairs people often mix up:

  • agent ≠ harness: the agent is the one doing the work; the harness is the program that hosts it.
  • skill ≠ plugin: a skill is mostly knowledge and instructions; a plugin is mostly new features.
  • workflow ≠ agent: a workflow is a fixed set of steps; an agent figures out its own steps.

LLM

The model itself, described above. In practice the choice that matters is which model: a stronger reasoning model, or a faster and cheaper one. It is a trade-off between quality, speed, and cost.

The major providers are OpenAI (GPT), Anthropic (Claude), Google (Gemini), and DeepSeek. There are also open-weight models you can run yourself, such as Llama (Meta) and Qwen (Alibaba). Model names change often, so you do not need to memorize them. Just know the two kinds: reasoning models, which are stronger on hard problems but slower and pricier, and chat models, which are fast and cheap.

Most models you will use are cloud models, which you call through an Application Programming Interface (API), as you will set up in Lab 13. They are strong but cost money and send your data to the provider. You can also run local models on your own computer, for example with Ollama. Local models are free and keep your data private, but they are slower and weaker than cloud models.

Prompt

Everything you say to the model: a system prompt (the role and rules) plus the user prompt (the task), plus any files or examples you attach. In coding, a good prompt is a clear spec. For example, “write a function that reads a CSV of station observations, returns a pandas.DataFrame, and handles missing values” works much better than “process the data”.

Context (engineering)

Everything the model can see right now: relevant code, error messages, documentation, and the conversation so far. Choosing carefully what goes into that window and what stays out is context engineering. Feeding the model 500 irrelevant lines is noise, not help.

drawing

Prepared for this course.

Tool

A single thing the agent can do, like read a file, edit a file, run a shell command, search the web, and so on. Tools are what turn a chatbot into something that can do things. For example, to “fix code and check it”, an agent needs at least two tools: “read file” and “run test”.

Agent

An agent is an LLM wrapped in a loop: think → act (call a tool) → observe (read the result) → think again, until the goal is reached. You give the goal (like, “make this script run and pass the test”); the agent reads, edits, runs, reads the error, and tries again. A main agent can also hand off parts of the work to subagents.

drawing

Figure source, adapted from Anthropic, Building Effective Agents (2024, redrawn).

Harness

The harness is the program that gives the agent its hands and its environment. It manages the session, connects the tools, enforces permissions and a sandbox, loads skills/plugins/workflows, and keeps track of models and credentials. It is the shell that lets the model act safely inside your environment. DeepSeek Harness, Claude Code, Codex, and Cursor are all harnesses.

drawing

Prepared for this course.

Skill

A skill is a reusable how-to with a short set of instructions that teaches the agent to do one kind of task well, loaded only when needed. For example, a “geoscience plotting style” skill could say “use cartopy, pick the projection this way, use cmocean colormaps, label the units”, so every figure comes out consistent.

drawing

Prepared for this course.

Workflow

A workflow is a fixed and multi-step process. It is a script that splits a big job into ordered steps and hands them to many subagents in parallel or in a pipeline. Use it for batch work that is well defined and repeatable. For example, “audit these 50 scripts for bugs and summarize”. It is predictable and easy to re-run.

drawing

Figure source, adapted from Anthropic, Building Effective Agents (2024, redrawn).

Plugin

A plugin is a software package that extends the harness. It can add new tools, new parts of the interface, or connections to other services, and it may bundle skills and workflows too. In DeepSeek Harness, plugins are installed as packages (aka, “bundles”) through the plugin manager.


The tool landscape

Three kinds of tools

Kind Examples What it is for
Chat assistant ChatGPT, Claude, DeepSeek web Answer questions, draft snippets, explain errors
IDE autocomplete GitHub Copilot, editor built-ins Suggest code as you type
Agent harness DeepSeek Harness, Claude Code, Cursor, Codex, Gemini CLI Run the edit→test→fix loop on its own; Customizable with skills/plugins/workflows

How to choose

  • The more verifiable and well-specified the task, the more you can hand it to an autonomous agent.
  • The more exploratory or one-off the task, the more a chat assistant fits.
  • Whatever the tool, it runs, it has tests, and you understand it.

In-class exercises

Exercise #1

Which is a better instruction to give a coding assistant, and why?

    1. “Fix my data analysis.”
    1. “Read station.csv with pandas, drop rows where Ozone is NaN, and plot a daily-mean time series saved as ozone_timeseries.png.”

Exercise #2

For each item, name the concept it matches: LLM, prompt, context, tool, agent, harness, skill, workflow, and plugin.

  • The shell that lets the model read files and run commands safely.
  • A reusable “how-to” that forces every figure to use cartopy and cmocean.
  • A script that audits 50 scripts by fanning out to many subagents.
  • A package that adds a new “connect to Zotero” capability.
  • The loop: think → act → observe → think again.

Exercise #3

Using any chat assistant you have access to, ask it to write a Python function that reads a CSV and computes the mean of a numeric column, ignoring missing values. Then:

  • identify which parts of your request were prompt and which were context;
  • find one thing you would have to verify before trusting the result.

Further reading

Practical guides


The notes were prepared for the ESE5023 AI-for-coding module and adapt ideas from the resources above.