Loading...
Loading...
Comprehensive guide to AI SDK v6 for agent development, tool definitions, multi-step agentic workflows, and result extraction patterns
npx skill4agent add skillrecordings/support ai-sdk// ✅ Standard Zod 4 import
import { z } from 'zod'| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Provider Setup | CRITICAL | |
| 2 | Text Generation | HIGH | |
| 3 | Tool Definitions | HIGH | |
| 4 | Multi-Step Agents | HIGH | |
| 5 | Result Extraction | MEDIUM | |
| 6 | Message Types | MEDIUM | |
| 7 | Error Handling | MEDIUM | |
// ❌ v5 patterns that FAIL in v6:
import { type CoreMessage } from 'ai' // → ModelMessage
parameters: z.object({...}) // → inputSchema
maxSteps: 5 // → stopWhen: stepCountIs(5)
call.args // → call.input
call.toolResult // → step.toolResults[].outputprovider-gatewayimport { generateText } from 'ai'
const result = await generateText({
model: 'anthropic/claude-opus-4-5', // AI Gateway string
prompt: 'Hello',
})generate-basictool-input-schematool-definitionimport { tool } from 'ai'
import { z } from 'zod'
const myTool = tool({
description: 'What this does',
inputSchema: z.object({ // ✅ inputSchema not parameters
param: z.string().describe('Description'),
}),
execute: async ({ param }) => {
return { result: 'done' }
},
})agent-stop-whenagent-multi-stepimport { generateText, stepCountIs } from 'ai'
const result = await generateText({
model: 'anthropic/claude-opus-4-5',
messages,
tools: agentTools,
stopWhen: stepCountIs(5), // ✅ not maxSteps: 5
})result-tool-access// ✅ Correct v6 pattern
const toolCalls = result.steps.flatMap((step) => {
const resultsMap = new Map(
(step.toolResults || []).map((r) => [r.toolCallId, r.output])
)
return (step.toolCalls || []).map((tc) => ({
name: tc.toolName,
args: tc.input, // ✅ input not args
result: resultsMap.get(tc.toolCallId), // ✅ from toolResults
}))
})message-model-messageimport { type ModelMessage } from 'ai' // ✅ not CoreMessage
const messages: ModelMessage[] = [
{ role: 'user', content: 'Hello' },
]rules/provider-gateway.md
rules/tool-input-schema.md
rules/agent-stop-when.md
rules/result-tool-access.md
rules/_sections.mdimport {
generateText,
generateObject,
streamText,
streamObject,
tool,
stepCountIs,
hasToolCall,
type ModelMessage,
} from 'ai'
import { z } from 'zod' // Zod 4.xanthropic/claude-opus-4-5
anthropic/claude-sonnet-4
openai/gpt-4o
google/gemini-2.0-flashAI_GATEWAY_API_KEY