Skip to content

Lesson 3 of 9 · 5 min read

Determinism Is a Setting, Not a Guarantee

Free lessonReviewed By the AIAgentInterviews editorial team
Reading position
In this lesson

TL;DR: Temperature 0 picks the most likely token every time, which makes output repeatable when one token is clearly ahead and still flips when two are nearly tied, because batching and cache reuse change floating-point sums on real servers. Use low temperature for tool calls, extraction and routing, a seed when you want variety that you can replay, and higher temperature only to generate candidates something else will judge. Then design around the residual: unit tests run against a scripted model, and evals run each task several times and report a rate.

After this lesson, you should be able to explain what temperature, top-p and a seed each change, pick settings for each kind of step in an agent, say why identical requests at temperature 0 can still differ, and state what that means for how you test and evaluate.

Before you read

Commit to an answer now. The lesson that follows explains it, and having guessed first, even wrongly, makes the explanation easier to remember.

  1. 1A teammate says the agent is deterministic because every call uses temperature 0, so one green run of the eval is enough to ship. Which part of that is wrong?

From probabilities to one token

At every position the model produces a score for every token in its vocabulary. Sampling turns those scores into one choice. The settings you pass change that step and nothing else:

SettingWhat it doesEffect on an agent step
TemperatureDivides every score before they become probabilities. Low sharpens toward the top token; high flattensLow for decisions with one right answer; high only to produce varied candidates
Top-pKeeps the smallest set of top tokens whose probabilities add to p, then samples among themCuts the long tail of unlikely tokens; useful with temperature above 0
Top-kKeeps the k most likely tokensA fixed-size cut; less common on hosted APIs
SeedFixes the random drawSame seed, same settings, same prefix: the same sample, when the server supports it
Temperature 0Always take the top token (greedy decoding)Repeatable when one token is clearly ahead

Here is the pipeline on an invented distribution, so you can see each knob move the numbers:

import math, random

def probs(scores, temperature):
    if temperature <= 0:                      # greedy: all mass on the top
        top = max(scores, key=scores.get)
        return {t: (1.0 if t == top else 0.0) for t in scores}
    scaled = {t: s / temperature for t, s in scores.items()}
    m = max(scaled.values())
    ex = {t: math.exp(s - m) for t, s in scaled.items()}
    z = sum(ex.values())
    return {t: v / z for t, v in ex.items()}

def top_p(p, keep):
    kept, total = {}, 0.0
    for t, v in sorted(p.items(), key=lambda kv: -kv[1]):
        kept[t] = v
        total += v
        if total >= keep:
            break
    z = sum(kept.values())
    return {t: v / z for t, v in kept.items()}

def sample(p, rng):
    r, acc = rng.random(), 0.0
    for t, v in p.items():
        acc += v
        if r <= acc:
            return t
    return t

scores = {"Canberra": 4.0, "Sydney": 2.2, "Melbourne": 1.1, "the": 0.3}
for T in (0, 0.5, 1.0, 1.5):
    p = probs(scores, T)
    print(T, round(p["Canberra"], 2), round(p["Sydney"], 2))

p = top_p(probs(scores, 1.0), 0.9)
print(sorted(p))  # => ['Canberra', 'Sydney']

draws = [sample(probs(scores, 1.0), random.Random(7)) for _ in range(3)]
print(draws)  # => ['Canberra', 'Canberra', 'Canberra']

At temperature 0.5 the right answer has almost all the mass. At 1.5 the wrong answers hold roughly a third between them, which is fine for a brainstorm and a disaster for a tool argument. Top-p at 0.9 keeps only the two plausible tokens and drops the tail. A fixed seed gives the same draw every time, which is what the seed parameter on hosted APIs does when the server honours it.

Which setting for which step

An agent is many model calls, and they are not all the same kind of call:

