Skip to content

Commit 11a2996

Browse files
Backport: docs: update v6 announcement post with new features (#9877)
This is an automated backport of #9873 to the release-v5.0 branch. Co-authored-by: Nico Albanese <49612682+nicoalbanese@users.noreply.github.com>
1 parent b88e215 commit 11a2996

File tree

1 file changed

+177
-1
lines changed
  • content/docs/01-announcing-ai-sdk-6-beta

1 file changed

+177
-1
lines changed

content/docs/01-announcing-ai-sdk-6-beta/index.mdx

Lines changed: 177 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ npm install ai@beta @ai-sdk/openai@beta @ai-sdk/react@beta
4141

4242
## What's New in AI SDK 6?
4343

44-
AI SDK 6 introduces three flagship features (with more to come soon!):
44+
AI SDK 6 introduces several features (with more to come soon!):
4545

4646
### Agent Abstraction
4747

@@ -51,6 +51,14 @@ A new unified interface for building agents with full control over execution flo
5151

5252
Request user confirmation before executing tools, enabling native human-in-the-loop patterns.
5353

54+
### Structured Output (Stable)
55+
56+
Generate structured data alongside tool calling with `generateText` and `streamText` - now stable and production-ready.
57+
58+
### Reranking Support
59+
60+
Improve search relevance by reordering documents based on their relationship to a query using specialized reranking models.
61+
5462
### Image Editing Support
5563

5664
Native support for image editing (coming soon).
@@ -243,6 +251,174 @@ const { messages, addToolApprovalResponse } = useChat({
243251
});
244252
```
245253

254+
## Structured Output (Stable)
255+
256+
AI SDK 6 stabilizes structured output support for agents, enabling you to generate structured data alongside multi-step tool calling.
257+
258+
Previously, you could only generate structured outputs with `generateObject` and `streamObject`, which didn't support tool calling. Now `ToolLoopAgent` (and `generateText` / `streamText`) can combine both capabilities using the `output` parameter:
259+
260+
```typescript
261+
import { Output, ToolLoopAgent, tool } from 'ai';
262+
import { openai } from '@ai-sdk/openai';
263+
import { z } from 'zod';
264+
265+
const agent = new ToolLoopAgent({
266+
model: openai('gpt-4o'),
267+
tools: {
268+
weather: tool({
269+
description: 'Get the weather in a location',
270+
inputSchema: z.object({
271+
city: z.string(),
272+
}),
273+
execute: async ({ city }) => {
274+
return { temperature: 72, condition: 'sunny' };
275+
},
276+
}),
277+
},
278+
output: Output.object({
279+
schema: z.object({
280+
summary: z.string(),
281+
temperature: z.number(),
282+
recommendation: z.string(),
283+
}),
284+
}),
285+
});
286+
287+
const { output } = await agent.generate({
288+
prompt: 'What is the weather in San Francisco and what should I wear?',
289+
});
290+
// The agent calls the weather tool AND returns structured output
291+
console.log(output);
292+
// {
293+
// summary: "It's sunny in San Francisco",
294+
// temperature: 72,
295+
// recommendation: "Wear light clothing and sunglasses"
296+
// }
297+
```
298+
299+
### Output Types
300+
301+
The `Output` object provides multiple strategies for structured generation:
302+
303+
- **`Output.object()`**: Generate structured objects with Zod schemas
304+
- **`Output.array()`**: Generate arrays of structured objects
305+
- **`Output.choice()`**: Select from a specific set of options
306+
- **`Output.text()`**: Generate plain text (default behavior)
307+
308+
### Streaming Structured Output
309+
310+
Use `agent.stream()` to stream structured output as it's being generated:
311+
312+
```typescript
313+
import { ToolLoopAgent, Output } from 'ai';
314+
import { openai } from '@ai-sdk/openai';
315+
import { z } from 'zod';
316+
317+
const profileAgent = new ToolLoopAgent({
318+
model: openai('gpt-4o'),
319+
instructions: 'Generate realistic person profiles.',
320+
output: Output.object({
321+
schema: z.object({
322+
name: z.string(),
323+
age: z.number(),
324+
occupation: z.string(),
325+
}),
326+
}),
327+
});
328+
329+
const { partialOutputStream } = await profileAgent.stream({
330+
prompt: 'Generate a person profile.',
331+
});
332+
333+
for await (const partial of partialOutputStream) {
334+
console.log(partial);
335+
// { name: "John" }
336+
// { name: "John", age: 30 }
337+
// { name: "John", age: 30, occupation: "Engineer" }
338+
}
339+
```
340+
341+
### Support in `generateText` and `streamText`
342+
343+
Structured outputs are also supported in `generateText` and `streamText` functions, allowing you to use this feature outside of agents when needed.
344+
345+
<Note>
346+
When using structured output with `generateText` or `streamText`, you must
347+
configure multiple steps with `stopWhen` because generating the structured
348+
output is itself a step. For example: `stopWhen: stepCountIs(2)` to allow tool
349+
calling and output generation.
350+
</Note>
351+
352+
## Reranking Support
353+
354+
AI SDK 6 introduces native support for reranking, a technique that improves search relevance by reordering documents based on their relationship to a query.
355+
356+
Unlike embedding-based similarity search, reranking models are specifically trained to understand query-document relationships, producing more accurate relevance scores:
357+
358+
```typescript
359+
import { rerank } from 'ai';
360+
import { cohere } from '@ai-sdk/cohere';
361+
362+
const documents = [
363+
'sunny day at the beach',
364+
'rainy afternoon in the city',
365+
'snowy night in the mountains',
366+
];
367+
368+
const { ranking } = await rerank({
369+
model: cohere.reranking('rerank-v3.5'),
370+
documents,
371+
query: 'talk about rain',
372+
topN: 2,
373+
});
374+
375+
console.log(ranking);
376+
// [
377+
// { originalIndex: 1, score: 0.9, document: 'rainy afternoon in the city' },
378+
// { originalIndex: 0, score: 0.3, document: 'sunny day at the beach' }
379+
// ]
380+
```
381+
382+
### Structured Document Reranking
383+
384+
Reranking also supports structured documents, making it ideal for searching through databases, emails, or other structured content:
385+
386+
```typescript
387+
import { rerank } from 'ai';
388+
import { cohere } from '@ai-sdk/cohere';
389+
390+
const documents = [
391+
{
392+
from: 'Paul Doe',
393+
subject: 'Follow-up',
394+
text: 'We are happy to give you a discount of 20% on your next order.',
395+
},
396+
{
397+
from: 'John McGill',
398+
subject: 'Missing Info',
399+
text: 'Sorry, but here is the pricing information from Oracle: $5000/month',
400+
},
401+
];
402+
403+
const { rerankedDocuments } = await rerank({
404+
model: cohere.reranking('rerank-v3.5'),
405+
documents,
406+
query: 'Which pricing did we get from Oracle?',
407+
topN: 1,
408+
});
409+
410+
console.log(rerankedDocuments[0]);
411+
// { from: 'John McGill', subject: 'Missing Info', text: '...' }
412+
```
413+
414+
### Supported Providers
415+
416+
Several providers offer reranking models:
417+
418+
- [Cohere](/providers/ai-sdk-providers/cohere#reranking-models)
419+
- [Amazon Bedrock](/providers/ai-sdk-providers/amazon-bedrock#reranking-models)
420+
- [Together.ai](/providers/ai-sdk-providers/togetherai#reranking-models)
421+
246422
## Image Editing Support
247423

248424
Native support for image editing and generation workflows is coming soon. This will enable:

0 commit comments

Comments
 (0)