Dynamic Scaffolding
also known as Adaptive Prompting, Just-in-Time Context
Inject task-specific scaffolding (examples, hints, schemas) into the prompt only when the task type warrants it.
Context
A general-purpose agent handles a wide range of task types in one product — answering free-text questions, writing or refactoring code, querying databases, transforming structured documents. Some of those tasks benefit a lot from extra material in the prompt such as worked examples, output schemas, or domain hints, while others are trivial and need none of it. The same prompt is shared across every request unless the team does something about it.
Problem
If the prompt always carries the full scaffolding library, easy requests waste tokens on examples they never needed and sometimes the irrelevant examples push the model toward a wrong shape of answer. If the prompt always carries nothing, the model under-performs on the hard cases that genuinely benefit from few-shot examples or explicit schemas. A single static prompt forces the team to choose between overshooting cost on easy tasks and undershooting quality on hard ones.
Forces
- Detection of when scaffolding helps is itself a problem.
- Scaffolding library curation effort.
- Compositional scaffolding (multiple scaffolds in one prompt) interacts unpredictably.
Example
A general-purpose coding assistant carries 4k tokens of examples, schemas, and hints in its prompt for every request, including 'rename this variable'. The scaffolding burns tokens on trivial tasks and is sometimes misleading. The team uses Dynamic Scaffolding: a lightweight classifier identifies the task type and only injects the relevant scaffolding — schemas for SQL tasks, refactor exemplars for refactor tasks, nothing extra for renames. Token cost drops on easy tasks and hard tasks get richer help than before.
Diagram
Solution
Therefore:
Maintain a library of scaffolds (few-shot examples, schemas, hints) keyed by task type or feature. At runtime, classify the task and inject the matching scaffolds. Audit which scaffolds fired per request.
What this pattern forbids. Scaffolds load only on matching task classification; default tasks see the bare prompt.
The smaller patterns that complete this one —
- usesRouting★★— Classify an incoming request and dispatch it to the specialist (lane / agent / model) best suited to handle it.
And the patterns that stand alongside it, or against it —
- complementsContext Window Packing★★— Choose what fits in the context window each turn given a fixed token budget.
- complementsAgent Skills★— Package author-time procedures (markdown + optional resources) the agent loads on demand for specific task types.
- complementsPrompt/Response Optimiser★★— At runtime, transform user inputs and model outputs into standardised, template-aligned prompts and responses against predefined constraints, so the agent and its downstream consumers see consistent shapes.
Neighbourhood
Click any neighbour to follow the language. Scroll to zoom, drag to pan.