DRYL COMPONENTS
Color mode: System — switch to light
2.20.1
Agents

Structured Generation

AI-aware

DrylAiGenerate<T> turns a stream of JSON into a growing, typed object — and renders your Blazor components against it while the model is still writing.

How it works

Structured output usually means: wait for the whole JSON, deserialize, then render. DRYL doesn't wait. A tolerant partial reader turns every chunk into a growing typed snapshotValue, IsComplete, State and the Raw text — so the surface assembles itself as tokens arrive: image, badges, rating, timeline, donut chart.

Where the innovation lies: progressive materialization of a typed object. You render against snap.Value?.Field and each part appears the moment the model commits it — no spinner-then-snap, no intermediate DTOs.

csharp
// Cache the stream in a field so the reference stays stable across renders.
IAsyncEnumerable<string> stream =
    Runner.GenerateStreamingAsync<Recipe>(agent, session, prompt, aiKey: "recipe");
razor
<DrylAiGenerate T="Recipe" Source="stream" Key="recipe">
    <ChildContent Context="snap">
        @if (snap.Value?.Title is { } title) { <h3>@title</h3> }
        @* badges, rating, timeline, donut … each fills in as tokens arrive *@
    </ChildContent>
</DrylAiGenerate>
Keep the source reference stable
DrylAiGenerate restarts whenever Source changes by reference. Cache the IAsyncEnumerable<string> in a field — never bind a computed property that produces a fresh stream on every render.

Throttling the render cadence

A fast model can emit tokens every few milliseconds. Naively that means one Blazor Server re-render — and one full re-parse of the buffer — per token, flooding the circuit. The ThrottleMs parameter caps that: token bursts are coalesced so the surface re-renders at most once per ThrottleMs, while text and lists still grow smoothly.

  • Default is 66 (~15fps) — a good balance of liveness and load.
  • 0 renders on every token — maximum liveness, maximum cost.
  • A slow stream is unaffected: if tokens already arrive slower than the budget, each one still renders. Throttling only ever reduces renders during fast bursts.
  • The final snapshot always renders — the tail is never dropped, so the completed object is never truncated.
Try it live below
The demo exposes a ThrottleMs slider. The simulated stream ticks about every 24 ms, so drag it from 0 up to 120 — even mid-generation — and watch the raw-output panel and timeline update in coarser steps as the budget grows.

Structured streaming with DrylAiGenerate<T>

The model emits JSON for your type — and DRYL streams it straight into live Blazor components. A tolerant partial reader produces a growing typed snapshot on every chunk, so the recipe below assembles itself while the AI writes: image, badges, rating, timeline, donut chart. Open the raw-output panel to watch the JSON that drives it.

66
Max ms between streaming re-renders. 0 renders every token; higher coalesces fast bursts. Try 0 vs 120 while generating.
An unhandled error has occurred. Reload x

Reconnecting to the server…

Attempt /

Next try in s