new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

AI SDK · Cookbook · all subjects

streaming and ui patterns

5 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

ToolLoopAgent streaming example

```ts const agent = new ToolLoopAgent({ model: __MODEL__, instructions: 'You are a creative storyteller.', }); const stream = agent.stream({ prompt: 'Tell me a short story about a time traveler.', }); for await (const chunk of stream.textStream) { process.stdout.write(chunk); } ```

streamText function for streaming text generation

The AI SDK provides a streamText function that enables streaming text generation in under 10 lines of code. Import streamText from 'ai', call it with model and prompt parameters, then iterate over the textStream using a for-await loop to process each text part as it arrives.

Streaming UI displays response parts as they become available

Streaming user interfaces can transmit and display parts of the LLM response as they become available, rather than waiting for the complete response. This allows users to see output faster, which is especially beneficial for long-running LLM generations that might otherwise require users to wait 5-40 seconds staring at loading spinners.

Blocking UI waits for full response before displaying

A blocking UI waits until the entire response is available from the LLM before displaying anything to the user. This can result in poor user experience when generating long outputs, as users must wait for the complete generation before any content appears.

When to use streaming vs smaller faster models

Streaming interfaces aren't always necessary or beneficial. If you can achieve your desired functionality using a smaller, faster model without streaming, this approach often leads to simpler and more manageable development processes. Consider streaming primarily when working with larger language models or when responsiveness is critical.

Give your agent this brain