StepSettingsWhy
Tool selection and argumentsTemperature 0 or near itOne right answer; randomness only adds wrong calls
Structured output, routing, classificationTemperature 0, structured output mode where availableSame reason, and the schema constrains the rest
Final prose answerLow to moderateSlight variety is acceptable; wandering is not
Candidate generation for a verifierHigher, with top-p, often several samplesYou want different attempts because something else will pick the best (Reflection with an External Signal)
EvalsYour production settings, many runsMeasure what users will get, not a tuned-down version

The last row is the one teams skip. Running evals at temperature 0 when production runs at 0.7 measures a system nobody ships.

Why temperature 0 still differs

Greedy decoding is deterministic in arithmetic. Serving is not. Two identical requests to a hosted model can be batched with different neighbours, scheduled onto different hardware, or served with and without a cached prefix. Each of those changes the order in which floating-point numbers are added, and floating-point addition is not exactly associative. The probabilities come out slightly different.

Most of the time that does not matter: the top token is far ahead and the choice is the same. When two tokens are nearly tied, the tiny shift flips the choice, and because every later token conditions on it, the rest of the output diverges. "Nearly tied" is common at exactly the points an agent cares about: which of two similar tools to call, whether to stop or take one more step, which of two plausible ids to use.

SAME REQUEST, TWO SERVER STATES
Where a greedy choice flips

One token clearly ahead

Scores

0.89 vs 0.11

Batched differently

0.8882 vs 0.1118

Same token

choice unchanged

Outcome, safe: Repeatable in practice

Two tokens nearly tied

Scores

0.501 vs 0.499

Batched differently

0.4996 vs 0.5004

Other token

the rest diverges

Outcome, unsafe: Flips between identical calls

A seed narrows this but does not remove it: it fixes your random draw, not the server's arithmetic. Providers describe seeded output as best-effort for this reason, and several expose a fingerprint of the serving configuration so you can at least tell when the backend changed under you (checked November 2026).

What this forces on testing and evaluation

Once you accept that the model is a noisy component, the engineering follows.

Unit tests of the harness do not call a model. They call a scripted stand-in that returns fixed replies, so the loop, the dispatcher, the budgets and the error paths are tested deterministically (Testing Agents with a Scripted Model). A test that depends on a live model's exact words is a flaky test by construction.

Evals of behaviour run each task several times and report a rate with its denominator: 46 of 50 tasks passed in all 5 runs, or pass^5 of 0.92 (pass@k and pass^k). A single run of a single task cannot tell a real regression from a near-tie that flipped. A change that moves the rate by less than its noise has not been shown to do anything (Regressions in a Non-Deterministic System).

Replay for debugging records the model's actual replies from a run and feeds them back, so you can step through a failure without the model changing its mind on the second look. Reading a Trace covers what to record.

Terms you will hear

TermWhat people sayWhat it means in the harness
Greedy decoding"temperature 0"Always take the most probable token; repeatable only when the top token is clearly ahead
Seed"reproducible mode"Fixes the sampling draw; does not fix the server's arithmetic
Top-p"nucleus sampling"Sample only from the smallest set of tokens covering probability p
Near-tie flip"it changed its mind"Two candidates close enough that serving noise swaps the choice
System fingerprint"backend version"A provider value that changes when the serving configuration changes

Say it in 30 seconds

"Temperature, top-p and a seed decide how the model turns probabilities into one token. I run tool calls and structured output near temperature 0, keep higher temperature for generating candidates a verifier will judge, and run evals at the production settings. Temperature 0 is greedy decoding, not determinism: batching and cache reuse change the floating-point sums, so near-tied tokens flip between identical calls. That is why unit tests use a scripted model and evals run each task several times and report a rate."

Check yourself

Answer aloud or on paper before revealing. Producing the explanation unaided is exactly what a panel listens for.

  1. 1Which step of a support agent should run at the highest temperature, and what must sit beside it?

  2. 2Your eval passed 10 of 10 tasks yesterday and 8 of 10 today with no code change. Name two explanations and how you would tell them apart.

  3. 3Why is a harness unit test that asserts on a live model's exact reply a bad test, even at temperature 0?

Practise it as an interviewer asks it

Related lessons