6.2.8 · D1AI Agents & Tool Use

Foundations — Code-generation agents

3,211 words15 min readBack to topic

Before you can read the parent note, you must own every letter it throws at you. The parent assumes you already know what , , , , , , , , , , and mean. Below we earn each one from zero — plain words first, then a picture, then why the topic can't live without it.


The picture that holds everything

Everything in this topic happens inside one repeating cycle. Look at it once now; every symbol below is just a label on some arrow or box in this picture.

Figure — Code-generation agents

Keep this figure in mind. Now we name each part.


Symbol 1 — the step counter

Picture: in the loop figure, imagine a small odometer that clicks up by one every time the arrow completes a full circle.

Why the topic needs it: the whole point of an agent is that it changes over time. Without a clock we could not talk about "the code as it was on attempt 2 versus attempt 3." Every other symbol wears as a subscript to say at which turn we mean it.


Symbol 2 — the requirements

Picture: the sticky note pinned to the top of the whiteboard in the figure — always visible, never rewritten.

Why the topic needs it: the agent must be reminded, on every single turn, what it is trying to do. If were forgotten after turn 0, the agent would fix a bug but lose sight of the goal.


Symbol 3 — the action and the "sampled from" arrow

We meet the action before the code state, because the action is what changes the code, so we cannot describe how code updates until we know what an action is.

Picture: the "Planning → Action" arrow in the loop figure; think of a bag of possible next moves, and is the one we pull out.


Symbol 4 — the code state and how updates it

Picture: the text file on the screen inside the "State" box. Each turn it may be edited.

evolves by a rule the parent writes as:

Why the topic needs it: an agent that solves whole problems must hold a growing artifact — the program — separate from any single message . is that artifact; is the photograph we take of it right before running.


Symbol 5 — the execution triple

This is three symbols that always travel together, so we meet them as a family.

Picture: below shows one such triple as three coloured cards — the code card, the output card, and the error card — clipped together.

Figure — Code-generation agents

The subscript vs : we use to walk over past attempts ("for each earlier run "), and for the current turn. They are the same kind of counter; just ranges over history.


Symbol 6 — the history and the set-builder notation

Let's decode that notation piece by piece, because it packs three ideas into little marks.

Picture: in the figure, the logbook is a stack of the clipped cards from Symbol 5 — one card-stack per past attempt.


Symbol 7 — the prompt , concatenation, and system instructions

Picture: the "Perception → Context" arrow in the loop figure is the machine that packs these four things into the scroll .

Why the topic needs it: the model can only react to what is in its prompt. is the formal answer to "what does the agent know this turn?" — and building it well (which of to keep when it grows huge) connects directly to retrieval.


Symbol 8 — Execute, giving and

Picture: the "Action → Execution → State" arrow, drawn as a fenced box (the sandbox) that swallows the program and spits out (green) and (red).

Why the topic needs it: this is the act half of sense–decide–act. It is what makes the loop grounded in reality instead of the model hallucinating success. It is the concrete use of tool use.


Symbol 9 — success probability , attempts , and

Now we reach the counting. The parent claims:

Let's earn every letter.

Figure — Code-generation agents

The figure shows this curve climbing toward 1 as grows. This one picture is the whole reason agents iterate: even a mediocre single-shot rate becomes near-certain with a few tries.


Symbol 10 — the binomial coefficient and pass@k

The performance metric uses a new mark:

Why the topic needs it: pass@ is how benchmarks like HumanEval report agent skill — it rewards exactly the try-several-times behaviour that defines an agent. It links straight to program synthesis evaluation.


How the foundations feed the topic

t step counter

State bundle

R requirements

C_t current code

H_t history logbook

P_t assembled prompt plus system rules

A_t sampled from LLM

Apply gives c_t full program

Execute c_t in sandbox

o_t output

e_t error

1 minus one minus p power k

pass at k benchmark

Read top to bottom: the four state pieces feed the prompt, the prompt is sampled into an action , the action is applied into a full program , that program is executed into output and error, both flow back into history — and repeating this loop is what the probability and pass@k formulas measure.


Equipment checklist

Test yourself — reveal only after answering aloud.

What does the subscript count?
The number of turns of the agent loop (turn 0, 1, 2, ...), not real seconds.
Why does carry no subscript?
The requirements never change during the loop, so there is no "before/after" version to distinguish.
How is the action chosen, and why the tilde ?
It is sampled from the model's distribution ; the tilde says the result is random, so repeated calls can differ.
What does produce, and what is ?
It applies the edit to the old code to give the new full program ; is that same program — the snapshot actually run this turn.
Does the sandbox run or ?
It runs the full program , not the bare edit (you cannot execute a diff).
In , why store and not ?
History items have the shape (code, output, error); a run must record the executed code , and has already done its job by producing .
What goes in the "system instructions" slot of ?
Fixed house rules applied every turn, e.g. "You are a coding assistant, output only runnable Python, ask if unsure" — separate from the task .
Why is raised to the power ?
All independent attempts must fail; multiplying equal failure chances gives an exponent.
Compute for , .
, i.e. 78.4%.
What is the valid range of in pass@k, and what happens outside it?
You need ; if then and the metric is undefined, so you always generate samples first.
What does average over in pass@k, and how do you compute it?
Over all problems in the benchmark; score each problem separately, then take the plain mean .