liveBook · Manning

Chapter 5: Resampler: Reliability through repeated sampling

What you will learn in chapter 5 of Agent Design Patterns

This introduction frames stochastic model output as a reliability risk at code–AI interfaces and introduces Resampler as a retry-and-check loop that can both constrain and exploit variation.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction frames stochastic model output as a reliability risk at code–AI interfaces and introduces Resampler as a retry-and-check loop that can both constrain and exploit variation.

Key terms: probabilistic sampling, code–AI interfaces, orchestration code, MathSolver, regular expression, <answer>…</answer>, Resampler pattern, intelligent element, IE, crucial criterion

5.1 The problem: Random, unreliable, constraint-violating outputs

This section explains how stochastic AI outputs create reliability problems and how repeated sampling against criteria can enforce desired properties or search for solution trajectories.

Key terms: stochasticity, probabilistic sampling, random sampling, deterministic, seed, pseudorandomness, Resampler pattern, criteria, resampling criteria, IEs

5.2 How the Resampler pattern works

This section explains how the Resampler pattern repeatedly samples a stochastic worker until an assessor accepts a candidate or a trial limit triggers failure.

Key terms: Resampler, worker IE, assessor, criterion satisfaction, trial, candidate output, reliance on stochasticity, iterativity, absence of material feedback, criterion assessment

5.2.1 Tradeoffs

This section contrasts the reliability benefits and costs of constraint-enforcing Resamplers with the capability benefits of stochasticity-using Resamplers.

Key terms: stochasticity-constraining configuration, stochasticity-using configuration, IEs, criterion assessor, reliability, interpretability

5.2.2 When and where to use Resampler

This section identifies appropriate Resampler uses, maps each use to an assessor, and warns against stochastic resampling for security or costly solution discovery.

Key terms: Resampler, criterion satisfaction assessor, regular expression, parser, errand, IE, security guardrail, information leak, stochastic chance, reverse invocation

5.2.3 How Resampler works with other patterns

This section compares Resampler with Guardrail and the Refiner-meta pattern, explaining their relationship and why a Resampler can be the safer, cheaper choice for small-scale reliability.

Key terms: Resampler, Guardrail, Resampling Guardrail, Refiner-meta pattern, Refiner, criterion assessor, worker IE, stochasticity of the IE, reliability, small scale

5.3.1 Resampling guardrails

This section explains how combining repeated sampling with guardrails can retry stochastic outputs until one complies, while identifying cases such as security screening where retries are unsafe.

Key terms: Resampling Guardrail, Guardrail, Resampler, worker agent, information elements, IEs, sequential guardrail, parallel guardrail, streamed resampling guardrail, AFD

5.3.2 Input-stochastic resamplers

This section explains how input-stochastic resamplers create output variety by randomly augmenting each trial’s input, while warning against their use for factually exact workloads.

Key terms: input-stochastic resampler, IEs, worker IE, post-training, prompt engineering, random augmentation, resampler trial, input stochasticity, random augmentations, input payload

5.4.1 Regex-powered reasoning reliability resampler

This section shows how to wrap a reasoning step in a Resampler that uses a regular expression to accept only outputs containing a clear final answer.

Key terms: reasoning step, reasoner IE, output budget, reliability, Resampler, assessment element, regular expression, valid final answer, <answer>(.*)</answer>, maximum permissible reasoning length

5.4.2 Style enforcement resampler

This subsection applies a Resampler to produce brief, neutral email summaries by rejecting nonconforming generations and regenerating them rather than editing them afterward.

Key terms: style enforcement resampler, factual bias, neutral tone, brevity, Resampler, neutrality, style conformity assessment, regenerating the summary, summarizer, style assessors

5.4.3 Chemical reaction chain discovery

This subsection shows how an input-stochastic resampler can discover varied chemical reaction chains by randomly presampling reactants before each model trial.

Key terms: stochasticity-using resampler, input-stochastic resampler, presampling, reactants, worker IE, reaction chain, target compound, reaction representation format, target compound as one of its products, resampling

5.5 Summary

This summary explains how the Resampler pattern uses repeated independent trials to turn generative-model randomness into more reliable or creatively diverse agent outputs.

Concepts explained in this chapter

← Chapter 4: Guardrail: A gating mechanism to boost reliability Chapter 6: Voter: Leveraging stochasticity for improved outputs →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.