diff --git a/docs/ai-chat/actions.mdx b/docs/ai-chat/actions.mdx index dcbfd6e76ca..79dfd5ed773 100644 --- a/docs/ai-chat/actions.mdx +++ b/docs/ai-chat/actions.mdx @@ -45,7 +45,7 @@ export const myChat = chat.agent({ }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` diff --git a/docs/ai-chat/anatomy.mdx b/docs/ai-chat/anatomy.mdx index 18d6360ece1..60681f377f0 100644 --- a/docs/ai-chat/anatomy.mdx +++ b/docs/ai-chat/anatomy.mdx @@ -65,7 +65,7 @@ export const myAgent = chat.agent({ run: async ({ messages, tools, signal, streamText }) => streamText({ tools, - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, stopWhen: stepCountIs(15), diff --git a/docs/ai-chat/backend.mdx b/docs/ai-chat/backend.mdx index e634d8d9d13..eedb1a1738d 100644 --- a/docs/ai-chat/backend.mdx +++ b/docs/ai-chat/backend.mdx @@ -37,7 +37,7 @@ export const simpleChat = chat.agent({ id: "simple-chat", run: async ({ messages, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), system: "You are a helpful assistant.", messages, abortSignal: signal, @@ -63,7 +63,7 @@ export const simpleChat = chat.agent({ id: "simple-chat", run: async ({ messages, signal, streamText }) => streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, stopWhen: stepCountIs(15), @@ -108,7 +108,7 @@ async function runAgentLoop(messages: ModelMessage[], streamText: ChatStreamText // ... agent logic, tool calls, etc. const result = streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, stopWhen: stepCountIs(15), }); @@ -129,7 +129,7 @@ export const myChat = chat.agent({ // This data part will be in responseMessage.parts in onTurnComplete writer.write({ type: "data-metadata", - data: { turn, model: "gpt-4o", timestamp: Date.now() }, + data: { turn, model: "gpt-6-luna", timestamp: Date.now() }, }); }, onTurnComplete: async ({ responseMessage }) => { @@ -143,7 +143,7 @@ export const myChat = chat.agent({ data: { searchResults: results }, }); - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -214,7 +214,7 @@ export const myChat = chat.agent({ run: async ({ messages, tools, signal, streamText }) => streamText({ tools, - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, stopWhen: stepCountIs(15), @@ -239,7 +239,7 @@ Use [AI Prompts](/ai/prompts) to manage your system prompt as versioned, overrid ```ts import { chat } from "@trigger.dev/sdk/ai"; import { prompts } from "@trigger.dev/sdk"; -import { createProviderRegistry } from "ai"; +import { createProviderRegistry, stepCountIs } from "ai"; import { anthropic } from "@ai-sdk/anthropic"; import { z } from "zod"; @@ -247,8 +247,8 @@ const registry = createProviderRegistry({ anthropic }); const systemPrompt = prompts.define({ id: "my-chat-system", - model: "anthropic:claude-sonnet-4-5", - config: { temperature: 0.7 }, + model: "anthropic:claude-sonnet-5-5", + config: { maxOutputTokens: 1024 }, variables: z.object({ name: z.string() }), content: `You are a helpful assistant for {{name}}.`, }); @@ -302,7 +302,7 @@ export const myChat = chat.agent({ id: "my-chat", run: async ({ messages, signal, stopSignal, cancelSignal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, // Handles both stop and cancel stopWhen: stepCountIs(15), @@ -330,7 +330,7 @@ export const myChat = chat.agent({ }); }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -344,7 +344,7 @@ export const myChat = chat.agent({ id: "my-chat", run: async ({ messages, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, onFinish: ({ isAborted }) => { @@ -397,7 +397,7 @@ export const myChat = chat.agent({ id: "my-chat", run: async ({ messages, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, tools: { sendEmail }, abortSignal: signal, @@ -636,7 +636,7 @@ export const myChat = chat.agent({ ]; }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -663,7 +663,7 @@ chat.agent({ run: async ({ messages, signal, streamText }) => { // Single-response agent — exit after this turn. chat.endRun(); - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -684,7 +684,7 @@ Use this when the agent knows its work is done (budget exhausted, goal achieved, chat.agent({ id: "budgeted-agent", run: async ({ messages, signal }) => - streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }), + streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }), // onBeforeTurnComplete carries the same fields as onTurnComplete, including // `usage`, and still runs while the response stream is open. onBeforeTurnComplete: async ({ chatId }) => { @@ -736,7 +736,7 @@ Override how long the run stays suspended waiting for the next message. Call fro ```ts run: async ({ messages, signal, streamText }) => { chat.setTurnTimeout("2h"); // Wait longer for this conversation - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, ``` @@ -747,7 +747,7 @@ Override how long the run stays idle (active, using compute) after each turn: ```ts run: async ({ messages, signal, streamText }) => { chat.setIdleTimeoutInSeconds(60); // Stay idle for 1 minute - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, ``` @@ -781,7 +781,7 @@ export const myChat = chat.agent({ }, }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -812,7 +812,7 @@ export const myChat = chat.agent({ sendSources: true, // Forward source citations (default: false) }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -830,7 +830,7 @@ export const myChat = chat.agent({ generateMessageId: () => uuidv7(), }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -850,7 +850,7 @@ export const myChat = chat .agent({ id: "my-chat", run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -872,7 +872,7 @@ run: async ({ messages, clientData, signal, streamText }) => { if (clientData.model?.includes("claude")) { chat.setUIMessageStreamOptions({ sendReasoning: true }); } - return streamText({ model: openai(clientData.model ?? "gpt-4o"), messages, abortSignal: signal }); + return streamText({ model: openai(clientData.model ?? "gpt-6-luna"), messages, abortSignal: signal }); }, ``` @@ -901,7 +901,7 @@ export const manualChat = task({ queue: { concurrencyLimit: 10 }, run: async (payload: ChatTaskPayload) => { const result = streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages: payload.messages, stopWhen: stepCountIs(15), }); diff --git a/docs/ai-chat/background-injection.mdx b/docs/ai-chat/background-injection.mdx index 69bb7beb33b..740a4841faa 100644 --- a/docs/ai-chat/background-injection.mdx +++ b/docs/ai-chat/background-injection.mdx @@ -87,7 +87,7 @@ const registry = createProviderRegistry({ anthropic }); const selfReviewPrompt = prompts.define({ id: "self-review", - model: "anthropic:claude-haiku-4-5", + model: "anthropic:claude-haiku-5-5", content: `You are a conversation quality reviewer. Analyze the assistant's most recent response. Focus on: @@ -107,7 +107,7 @@ export const myChat = chat.agent({ const resolved = await selfReviewPrompt.resolve({}); const review = await generateObject({ - model: registry.languageModel(resolved.model ?? "anthropic:claude-haiku-4-5"), + model: registry.languageModel(resolved.model ?? "anthropic:claude-haiku-5-5"), ...resolved.toAISDKTelemetry(), system: resolved.text, prompt: messages @@ -152,7 +152,7 @@ export const myChat = chat.agent({ }); ``` -The self-review runs on `claude-haiku-4-5` (fast, cheap) in the background. If the user sends another message before it completes, the coaching is still injected, because `chat.inject()` persists across the idle wait. +The self-review runs on `claude-haiku-5-5` (fast, cheap) in the background. If the user sends another message before it completes, the coaching is still injected, because `chat.inject()` persists across the idle wait. ## Other use cases @@ -173,7 +173,7 @@ export const myChat = chat.agent({ chat.defer(analytics.track("turn_started", { chatId, runId })); }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -200,7 +200,7 @@ export const myChat = chat.agent({ ); }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` diff --git a/docs/ai-chat/chat-local.mdx b/docs/ai-chat/chat-local.mdx index 0ae24903139..4f0dfff73f5 100644 --- a/docs/ai-chat/chat-local.mdx +++ b/docs/ai-chat/chat-local.mdx @@ -48,7 +48,7 @@ export const myChat = chat.agent({ userContext.messageCount++; return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), system: `Helping ${userContext.name} (${userContext.plan} plan).`, messages, abortSignal: signal, @@ -117,7 +117,7 @@ export const myChat = chat.agent({ }, run: async ({ messages, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, tools: { analyzeData }, abortSignal: signal, diff --git a/docs/ai-chat/compaction.mdx b/docs/ai-chat/compaction.mdx index e7d1ed0074f..622d8b71c7f 100644 --- a/docs/ai-chat/compaction.mdx +++ b/docs/ai-chat/compaction.mdx @@ -29,7 +29,7 @@ export const myChat = chat.agent({ shouldCompact: ({ totalTokens }) => (totalTokens ?? 0) > 80_000, summarize: async ({ messages }) => { const result = await generateText({ - model: anthropic("claude-haiku-4-5"), + model: anthropic("claude-haiku-5-5"), messages: [...messages, { role: "user", content: "Summarize this conversation concisely." }], }); return result.text; @@ -84,7 +84,7 @@ export const myChat = chat.agent({ shouldCompact: ({ totalTokens }) => (totalTokens ?? 0) > 80_000, summarize: async ({ messages }) => { return generateText({ - model: anthropic("claude-haiku-4-5"), + model: anthropic("claude-haiku-5-5"), messages: [...messages, { role: "user", content: "Summarize." }], }).then((r) => r.text); }, @@ -98,7 +98,7 @@ export const myChat = chat.agent({ ], }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -192,7 +192,7 @@ export const myChat = chat.agent({ }); }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -214,7 +214,7 @@ import { z } from "zod"; // Reusable summarize fn — also used by the automatic compaction config. async function summarize(messages: ModelMessage[]) { const result = await generateText({ - model: anthropic("claude-haiku-4-5"), + model: anthropic("claude-haiku-5-5"), messages: [...messages, { role: "user", content: "Summarize this conversation concisely." }], }); return result.text; @@ -250,7 +250,7 @@ export const myChat = chat.agent({ }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -317,7 +317,10 @@ const session = chat.createSession(payload, { compaction: { shouldCompact: ({ totalTokens }) => (totalTokens ?? 0) > 80_000, summarize: async ({ messages }) => - generateText({ model: anthropic("claude-haiku-4-5"), messages }).then((r) => r.text), + generateText({ + model: anthropic("claude-haiku-5-5"), + messages: [...messages, { role: "user", content: "Summarize this conversation concisely." }], + }).then((r) => r.text), compactUIMessages: ({ uiMessages, summary }) => [ { id: generateId(), role: "assistant", parts: [{ type: "text", text: `[Summary]\n\n${summary}` }] }, @@ -328,7 +331,7 @@ const session = chat.createSession(payload, { for await (const turn of session) { const result = streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages: turn.messages, abortSignal: turn.signal, stopWhen: stepCountIs(15), @@ -353,7 +356,10 @@ const conversation = new chat.MessageAccumulator({ compaction: { shouldCompact: ({ totalTokens }) => (totalTokens ?? 0) > 80_000, summarize: async ({ messages }) => - generateText({ model: anthropic("claude-haiku-4-5"), messages }).then((r) => r.text), + generateText({ + model: anthropic("claude-haiku-5-5"), + messages: [...messages, { role: "user", content: "Summarize this conversation concisely." }], + }).then((r) => r.text), compactUIMessages: ({ summary }) => [ { id: generateId(), role: "assistant", parts: [{ type: "text", text: `[Summary]\n\n${summary}` }] }, @@ -365,7 +371,7 @@ for (let turn = 0; turn < 100; turn++) { const messages = await conversation.addIncoming(payload.messages, payload.trigger, turn); const result = streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, prepareStep: conversation.prepareStep(), // Inner-loop compaction stopWhen: stepCountIs(15), @@ -392,7 +398,10 @@ prepareStep: async ({ messages: stepMessages, steps }) => { const result = await chat.compact(stepMessages, steps, { threshold: 80_000, summarize: async (msgs) => - generateText({ model: anthropic("claude-haiku-4-5"), messages: msgs }).then((r) => r.text), + generateText({ + model: anthropic("claude-haiku-5-5"), + messages: [...msgs, { role: "user", content: "Summarize this conversation concisely." }], + }).then((r) => r.text), }); return result.type === "skipped" ? undefined : result; }, @@ -404,7 +413,10 @@ Or use the `chat.compactionStep()` factory: prepareStep: chat.compactionStep({ threshold: 80_000, summarize: async (msgs) => - generateText({ model: anthropic("claude-haiku-4-5"), messages: msgs }).then((r) => r.text), + generateText({ + model: anthropic("claude-haiku-5-5"), + messages: [...msgs, { role: "user", content: "Summarize this conversation concisely." }], + }).then((r) => r.text), }), ``` diff --git a/docs/ai-chat/custom-agents.mdx b/docs/ai-chat/custom-agents.mdx index eaa0c71733a..fb696608942 100644 --- a/docs/ai-chat/custom-agents.mdx +++ b/docs/ai-chat/custom-agents.mdx @@ -109,7 +109,7 @@ export const myChat = chat }); const result = streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages: turn.messages, abortSignal: turn.signal, stopWhen: stepCountIs(15), @@ -230,7 +230,7 @@ For more control, you can do each step manually: ```ts for await (const turn of session) { const result = streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages: turn.messages, abortSignal: turn.signal, stopWhen: stepCountIs(15), @@ -267,7 +267,7 @@ and aborts that turn as normal. ```ts trigger/my-chat.ts for await (const turn of session) { const result = streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages: turn.messages, abortSignal: turn.signal, // fires on a user stop OR a run cancel stopWhen: stepCountIs(15), @@ -442,7 +442,7 @@ export const myChat = chat.customAgent({ const combinedSignal = AbortSignal.any([runSignal, stop.signal]); const result = streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: combinedSignal, stopWhen: stepCountIs(15), diff --git a/docs/ai-chat/error-handling.mdx b/docs/ai-chat/error-handling.mdx index 002542ad9b1..37db7eb2757 100644 --- a/docs/ai-chat/error-handling.mdx +++ b/docs/ai-chat/error-handling.mdx @@ -38,7 +38,7 @@ export const myChat = chat.agent({ }, }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -74,7 +74,7 @@ export const myChat = chat.agent({ await db.chat.update({ where: { id: chatId }, data: { messages: uiMessages } }); }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -142,7 +142,7 @@ chat.agent({ }); }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -174,7 +174,7 @@ chat.agent({ } }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` diff --git a/docs/ai-chat/fast-starts.mdx b/docs/ai-chat/fast-starts.mdx index 88497b42b09..d5ea085c9f5 100644 --- a/docs/ai-chat/fast-starts.mdx +++ b/docs/ai-chat/fast-starts.mdx @@ -81,7 +81,7 @@ export const myChat = chat.agent({ // ... fallback initialization for non-preloaded runs }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -241,7 +241,8 @@ This is an **import-chain** problem, not a runtime one. A "we'll strip the execu id: "my-chat", run: async ({ messages, signal, streamText }) => streamText({ - model: anthropic("claude-sonnet-4-6"), + model: anthropic("claude-sonnet-5-5"), + system: "You are a helpful assistant.", messages, tools: chatTools, stopWhen: stepCountIs(10), @@ -263,7 +264,7 @@ This is an **import-chain** problem, not a runtime one. A "we'll strip the execu agentId: "my-chat", run: async ({ streamText }) => streamText({ - model: anthropic("claude-sonnet-4-6"), + model: anthropic("claude-sonnet-5-5"), system: "You are a helpful assistant.", tools: headStartTools, }), @@ -280,7 +281,7 @@ This is an **import-chain** problem, not a runtime one. A "we'll strip the execu - Use the **same model** on both sides (route handler and `chat.agent`) to avoid a tone or style shift between step 1 and step 2+. Your LLM provider keys stay server-side in your warm process — Trigger.dev never holds them in this design. + Use the **same model and system prompt** on both sides (route handler and `chat.agent`), with the same tool names and schemas. On Claude 5.5 models, step 1's thinking is bound to that system prompt and tool set, so a mismatch makes step 2 fail with a 400. Your LLM provider keys stay server-side in your warm process — Trigger.dev never holds them in this design. Mount the handler in whatever framework you use — see [Mounting in your framework](#mounting-in-your-framework) below. @@ -569,7 +570,7 @@ for await (const turn of session) { const result = turn.handover?.isFinal ? undefined : streamText({ - model: anthropic("claude-sonnet-4-6"), + model: anthropic("claude-sonnet-5-5"), messages: turn.messages, abortSignal: turn.signal, stopWhen: stepCountIs(10), @@ -593,7 +594,7 @@ if (turn === 0 && payload.trigger === "handover-prepare") { // passing originalMessages so the tool output merges into the // handed-over assistant instead of starting a new message. const result = streamText({ - model: anthropic("claude-sonnet-4-6"), + model: anthropic("claude-sonnet-5-5"), messages: conversation.modelMessages, stopWhen: stepCountIs(10), }); @@ -691,7 +692,7 @@ export async function POST(req: Request) { messages, // first-turn user history run: async ({ streamText }) => streamText({ - model: anthropic("claude-sonnet-4-6"), + model: anthropic("claude-sonnet-5-5"), system: "You are a helpful assistant.", tools: headStartTools, }), diff --git a/docs/ai-chat/frontend.mdx b/docs/ai-chat/frontend.mdx index a45ec59d4a3..f5a85cc4f29 100644 --- a/docs/ai-chat/frontend.mdx +++ b/docs/ai-chat/frontend.mdx @@ -267,7 +267,7 @@ Browser-supplied `clientData` is input, including after schema validation. Use i Pass metadata with individual messages via `sendMessage`. Per-message values are merged with transport-level client data (per-message wins on conflicts): ```ts -sendMessage({ text: "Hello" }, { metadata: { model: "gpt-4o", priority: "high" } }); +sendMessage({ text: "Hello" }, { metadata: { model: "gpt-6-luna", priority: "high" } }); ``` ### Typed client data with clientDataSchema @@ -287,7 +287,7 @@ export const myChat = chat.agent({ }), run: async ({ messages, clientData, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), system: clientData?.locale === "fr" ? "Reply in French." : "Reply in English.", messages, abortSignal: signal, diff --git a/docs/ai-chat/lifecycle-hooks.mdx b/docs/ai-chat/lifecycle-hooks.mdx index f02b24310eb..8b414214bdb 100644 --- a/docs/ai-chat/lifecycle-hooks.mdx +++ b/docs/ai-chat/lifecycle-hooks.mdx @@ -62,7 +62,7 @@ export const myChat = chat.agent({ } }, run: async ({ messages, signal }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -101,7 +101,7 @@ export const myChat = chat.agent({ // (splice partial + first user into chain, dispatch the rest). }, run: async ({ messages, signal }) => - streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }), + streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }), }); ``` @@ -157,7 +157,7 @@ export const myChat = chat.agent({ // ... non-preloaded chat-row initialization }, run: async ({ messages, signal }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -206,7 +206,7 @@ export const myChat = chat.agent({ }); }, run: async ({ messages, signal }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -245,7 +245,7 @@ export const myChat = chat.agent({ return messages; }, run: async ({ messages, signal }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, tools: chatTools, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, tools: chatTools, abortSignal: signal }); }, }); ``` @@ -305,7 +305,7 @@ export const myChat = chat.agent({ return stored; }, run: async ({ messages, signal }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -363,7 +363,7 @@ export const myChat = chat.agent({ }); }, run: async ({ messages, signal }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -398,7 +398,7 @@ export const myChat = chat.agent({ } }, run: async ({ messages, signal }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -446,7 +446,7 @@ export const myChat = chat.agent({ ]); }, run: async ({ messages, signal }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -489,7 +489,7 @@ export const myChat = chat.agent({ logger.info("Resumed", { phase: event.phase }); }, run: async ({ messages, signal }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -523,7 +523,7 @@ export const myChat = chat.agent({ await initializeChat(chatId, clientData); }, run: async ({ messages, signal }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` diff --git a/docs/ai-chat/migrating-from-a-route-handler.mdx b/docs/ai-chat/migrating-from-a-route-handler.mdx index dbfb0cdcf97..7652276e169 100644 --- a/docs/ai-chat/migrating-from-a-route-handler.mdx +++ b/docs/ai-chat/migrating-from-a-route-handler.mdx @@ -119,7 +119,7 @@ export async function POST(req: Request) { if (!session) return new Response("Unauthorized", { status: 401 }); const result = streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), system: "You are a helpful assistant.", messages: convertToModelMessages(messages), tools, @@ -148,7 +148,7 @@ export const myChat = chat.agent({ run: async ({ messages, tools, signal, streamText }) => streamText({ tools, - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), system: "You are a helpful assistant.", messages, abortSignal: signal, @@ -359,7 +359,7 @@ export const myChat = chat.agent({ run: async ({ messages, tools, signal, streamText }) => streamText({ tools, - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), system: "You are a helpful assistant.", messages, abortSignal: signal, @@ -469,7 +469,7 @@ Head Start brings the route handler back for exactly that first turn. It runs st agentId: "my-chat", run: async ({ streamText }) => streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), system: "You are a helpful assistant.", tools: headStartTools, }), diff --git a/docs/ai-chat/migrating-from-hydrate-messages.mdx b/docs/ai-chat/migrating-from-hydrate-messages.mdx index e6baa6f1bcd..24bfba0e1ab 100644 --- a/docs/ai-chat/migrating-from-hydrate-messages.mdx +++ b/docs/ai-chat/migrating-from-hydrate-messages.mdx @@ -194,7 +194,7 @@ With `hydrateMessages`, your hook was the source of truth and the runtime wrote storage: transcriptStorage, clientDataSchema: z.object({ userId: z.string() }), run: async ({ messages, signal, streamText }) => - streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }), + streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }), }); ``` diff --git a/docs/ai-chat/overview.mdx b/docs/ai-chat/overview.mdx index df8a3a9c7bd..c14d982e7ce 100644 --- a/docs/ai-chat/overview.mdx +++ b/docs/ai-chat/overview.mdx @@ -19,7 +19,7 @@ export const myChat = chat.agent({ id: "my-chat", run: async ({ messages, signal, streamText }) => streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, stopWhen: stepCountIs(15), diff --git a/docs/ai-chat/patterns/branching-conversations.mdx b/docs/ai-chat/patterns/branching-conversations.mdx index dfbeecf4ef4..371a3e6ad5d 100644 --- a/docs/ai-chat/patterns/branching-conversations.mdx +++ b/docs/ai-chat/patterns/branching-conversations.mdx @@ -97,7 +97,7 @@ export const myChat = chat.agent({ }, run: async ({ messages, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, }); diff --git a/docs/ai-chat/patterns/database-persistence.mdx b/docs/ai-chat/patterns/database-persistence.mdx index 08aec84beeb..e527ff41621 100644 --- a/docs/ai-chat/patterns/database-persistence.mdx +++ b/docs/ai-chat/patterns/database-persistence.mdx @@ -227,7 +227,7 @@ export const myChat = chat.agent({ ]); }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -298,7 +298,7 @@ export const myChat = chat.agent({ }, run: async ({ messages, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, stopWhen: stepCountIs(15), diff --git a/docs/ai-chat/patterns/human-in-the-loop.mdx b/docs/ai-chat/patterns/human-in-the-loop.mdx index 5d4254a2386..b197d3ba19d 100644 --- a/docs/ai-chat/patterns/human-in-the-loop.mdx +++ b/docs/ai-chat/patterns/human-in-the-loop.mdx @@ -76,7 +76,7 @@ export const myChat = chat.withUIMessage().agent({ tools, run: async ({ messages, tools, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, tools, abortSignal: signal, diff --git a/docs/ai-chat/patterns/native-compaction.mdx b/docs/ai-chat/patterns/native-compaction.mdx index 125751a9d8f..16a04d4f65d 100644 --- a/docs/ai-chat/patterns/native-compaction.mdx +++ b/docs/ai-chat/patterns/native-compaction.mdx @@ -77,7 +77,7 @@ export const nativePersist = chat.agent({ tools: { fetchRecord }, run: async ({ messages, chatId, tools, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, tools, abortSignal: signal, @@ -126,6 +126,10 @@ Turn 1 sends the user message and accumulates six tool results. Anthropic clears `onTurnComplete` is where persistence happens. Action turns fire `onAction` only, and a `chat.history.set()` inside `run()` is overwritten by the accumulator at turn end. See [Persistence and replay](/ai-chat/patterns/persistence-and-replay#action-turns-no-snapshot-write). + + Thinking is on by default on Claude 5.5 models, and each thinking block is bound to the conversation that came before it. Removing tool parts from earlier turns in your own code changes that history, so Anthropic can reject the next request with a 400 (`Invalid signature in thinking block`). Server-side context editing, as configured above, doesn't count as an edit. If you prune history yourself, also remove the reasoning parts from the turns you change and every turn after them. + + ## Persist OpenAI stored responses OpenAI's `store: true` keeps the thread server-side and returns a `responseId`. Pass that back as `previousResponseId` on the next turn and send only the messages since the last assistant reply; everything before it lives on OpenAI's side. @@ -156,7 +160,7 @@ export const openaiStore = chat.agent({ const outbound = native ? messagesSinceLastAssistant(messages) : messages; const result = streamText({ - model: openai("gpt-4o"), + model: openai("gpt-6-luna"), messages: outbound, abortSignal: signal, stopWhen: stepCountIs(5), @@ -197,10 +201,17 @@ const FALLBACK_ORDER: Provider[] = ["anthropic", "openai"]; type NativeState = { provider: "openai"; previousResponseId: string }; const nativeStore = new Map(); +// Retained messages follow a different history after compaction, so their thinking +// blocks no longer verify on Claude 5.5 models. Drop reasoning parts before replaying them. +function stripReasoning(message: ModelMessage): ModelMessage { + if (message.role !== "assistant" || typeof message.content === "string") return message; + return { ...message, content: message.content.filter((part) => part.type !== "reasoning") }; +} + // Provider-agnostic summary: a plain string, portable across any provider. async function summarizeConversation(messages: ModelMessage[]): Promise { const { text } = await generateText({ - model: openai("gpt-4o-mini"), + model: openai("gpt-6-luna"), messages: [ ...messages, { @@ -223,7 +234,7 @@ export const resilientChat = chat.agent({ summarize: ({ messages }) => summarizeConversation(messages), compactModelMessages: ({ modelMessages, summary }) => [ { role: "user", content: `Summary of the conversation so far:\n\n${summary}` }, - ...modelMessages.slice(-2), + ...modelMessages.slice(-2).map(stripReasoning), ], compactUIMessages: ({ uiMessages, summary }) => [ { @@ -251,7 +262,7 @@ export const resilientChat = chat.agent({ // compacted baseline (summary + recent), so raw history is not re-sent. const useHandle = native?.provider === "openai"; const result = streamText({ - model: openai("gpt-4o"), + model: openai("gpt-6-luna"), messages, abortSignal: signal, stopWhen: stepCountIs(5), @@ -269,7 +280,7 @@ export const resilientChat = chat.agent({ } return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, stopWhen: stepCountIs(5), @@ -292,6 +303,10 @@ export const resilientChat = chat.agent({ When Anthropic is down, the loop falls through to OpenAI. Because `compaction` has already reduced `messages` to a summary plus the last couple of exchanges, the switch sends the portable baseline, not megabytes of raw transcript. + + The messages that `compactModelMessages` keeps after the summary now follow a different history from the one their thinking blocks were produced in. Claude 5.5 models reject those blocks with a 400 (`Invalid signature in thinking block`), which is why the example runs the retained messages through `stripReasoning`. + + Fallback here retries a turn that hasn't started streaming yet. Once a response is streaming to the client, a mid-stream provider failure can't be swapped transparently. Surface the error and let the frontend regenerate the turn. See [Error handling](/ai-chat/error-handling). diff --git a/docs/ai-chat/patterns/persistence-and-replay.mdx b/docs/ai-chat/patterns/persistence-and-replay.mdx index b082ca30163..c93dc6d9b8b 100644 --- a/docs/ai-chat/patterns/persistence-and-replay.mdx +++ b/docs/ai-chat/patterns/persistence-and-replay.mdx @@ -163,7 +163,7 @@ export const myChat = chat.agent({ await db.chat.update({ where: { id: chatId }, data: { messages: uiMessages } }); }, run: async ({ messages, signal }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` diff --git a/docs/ai-chat/patterns/redacting-telemetry.mdx b/docs/ai-chat/patterns/redacting-telemetry.mdx index dea985801b8..79413b2adc5 100644 --- a/docs/ai-chat/patterns/redacting-telemetry.mdx +++ b/docs/ai-chat/patterns/redacting-telemetry.mdx @@ -28,7 +28,7 @@ export const supportAgent = chat.agent({ id: "support-agent", telemetry: { recordUserMessage: false, recordClientData: false }, run: async ({ messages, signal, streamText }) => - streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }), + streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }), }); ``` @@ -47,7 +47,7 @@ export const supportAgent = chat.agent({ telemetry: { recordUserMessage: false, recordClientData: false }, run: async ({ messages, signal, streamText }) => streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, // Replaces the default telemetry config (and chat.prompt.set()'s), so keep isEnabled on diff --git a/docs/ai-chat/patterns/skills.mdx b/docs/ai-chat/patterns/skills.mdx index f5da0861793..c268d2ac7da 100644 --- a/docs/ai-chat/patterns/skills.mdx +++ b/docs/ai-chat/patterns/skills.mdx @@ -94,7 +94,7 @@ export const agent = chat.agent({ }, run: async ({ messages, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, stopWhen: stepCountIs(15), @@ -165,7 +165,7 @@ If you also define your own AI SDK tools, pass them through `chat.toStreamTextOp ```ts return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, tools: { diff --git a/docs/ai-chat/patterns/sub-agents.mdx b/docs/ai-chat/patterns/sub-agents.mdx index 5f17f206da7..89310ec1295 100644 --- a/docs/ai-chat/patterns/sub-agents.mdx +++ b/docs/ai-chat/patterns/sub-agents.mdx @@ -301,7 +301,7 @@ export const myAgent = chat.agent({ tools, // declare here so toModelOutput survives across turns run: async ({ messages, tools, stopSignal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-6"), + model: anthropic("claude-sonnet-5-5"), messages, tools, abortSignal: stopSignal, diff --git a/docs/ai-chat/patterns/tool-result-auditing.mdx b/docs/ai-chat/patterns/tool-result-auditing.mdx index e547260fc04..7b8ad06499f 100644 --- a/docs/ai-chat/patterns/tool-result-auditing.mdx +++ b/docs/ai-chat/patterns/tool-result-auditing.mdx @@ -37,7 +37,7 @@ export const myChat = chat.agent({ return await db.getMessages(chatId); }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` diff --git a/docs/ai-chat/patterns/trusted-edge-signals.mdx b/docs/ai-chat/patterns/trusted-edge-signals.mdx index f065733996a..ed05c4426db 100644 --- a/docs/ai-chat/patterns/trusted-edge-signals.mdx +++ b/docs/ai-chat/patterns/trusted-edge-signals.mdx @@ -247,7 +247,7 @@ export const myAgent = chat // Score-based routing. The values arrive from the edge proxy. if (clientData.__cf.botScore < 30) { return streamText({ - model: anthropic("claude-haiku-4-5"), + model: anthropic("claude-haiku-5-5"), messages: [{ role: "system", content: "Reject politely; do not engage." }], abortSignal: signal, stopWhen: stepCountIs(15), @@ -255,7 +255,7 @@ export const myAgent = chat } return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, // ... diff --git a/docs/ai-chat/patterns/version-upgrades.mdx b/docs/ai-chat/patterns/version-upgrades.mdx index 37a798db2d1..eec1a0e11cc 100644 --- a/docs/ai-chat/patterns/version-upgrades.mdx +++ b/docs/ai-chat/patterns/version-upgrades.mdx @@ -122,7 +122,7 @@ export const myChat = chat } }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` @@ -184,7 +184,7 @@ export const myChat = chat } }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` diff --git a/docs/ai-chat/pending-messages.mdx b/docs/ai-chat/pending-messages.mdx index 79af3560f37..2dbe7e1daa8 100644 --- a/docs/ai-chat/pending-messages.mdx +++ b/docs/ai-chat/pending-messages.mdx @@ -45,7 +45,7 @@ export const myChat = chat.agent({ }, run: async ({ messages, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, tools: { inspectDocument: tool({ @@ -151,7 +151,7 @@ const session = chat.createSession(payload, { for await (const turn of session) { const result = streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages: turn.messages, abortSignal: turn.signal, prepareStep: turn.prepareStep(), // Handles injection + compaction @@ -193,7 +193,7 @@ for (let turn = 0; turn < 100; turn++) { }); const result = streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, prepareStep: conversation.prepareStep(), // Handles injection + compaction stopWhen: stepCountIs(15), @@ -248,7 +248,7 @@ function Chat({ chatId }: { chatId: string }) { messages, setMessages, sendMessage, - metadata: { model: "gpt-4o" }, + metadata: { model: "gpt-6-luna" }, }); return ( @@ -345,7 +345,7 @@ const sent = await transport.sendPendingMessage(chatId, { id: crypto.randomUUID(), role: "user", parts: [{ type: "text", text: "and compare to vercel" }], -}, { model: "gpt-4o" }); +}, { model: "gpt-6-luna" }); ``` Unlike `sendMessage()` from useChat, this does NOT: diff --git a/docs/ai-chat/prompt-caching.mdx b/docs/ai-chat/prompt-caching.mdx index 1a30b475f15..2b85338d3b9 100644 --- a/docs/ai-chat/prompt-caching.mdx +++ b/docs/ai-chat/prompt-caching.mdx @@ -4,7 +4,7 @@ sidebarTitle: "Prompt caching" description: "Cache the stable prefix of your agent's prompt with Anthropic prompt caching to cut token cost and latency on every turn." --- -**Prompt caching lets a provider reuse the unchanged prefix of your prompt across requests, billing it at a fraction of the input price and skipping re-processing.** With Anthropic, cache reads cost ~10% of base input tokens, so a long, stable system prompt or a growing conversation history pays full price once and reads cheaply on every turn after. +**Prompt caching lets a provider reuse the unchanged prefix of your prompt across requests, billing it at a fraction of the input price and skipping re-processing.** With Anthropic, cache reads cost ~5% of base input tokens on Claude Sonnet 5.5 and Opus 5.5, so a long, stable system prompt or a growing conversation history pays full price once and reads cheaply on every turn after. Caching is a **byte-exact prefix match**: any change in the prefix invalidates everything after it. A multi-turn agent is the ideal case — the system prompt, tools, and earlier turns are identical turn over turn, so the cacheable prefix only grows. `chat.agent` is built to keep that prefix stable across turns, suspends, and resumes; this page shows how to place the cache breakpoints and verify they're hitting. @@ -46,7 +46,7 @@ export const myChat = chat.agent({ }, run: async ({ messages, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-6"), + model: anthropic("claude-sonnet-5-5"), // Caches the system block with a 5-minute breakpoint. messages, abortSignal: signal, @@ -63,7 +63,7 @@ export const myChat = chat.agent({ systemProviderOptions: { anthropic: { cacheControl: { type: "ephemeral" } } }, run: async ({ messages, signal, streamText }) => streamText({ - model: anthropic("claude-sonnet-4-6"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, }), @@ -80,7 +80,7 @@ onChatStart: async () => { }, run: async ({ messages, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-6"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, }); @@ -117,7 +117,7 @@ export const myChat = chat.agent({ }, run: async ({ messages, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-6"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, }); @@ -128,7 +128,7 @@ export const myChat = chat.agent({ The system breakpoint and the conversation breakpoint compose: the system block is cached once for the life of the chat, and each turn extends the cached message prefix. - Anthropic allows **at most 4** cache breakpoints per request, and a prefix must be at least ~1024 tokens (model-dependent) to cache at all — shorter prefixes silently don't cache. One system breakpoint plus one rolling message breakpoint is the typical setup and leaves headroom. + Anthropic allows **at most 4** cache breakpoints per request, and a prefix must reach a model-dependent minimum to cache at all (512 tokens on Claude Sonnet 5.5 and Opus 5.5) — shorter prefixes silently don't cache. One system breakpoint plus one rolling message breakpoint is the typical setup and leaves headroom. @@ -171,7 +171,7 @@ run: async ({ messages, signal, previousTurnUsage, streamText }) => { console.log("cache write", previousTurnUsage?.inputTokenDetails?.cacheWriteTokens); return streamText({ - model: anthropic("claude-sonnet-4-6"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, }); diff --git a/docs/ai-chat/quick-start.mdx b/docs/ai-chat/quick-start.mdx index 93c0147cd6c..47aaafbe24f 100644 --- a/docs/ai-chat/quick-start.mdx +++ b/docs/ai-chat/quick-start.mdx @@ -23,7 +23,7 @@ The chat surface works with Vercel AI SDK **v5, v6, or v7**; install whichever m id: "my-chat", run: async ({ messages, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, stopWhen: stepCountIs(15), diff --git a/docs/ai-chat/testing.mdx b/docs/ai-chat/testing.mdx index c32d762841a..eb286efac83 100644 --- a/docs/ai-chat/testing.mdx +++ b/docs/ai-chat/testing.mdx @@ -92,7 +92,7 @@ export const myChatAgent = chat id: "my-chat", run: async ({ messages, clientData, signal, streamText }) => { return streamText({ - model: clientData?.model ?? "openai/gpt-4o-mini", + model: clientData?.model ?? "openai/gpt-6-luna", messages, abortSignal: signal, stopWhen: stepCountIs(15), @@ -161,7 +161,7 @@ export const agent = chat id: "agent", run: async ({ messages, clientData, signal, streamText }) => { return streamText({ - model: clientData?.model ?? anthropic("claude-haiku-4-5"), + model: clientData?.model ?? anthropic("claude-haiku-5-5"), messages, abortSignal: signal, stopWhen: stepCountIs(15), @@ -534,7 +534,7 @@ export const agent = chat.agent({ }); }, run: async ({ messages, signal }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` diff --git a/docs/ai-chat/tools.mdx b/docs/ai-chat/tools.mdx index 074182e17a3..07397c76cc0 100644 --- a/docs/ai-chat/tools.mdx +++ b/docs/ai-chat/tools.mdx @@ -26,7 +26,7 @@ export const myChat = chat.agent({ run: async ({ messages, tools, signal, streamText }) => streamText({ tools, - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, stopWhen: stepCountIs(15), @@ -88,7 +88,7 @@ export const chartChat = chat.agent({ run: async ({ messages, tools, signal, streamText }) => streamText({ tools, - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, stopWhen: stepCountIs(15), @@ -112,7 +112,7 @@ export const myChat = chat run: async ({ messages, tools, signal, streamText }) => streamText({ tools, - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, stopWhen: stepCountIs(15), @@ -120,6 +120,10 @@ export const myChat = chat }); ``` + + Claude 5.5 models bind each thinking block to the tool set it was produced with. Adding or removing a tool partway through a chat can make Anthropic reject the earlier thinking blocks with a 400, so keep a chat's tool set stable once it starts (for example, decide `plan`-based tools on the first turn). + + The function receives a `ResolveToolsEvent` and runs once per turn (after `clientData` is parsed): | Field | Type | Description | @@ -140,7 +144,7 @@ run: async ({ messages, tools, signal, streamText }) => { // `tools` is typed as your tool set, not a broad `ToolSet` return streamText({ tools, - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, }); @@ -181,7 +185,7 @@ const messages = await convertToModelMessages(uiMessages, { ignoreIncompleteToolCalls: true, }); -return streamText({ model: anthropic("claude-sonnet-4-5"), messages, tools }); +return streamText({ model: anthropic("claude-sonnet-5-5"), messages, tools }); ``` ## Learn more diff --git a/docs/ai-chat/transcript-storage.mdx b/docs/ai-chat/transcript-storage.mdx index 9a5684bbc26..a95697566e9 100644 --- a/docs/ai-chat/transcript-storage.mdx +++ b/docs/ai-chat/transcript-storage.mdx @@ -36,7 +36,7 @@ import { anthropic } from "@ai-sdk/anthropic"; export const myChat = chat.agent({ id: "my-chat", run: async ({ messages, signal, streamText }) => - streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }), + streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }), }); ``` @@ -55,7 +55,7 @@ export const myChat = chat.agent({ id: "my-chat", storage: myTranscriptStorage, run: async ({ messages, signal, streamText }) => - streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }), + streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }), }); ``` diff --git a/docs/ai-chat/types.mdx b/docs/ai-chat/types.mdx index b785a36767e..680b044fd1d 100644 --- a/docs/ai-chat/types.mdx +++ b/docs/ai-chat/types.mdx @@ -93,10 +93,12 @@ export const myChat = chat run: async ({ messages, tools, signal, streamText }) => { // `tools` is myTools, typed, handed back on the payload return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, tools, abortSignal: signal, + // Claude 5.5 models omit thinking text unless you ask for a summary + providerOptions: { anthropic: { thinking: { type: "adaptive", display: "summarized" } } }, stopWhen: stepCountIs(15), }); }, @@ -194,7 +196,12 @@ export const myChat = chat .agent({ id: "my-chat", run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ + model: anthropic("claude-sonnet-5-5"), + messages, + abortSignal: signal, + providerOptions: { anthropic: { thinking: { type: "adaptive", display: "summarized" } } }, + }); }, }); ``` @@ -219,7 +226,7 @@ chat await createChatRecord(event.chatId); }, run: async ({ messages, signal, streamText }) => { - return streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }); + return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }); }, }); ``` diff --git a/docs/ai/observability.mdx b/docs/ai/observability.mdx index 2d10c46b51b..4f4f0c0602f 100644 --- a/docs/ai/observability.mdx +++ b/docs/ai/observability.mdx @@ -1,7 +1,7 @@ --- title: "LLM observability" sidebarTitle: "LLM observability" -description: "Capture Vercel AI SDK calls in a task as spans in the run trace, with model, token usage, cost, and latency. Opt in per call, link calls to prompt versions, and query usage across runs." +description: "Capture Vercel AI SDK calls in a task as spans in the run trace, with model, token usage, cost, and latency. Link calls to prompt versions and query usage across runs." --- **LLM observability turns a Vercel AI SDK call inside a task into its own span in the run trace, next to your logs and other spans.** Each span carries the model, provider, input, output, and total token counts, cost, and latency, so you can see what each generation did and what it cost without leaving the run. @@ -9,12 +9,27 @@ description: "Capture Vercel AI SDK calls in a task as spans in the run trace, w Everything shows up inline in the run trace you already use to debug runs. There is no separate product and no dashboard to set up. - Observability is opt-in per call and only covers [Vercel AI SDK](https://ai-sdk.dev) functions (`generateText`, `streamText`, `generateObject`). Calls you make with a raw `fetch`, a provider's own SDK, or any other HTTP client are not captured automatically. + Observability only covers [Vercel AI SDK](https://ai-sdk.dev) functions (`generateText`, `streamText`, `generateObject`). On AI SDK 5 and 6 it's opt-in per call. On AI SDK 7, once the `@ai-sdk/otel` adapter is registered, every call is traced, including its prompts and responses, unless you pass `telemetry: { isEnabled: false }`. Calls you make with a raw `fetch`, a provider's own SDK, or any other HTTP client are not captured automatically. ## Turn it on -Set `experimental_telemetry: { isEnabled: true }` on the AI SDK call. There is nothing to install for AI SDK 6, and nothing to configure on the Trigger.dev side. +Set `experimental_telemetry: { isEnabled: true }` on the AI SDK call. There is nothing to configure on the Trigger.dev side. + + + **AI SDK 7** moved span emission out of `ai` core into the `@ai-sdk/otel` adapter. In a task, install `@ai-sdk/otel` and register it once yourself, for example at the top of your task file: + + ```ts /trigger/summarize.ts + import { registerTelemetry } from "ai"; + import { OpenTelemetry } from "@ai-sdk/otel"; + + registerTelemetry(new OpenTelemetry()); + ``` + + Register it the same way in projects with [`chat.agent()`](/ai-chat/overview) runs too: the static import is what includes `@ai-sdk/otel` in your deployed bundle. `chat.agent()` detects the existing registration and won't add a second one. + + Once the adapter is registered, AI SDK 7 traces every call by default, so the per-call flag is optional. To leave a call out, pass `telemetry: { isEnabled: false }` (`telemetry` is the non-deprecated name for `experimental_telemetry`). On AI SDK 5 and 6, `ai` core emits spans directly and no adapter is needed. + ```ts /trigger/summarize.ts import { task } from "@trigger.dev/sdk"; @@ -25,7 +40,7 @@ export const summarize = task({ id: "summarize", run: async (payload: { text: string }) => { const result = await generateText({ - model: openai("gpt-4o"), + model: openai("gpt-6-luna"), prompt: `Summarize the following text:\n\n${payload.text}`, experimental_telemetry: { isEnabled: true }, }); @@ -37,19 +52,6 @@ export const summarize = task({ Trigger the task and open the run. The `generateText` call appears as a span in the trace. `streamText` and `generateObject` work the same way: add the same `experimental_telemetry` flag to each call you want captured. - - **AI SDK 7** moved span emission out of `ai` core into the `@ai-sdk/otel` adapter. In a task, install `@ai-sdk/otel` and register it once yourself, for example at the top of your task file: - - ```ts /trigger/summarize.ts - import { registerTelemetry } from "ai"; - import { OpenTelemetry } from "@ai-sdk/otel"; - - registerTelemetry(new OpenTelemetry()); - ``` - - A [`chat.agent()`](/ai-chat/overview) run registers the adapter for you at run start, so chat agents need only the install. On AI SDK 5 and 6, `ai` core emits spans directly and no adapter is needed. - - ## What each span shows Open an AI generation span in the run trace to get a dedicated inspector with three tabs: @@ -64,6 +66,10 @@ A fourth **Prompt** tab appears when the call is linked to an [AI Prompt](/ai/pr If you manage prompts with [AI Prompts](/ai/prompts), resolve the prompt and spread `toAISDKTelemetry()` into the call. This sets `experimental_telemetry` for you and links the span back to the exact prompt version that produced it. + + Prompt linking currently works on AI SDK 5 and 6. On AI SDK 7, the metadata from `toAISDKTelemetry()` doesn't reach the span yet, so the call is traced but isn't linked to its prompt version or given the custom attributes. + + ```ts /trigger/support.ts import { task, prompts } from "@trigger.dev/sdk"; import { generateText } from "ai"; @@ -80,7 +86,7 @@ export const handleSupport = task({ }); const result = await generateText({ - model: openai(resolved.model ?? "gpt-4o"), + model: openai(resolved.model ?? "gpt-6-luna"), system: resolved.text, prompt: payload.issue, ...resolved.toAISDKTelemetry(), @@ -97,7 +103,7 @@ Pass custom attributes to `toAISDKTelemetry()` to tag the span with your own met ```ts const result = await generateText({ - model: openai(resolved.model ?? "gpt-4o"), + model: openai(resolved.model ?? "gpt-6-luna"), system: resolved.text, prompt: payload.issue, ...resolved.toAISDKTelemetry({ diff --git a/docs/ai/prompts.mdx b/docs/ai/prompts.mdx index c80e1170edb..4b7a7e83dc4 100644 --- a/docs/ai/prompts.mdx +++ b/docs/ai/prompts.mdx @@ -25,8 +25,8 @@ import { z } from "zod"; export const supportPrompt = prompts.define({ id: "customer-support", description: "System prompt for customer support interactions", - model: "gpt-4o", - config: { temperature: 0.7 }, + model: "gpt-6-luna", + config: { maxOutputTokens: 1024 }, variables: z.object({ customerName: z.string(), plan: z.string(), @@ -50,8 +50,8 @@ Respond to the customer's issue. Be concise and helpful.`, |--------|------|----------|-------------| | `id` | `string` | Yes | Unique identifier (becomes the prompt slug) | | `description` | `string` | No | Shown in the dashboard | -| `model` | `string` | No | Default model (e.g. `"gpt-4o"`, `"claude-sonnet-4-6"`) | -| `config` | `object` | No | Default config (temperature, maxTokens, etc.) | +| `model` | `string` | No | Default model (e.g. `"gpt-6-luna"`, `"claude-sonnet-5-5"`) | +| `config` | `object` | No | Default AI SDK call settings (e.g. `maxOutputTokens`) | | `variables` | Zod/ArkType schema | No | Schema for template variables (enables validation and dashboard UI) | | `content` | `string` | Yes | The prompt template with `{{variable}}` placeholders | @@ -65,7 +65,7 @@ Templates use Mustache-style placeholders: ```ts export const prompt = prompts.define({ id: "summarizer", - model: "gpt-4o-mini", + model: "gpt-6-luna", variables: z.object({ text: z.string(), maxSentences: z.string().optional(), @@ -91,7 +91,7 @@ const resolved = await supportPrompt.resolve({ console.log(resolved.text); // The compiled prompt with variables filled in console.log(resolved.version); // e.g. 3 -console.log(resolved.model); // "gpt-4o" +console.log(resolved.model); // "gpt-6-luna" console.log(resolved.labels); // ["current"] or ["override"] ``` @@ -135,12 +135,16 @@ By default, `resolve()` returns the **override** version if one is active, other The resolved prompt integrates with the [Vercel AI SDK](https://ai-sdk.dev) via `toAISDKTelemetry()`. This links AI generation spans to the prompt in the dashboard. + + Prompt linking currently works on AI SDK 5 and 6. On AI SDK 7, the metadata from `toAISDKTelemetry()` doesn't reach the span yet, so generations are traced but not linked to the prompt. + + ### generateText ```ts import { task } from "@trigger.dev/sdk"; import { generateText, stepCountIs } from "ai"; -import { anthropic } from "@ai-sdk/anthropic"; +import { openai } from "@ai-sdk/openai"; export const supportTask = task({ id: "handle-support", @@ -152,9 +156,10 @@ export const supportTask = task({ }); const result = await generateText({ - model: openai(resolved.model ?? "gpt-4o"), + model: openai(resolved.model ?? "gpt-6-luna"), system: resolved.text, prompt: payload.issue, + ...resolved.config, ...resolved.toAISDKTelemetry(), }); @@ -178,9 +183,10 @@ export const streamTask = task({ }); const result = streamText({ - model: openai(resolved.model ?? "gpt-4o"), + model: openai(resolved.model ?? "gpt-6-luna"), system: resolved.text, prompt: payload.issue, + ...resolved.config, ...resolved.toAISDKTelemetry(), stopWhen: stepCountIs(15), }); @@ -201,7 +207,7 @@ Pass additional metadata to `toAISDKTelemetry()` that will appear on the generat ```ts const result = await generateText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), prompt: resolved.text, ...resolved.toAISDKTelemetry({ "task.type": "summarization", @@ -227,8 +233,8 @@ const registry = createProviderRegistry({ anthropic }); const systemPrompt = prompts.define({ id: "my-chat-system", - model: "anthropic:claude-sonnet-4-5", - config: { temperature: 0.7 }, + model: "anthropic:claude-sonnet-5-5", + config: { maxOutputTokens: 1024 }, variables: z.object({ name: z.string() }), content: `You are a helpful assistant for {{name}}.`, }); @@ -259,21 +265,21 @@ Inside a `chat.agent` you don't need this: the `streamText` passed to `run()` ap - `system` — the compiled prompt text - `model` — resolved via the `registry` when provided -- `temperature`, `maxTokens`, etc. — from the prompt's `config` +- `maxOutputTokens` and other call settings — from the prompt's `config` - `experimental_telemetry` — links generations to the prompt in the dashboard ```ts // With registry — model is resolved automatically const options = chat.toStreamTextOptions({ registry }); -// { system: "...", model: LanguageModel, temperature: 0.7, experimental_telemetry: { ... } } +// { system: "...", model: LanguageModel, maxOutputTokens: 1024, experimental_telemetry: { ... } } // Without registry — model is not included const options = chat.toStreamTextOptions(); -// { system: "...", temperature: 0.7, experimental_telemetry: { ... } } +// { system: "...", maxOutputTokens: 1024, experimental_telemetry: { ... } } ``` - When the user provides a `registry` and the prompt has a `model` string (e.g. `"anthropic:claude-sonnet-4-5"`), the model is resolved via `registry.languageModel()` and included in the returned options. This means `streamText` uses the prompt's model by default — no manual model selection needed. + When the user provides a `registry` and the prompt has a `model` string (e.g. `"anthropic:claude-sonnet-5-5"`), the model is resolved via `registry.languageModel()` and included in the returned options. This means `streamText` uses the prompt's model by default — no manual model selection needed. ### Reading the prompt @@ -284,7 +290,7 @@ Access the stored prompt from anywhere in the run: run: async ({ messages, signal, streamText }) => { const prompt = chat.prompt(); // Throws if not set console.log(prompt.text); // The compiled prompt - console.log(prompt.model); // "anthropic:claude-sonnet-4-5" + console.log(prompt.model); // "anthropic:claude-sonnet-5-5" console.log(prompt.version); // 3 return streamText({ @@ -324,7 +330,7 @@ Create a new override that takes priority over the deployed version: ```ts const result = await prompts.createOverride("customer-support", { textContent: "New prompt template: Hello {{customerName}}!", - model: "gpt-4o-mini", + model: "gpt-6-luna", commitMessage: "Shorter prompt", }); ``` @@ -334,7 +340,7 @@ const result = await prompts.createOverride("customer-support", { ```ts await prompts.updateOverride("customer-support", { textContent: "Updated template: Hi {{customerName}}!", - model: "gpt-4o", + model: "gpt-6-luna", }); ``` diff --git a/docs/database-connections.mdx b/docs/database-connections.mdx index b83e9051d72..657c182a052 100644 --- a/docs/database-connections.mdx +++ b/docs/database-connections.mdx @@ -186,7 +186,7 @@ export const myChat = chat.agent({ const user = await prisma.user.findUnique({ where: { id: clientData.userId } }); // The connection is back in the pool before the model stream starts. return streamText({ - model: openai("gpt-4o"), + model: openai("gpt-6-luna"), system: `Helping ${user?.name ?? "the user"}.`, messages, abortSignal: signal, diff --git a/docs/errors-retrying.mdx b/docs/errors-retrying.mdx index 1890e935615..33572588735 100644 --- a/docs/errors-retrying.mdx +++ b/docs/errors-retrying.mdx @@ -216,7 +216,7 @@ export const openaiTask = task({ run: async (payload: { prompt: string }) => { const chatCompletion = await openai.chat.completions.create({ messages: [{ role: "user", content: payload.prompt }], - model: "gpt-3.5-turbo", + model: "gpt-6-luna", }); return chatCompletion.choices[0].message.content; @@ -319,7 +319,7 @@ export const openaiTask = task({ //if this fails, it will throw an error and stop retrying const chatCompletion = await openai.chat.completions.create({ messages: [{ role: "user", content: payload.prompt }], - model: "gpt-3.5-turbo", + model: "gpt-6-luna", }); if (chatCompletion.choices[0]?.message.content === undefined) { @@ -334,10 +334,15 @@ export const openaiTask = task({ ### Using try/catch -Sometimes you want to catch an error and don't want to retry the task. You can use try/catch as you normally would. In this example we fallback to using Replicate if OpenAI fails. +Sometimes you want to catch an error and don't want to retry the task. You can use try/catch as you normally would. In this example we fall back to using Anthropic if OpenAI fails. ```ts /trigger/myTasks.ts import { task } from "@trigger.dev/sdk"; +import Anthropic from "@anthropic-ai/sdk"; +import OpenAI from "openai"; + +const openai = new OpenAI(); +const anthropic = new Anthropic(); export const openaiTask = task({ id: "openai-task", @@ -346,7 +351,7 @@ export const openaiTask = task({ //if this fails, it will throw an error and retry const chatCompletion = await openai.chat.completions.create({ messages: [{ role: "user", content: payload.prompt }], - model: "gpt-3.5-turbo", + model: "gpt-6-luna", }); if (chatCompletion.choices[0]?.message.content === undefined) { @@ -356,23 +361,25 @@ export const openaiTask = task({ return chatCompletion.choices[0].message.content; } catch (error) { - //use Replicate if OpenAI fails - const prediction = await replicate.run( - "meta/llama-2-70b-chat:02e509c789964a7ea8736978a43525956ef40397be9033abf9fd2badfe68c9e3", - { - input: { - prompt: payload.prompt, - max_new_tokens: 250, - }, - } - ); + //use Anthropic if OpenAI fails + const message = await anthropic.messages.create({ + model: "claude-haiku-5-5", + max_tokens: 16000, + messages: [{ role: "user", content: payload.prompt }], + }); + + //the response can include thinking blocks, so only read the text blocks + const text = message.content + .filter((block) => block.type === "text") + .map((block) => block.text) + .join(""); - if (prediction.output === undefined) { - //retry if Replicate fails - throw new Error("Replicate call failed"); + if (!text) { + //retry if Anthropic fails + throw new Error("Anthropic call failed"); } - return prediction.output; + return text; } }, }); diff --git a/docs/guides/ai-agents/chat-agent.mdx b/docs/guides/ai-agents/chat-agent.mdx index 7c6d890c77b..d038b3a1a76 100644 --- a/docs/guides/ai-agents/chat-agent.mdx +++ b/docs/guides/ai-agents/chat-agent.mdx @@ -23,7 +23,7 @@ export const myChat = chat.agent({ id: "my-chat", run: async ({ messages, signal, streamText }) => { return streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, stopWhen: stepCountIs(15), @@ -61,7 +61,7 @@ export const myChat = chat.agent({ run: async ({ messages, tools, signal, streamText }) => { return streamText({ tools, - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, stopWhen: stepCountIs(15), abortSignal: signal, diff --git a/docs/guides/ai-agents/claude-code-trigger.mdx b/docs/guides/ai-agents/claude-code-trigger.mdx index 859171d542d..41f54ea70f9 100644 --- a/docs/guides/ai-agents/claude-code-trigger.mdx +++ b/docs/guides/ai-agents/claude-code-trigger.mdx @@ -89,7 +89,7 @@ export const codeGenerator = schemaTask({ const result = query({ prompt, options: { - model: "claude-sonnet-4-20250514", + model: "claude-sonnet-5-5", abortController, cwd: workDir, maxTurns: 10, diff --git a/docs/guides/ai-agents/generate-translate-copy.mdx b/docs/guides/ai-agents/generate-translate-copy.mdx index 1c16a05a3cb..1ad5653739e 100644 --- a/docs/guides/ai-agents/generate-translate-copy.mdx +++ b/docs/guides/ai-agents/generate-translate-copy.mdx @@ -39,12 +39,9 @@ export const generateAndTranslateTask = task({ run: async (payload: TranslatePayload) => { // Step 1: Generate marketing copy const generatedCopy = await generateText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), + system: "You are an expert copywriter.", messages: [ - { - role: "system", - content: "You are an expert copywriter.", - }, { role: "user", content: `Generate as close as possible to ${payload.targetWordCount} words of compelling marketing copy for ${payload.marketingSubject}`, @@ -72,12 +69,9 @@ export const generateAndTranslateTask = task({ // Step 2: Translate to target language const translatedCopy = await generateText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), + system: `You are an expert translator specializing in marketing content translation into ${payload.targetLanguage}.`, messages: [ - { - role: "system", - content: `You are an expert translator specializing in marketing content translation into ${payload.targetLanguage}.`, - }, { role: "user", content: `Translate the following marketing copy to ${payload.targetLanguage}, maintaining the same tone and marketing impact:\n\n${generatedCopy.text}`, diff --git a/docs/guides/ai-agents/respond-and-check-content.mdx b/docs/guides/ai-agents/respond-and-check-content.mdx index 116216c673f..de15f26813d 100644 --- a/docs/guides/ai-agents/respond-and-check-content.mdx +++ b/docs/guides/ai-agents/respond-and-check-content.mdx @@ -18,7 +18,7 @@ In this example, we'll create a workflow that simultaneously checks content for - Uses `generateText` from the [AI SDK](https://ai-sdk.dev/) to call Anthropic's Claude models - Uses `experimental_telemetry` to surface each LLM call on the Run page in the dashboard - Uses [`batch.triggerByTaskAndWait`](/triggering#batch-triggerbytaskandwait) to run customer response and content moderation tasks in parallel -- Answers with `claude-sonnet-4-5` and moderates with the faster, cheaper `claude-haiku-4-5` +- Answers with `claude-sonnet-5-5` and moderates with the faster, cheaper `claude-haiku-5-5` - Simultaneously checks for inappropriate content while generating responses ```typescript @@ -31,12 +31,9 @@ export const generateCustomerResponse = task({ id: "generate-customer-response", run: async (payload: { question: string }) => { const response = await generateText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), + system: "You are a helpful customer service representative.", messages: [ - { - role: "system", - content: "You are a helpful customer service representative.", - }, { role: "user", content: payload.question }, ], experimental_telemetry: { @@ -54,13 +51,9 @@ export const checkInappropriateContent = task({ id: "check-inappropriate-content", run: async (payload: { text: string }) => { const response = await generateText({ - model: anthropic("claude-haiku-4-5"), + model: anthropic("claude-haiku-5-5"), + system: "You are a content moderator. Respond with 'true' if the content is inappropriate or contains harmful, threatening, offensive, or explicit content, 'false' otherwise.", messages: [ - { - role: "system", - content: - "You are a content moderator. Respond with 'true' if the content is inappropriate or contains harmful, threatening, offensive, or explicit content, 'false' otherwise.", - }, { role: "user", content: payload.text }, ], experimental_telemetry: { diff --git a/docs/guides/ai-agents/route-question.mdx b/docs/guides/ai-agents/route-question.mdx index 717b82cbbca..42d6d36f449 100644 --- a/docs/guides/ai-agents/route-question.mdx +++ b/docs/guides/ai-agents/route-question.mdx @@ -18,8 +18,8 @@ In this example, we'll create a workflow that routes a question to a different A - Uses `generateObject` from the [AI SDK](https://ai-sdk.dev/) to classify the question into a typed routing decision - Uses `experimental_telemetry` to surface each LLM call on the Run page in the dashboard -- Classifies complexity with a fast, cheap model (`claude-haiku-4-5`) -- Directs simple questions to `claude-haiku-4-5` and complex ones to `claude-sonnet-4-5` +- Classifies complexity with a fast, cheap model (`claude-haiku-5-5`) +- Directs simple questions to `claude-haiku-5-5` and complex ones to `claude-sonnet-5-5` - Returns both the answer and metadata about the routing decision ```typescript @@ -31,7 +31,7 @@ import { z } from "zod"; // The router's structured decision. generateObject validates the model // output against this schema, so there's no manual JSON parsing. const routingSchema = z.object({ - model: z.enum(["claude-haiku-4-5", "claude-sonnet-4-5"]), + model: z.enum(["claude-haiku-5-5", "claude-sonnet-5-5"]), reason: z.string(), }); @@ -40,12 +40,12 @@ export const routeAndAnswerQuestion = task({ run: async (payload: { question: string }) => { // Step 1: Classify the question and pick a model const { object: routing } = await generateObject({ - model: anthropic("claude-haiku-4-5"), + model: anthropic("claude-haiku-5-5"), schema: routingSchema, system: "You are a routing assistant. Pick the model best suited to answer the question:\n" + - "- claude-haiku-4-5 for simple, common, or straightforward questions\n" + - "- claude-sonnet-4-5 for complex, unusual, or questions needing deep reasoning", + "- claude-haiku-5-5 for simple, common, or straightforward questions\n" + + "- claude-sonnet-5-5 for complex, unusual, or questions needing deep reasoning", prompt: payload.question, experimental_telemetry: { isEnabled: true, @@ -76,7 +76,7 @@ export const routeAndAnswerQuestion = task({ ## Run a test -Triggering our task with a simple question shows it routing to the `claude-haiku-4-5` model and returning the answer with reasoning: +Triggering our task with a simple question shows it routing to the `claude-haiku-5-5` model and returning the answer with reasoning: ```json { diff --git a/docs/guides/ai-agents/translate-and-refine.mdx b/docs/guides/ai-agents/translate-and-refine.mdx index f5958524c55..10ec164710a 100644 --- a/docs/guides/ai-agents/translate-and-refine.mdx +++ b/docs/guides/ai-agents/translate-and-refine.mdx @@ -63,13 +63,10 @@ export const translateAndRefine = task({ : `Translate this text into ${payload.targetLanguage}, preserving style and meaning: "${payload.text}"`; const translation = await generateText({ - model: anthropic("claude-sonnet-4-5"), - messages: [ - { - role: "system", - content: `You are an expert literary translator into ${payload.targetLanguage}. + model: anthropic("claude-sonnet-5-5"), + system: `You are an expert literary translator into ${payload.targetLanguage}. Focus on accuracy first, then style and natural flow.`, - }, + messages: [ { role: "user", content: translationPrompt, @@ -83,11 +80,8 @@ export const translateAndRefine = task({ // Evaluate the translation const evaluation = await generateText({ - model: anthropic("claude-sonnet-4-5"), - messages: [ - { - role: "system", - content: `You are an expert literary critic and translator focused on practical, high-quality translations. + model: anthropic("claude-sonnet-5-5"), + system: `You are an expert literary critic and translator focused on practical, high-quality translations. Your goal is to ensure translations are accurate and natural, but not necessarily perfect. This is iteration ${ rejectionCount + 1 @@ -109,7 +103,7 @@ export const translateAndRefine = task({ - First iteration MUST receive feedback for improvement - Be very strict on accuracy in early iterations - After 3 iterations, lower quality threshold to 85%`, - }, + messages: [ { role: "user", content: `Original: "${payload.text}" diff --git a/docs/guides/ai-agents/verify-news-article.mdx b/docs/guides/ai-agents/verify-news-article.mdx index e6bfe076c36..ca6a5fae687 100644 --- a/docs/guides/ai-agents/verify-news-article.mdx +++ b/docs/guides/ai-agents/verify-news-article.mdx @@ -19,7 +19,7 @@ Our example task uses multiple LLM calls to extract claims from a news article a - Uses `generateText` from the [AI SDK](https://ai-sdk.dev/) to call Anthropic's Claude models - Uses `experimental_telemetry` to surface each LLM call on the Run page in the dashboard - Uses [`batch.triggerByTaskAndWait`](/triggering#batch-triggerbytaskandwait) to orchestrate parallel processing of claims -- Extracts factual claims from news articles using `claude-sonnet-4-5` +- Extracts factual claims from news articles using `claude-sonnet-5-5` - Evaluates claims against recent sources and analyzes historical context in parallel - Combines results into a structured analysis report @@ -53,12 +53,8 @@ export const extractClaims = task({ id: "extract-claims", run: async ({ article }: { article: string }) => { try { + const system = "Extract distinct factual claims from the news article. Format as numbered claims."; const messages: ModelMessage[] = [ - { - role: "system", - content: - "Extract distinct factual claims from the news article. Format as numbered claims.", - }, { role: "user", content: article, @@ -66,7 +62,8 @@ export const extractClaims = task({ ]; const response = await generateText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), + system, messages, experimental_telemetry: { isEnabled: true, @@ -98,13 +95,9 @@ export const verifySource = task({ id: "verify-source", run: async (claim: Claim) => { const response = await generateText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), + system: "Verify this claim by considering recent news sources and official statements. Assess reliability.", messages: [ - { - role: "system", - content: - "Verify this claim by considering recent news sources and official statements. Assess reliability.", - }, { role: "user", content: claim.text, @@ -130,13 +123,9 @@ export const analyzeHistory = task({ id: "analyze-history", run: async (claim: Claim) => { const response = await generateText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), + system: "Analyze this claim in historical context, considering past announcements and technological feasibility.", messages: [ - { - role: "system", - content: - "Analyze this claim in historical context, considering past announcements and technological feasibility.", - }, { role: "user", content: claim.text, diff --git a/docs/guides/examples/open-ai-with-retrying.mdx b/docs/guides/examples/open-ai-with-retrying.mdx index 483fbd97263..d68ebac181f 100644 --- a/docs/guides/examples/open-ai-with-retrying.mdx +++ b/docs/guides/examples/open-ai-with-retrying.mdx @@ -32,7 +32,7 @@ export const openaiTask = task({ //if this fails, it will throw an error and retry const chatCompletion = await openai.chat.completions.create({ messages: [{ role: "user", content: payload.prompt }], - model: "gpt-3.5-turbo", + model: "gpt-6-luna", }); if (chatCompletion.choices[0]?.message.content === undefined) { diff --git a/docs/guides/examples/scrape-hacker-news.mdx b/docs/guides/examples/scrape-hacker-news.mdx index fe9ecf1fd95..95b6877b2d6 100644 --- a/docs/guides/examples/scrape-hacker-news.mdx +++ b/docs/guides/examples/scrape-hacker-news.mdx @@ -190,7 +190,7 @@ export const scrapeAndSummarizeArticle = task({ // Summarize the content using ChatGPT const response = await openai.chat.completions.create({ - model: "gpt-4o", + model: "gpt-6-luna", messages: [ { role: "user", diff --git a/docs/guides/examples/vercel-ai-sdk.mdx b/docs/guides/examples/vercel-ai-sdk.mdx index dbddb8a6d64..244e0079ed6 100644 --- a/docs/guides/examples/vercel-ai-sdk.mdx +++ b/docs/guides/examples/vercel-ai-sdk.mdx @@ -29,7 +29,7 @@ export const openaiTask = task({ run: async (payload: { prompt: string }) => { const chatCompletion = await generateText({ - model: openai("gpt-4-turbo"), + model: openai("gpt-6-luna"), // Add a system message which will be included with the prompt system: "You are a friendly assistant!", // The prompt passed in from the payload diff --git a/docs/guides/frameworks/nango.mdx b/docs/guides/frameworks/nango.mdx index ea3fb16dfea..b20367ad578 100644 --- a/docs/guides/frameworks/nango.mdx +++ b/docs/guides/frameworks/nango.mdx @@ -203,8 +203,8 @@ export const analyzePRs = task({ .join("\n\n"); const message = await anthropic.messages.create({ - model: "claude-opus-4-6", - max_tokens: 1024, + model: "claude-opus-5-5", + max_tokens: 16000, messages: [ { role: "user", @@ -213,7 +213,15 @@ export const analyzePRs = task({ ], }); - const summary = message.content[0].type === "text" ? message.content[0].text : ""; + if (message.stop_reason === "max_tokens") { + throw new Error("Summary was cut off by max_tokens"); + } + + // Claude may return a thinking block before the text, so read text blocks by type + const summary = message.content + .filter((block): block is Anthropic.TextBlock => block.type === "text") + .map((block) => block.text) + .join("\n"); return { summary, prCount: prs.length }; }, diff --git a/docs/introduction.mdx b/docs/introduction.mdx index 50d4cd80785..e4cef590f53 100644 --- a/docs/introduction.mdx +++ b/docs/introduction.mdx @@ -44,7 +44,7 @@ export const supportAgent = chat.agent({ id: "support-agent", run: async ({ messages, signal, streamText }) => streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal, }), diff --git a/docs/migrating-from-v3.mdx b/docs/migrating-from-v3.mdx index 1248b626cfe..76c0f2153fb 100644 --- a/docs/migrating-from-v3.mdx +++ b/docs/migrating-from-v3.mdx @@ -154,7 +154,7 @@ export const myAiTask = schemaTask({ run: async (payload, { ctx }) => { const { text } = await generateText({ prompt: payload.text, - model: openai("gpt-4o"), + model: openai("gpt-6-luna"), tools: { myToolTask, }, diff --git a/docs/oidc/openrouter.mdx b/docs/oidc/openrouter.mdx index 31500d3d719..698e6c45f56 100644 --- a/docs/oidc/openrouter.mdx +++ b/docs/oidc/openrouter.mdx @@ -73,7 +73,7 @@ export const openrouterChat = task({ apiKey: access_token, }); const completion = await openrouter.chat.completions.create({ - model: "openai/gpt-4o-mini", + model: "openai/gpt-6-luna", messages: [{ role: "user", content: payload.prompt }], }); diff --git a/docs/runs/metadata.mdx b/docs/runs/metadata.mdx index 3e2526abefc..88a40a5455e 100644 --- a/docs/runs/metadata.mdx +++ b/docs/runs/metadata.mdx @@ -347,7 +347,7 @@ export const myTask = task({ run: async (payload: { prompt: string }) => { const completion = await openai.chat.completions.create({ messages: [{ role: "user", content: payload.prompt }], - model: "gpt-3.5-turbo", + model: "gpt-6-luna", stream: true, }); diff --git a/docs/snippets/code/openai-retry.mdx b/docs/snippets/code/openai-retry.mdx index beb386e812e..d2abf53c8b0 100644 --- a/docs/snippets/code/openai-retry.mdx +++ b/docs/snippets/code/openai-retry.mdx @@ -20,7 +20,7 @@ export const openaiTask = task({ //if this fails, it will throw an error and retry const chatCompletion = await openai.chat.completions.create({ messages: [{ role: "user", content: payload.prompt }], - model: "gpt-3.5-turbo", + model: "gpt-6-luna", }); if (chatCompletion.choices[0]?.message.content === undefined) { diff --git a/docs/snippets/migrate-v4-using-ai.mdx b/docs/snippets/migrate-v4-using-ai.mdx index aa5393c158d..f40f4f58b6a 100644 --- a/docs/snippets/migrate-v4-using-ai.mdx +++ b/docs/snippets/migrate-v4-using-ai.mdx @@ -75,7 +75,7 @@ export const myAiTask = schemaTask({ run: async (payload, { ctx }) => { const { text } = await generateText({ prompt: payload.text, - model: openai("gpt-4o"), + model: openai("gpt-6-luna"), tools: { myToolTask, }, @@ -88,7 +88,7 @@ This is the new version: import { schemaTask } from "@trigger.dev/sdk"; import { ai } from "@trigger.dev/sdk/ai"; import { z } from "zod"; -import { generateText, tool } from "ai"; +import { generateText, stepCountIs, tool } from "ai"; import { openai } from "@ai-sdk/openai"; // Convert toolTask to schemaTask with a schema @@ -115,10 +115,11 @@ export const myAiTask = schemaTask({ run: async (payload, { ctx }) => { const { text } = await generateText({ prompt: payload.text, - model: openai("gpt-4o"), + model: openai("gpt-6-luna"), tools: { myTool, }, + stopWhen: stepCountIs(5), }); }, }); diff --git a/docs/tasks/schemaTask.mdx b/docs/tasks/schemaTask.mdx index a551fb1af49..4f288899bf5 100644 --- a/docs/tasks/schemaTask.mdx +++ b/docs/tasks/schemaTask.mdx @@ -87,7 +87,7 @@ Prefer building the tool with the AI SDK’s [`tool()`](https://sdk.vercel.ai/do ```ts import { ai } from "@trigger.dev/sdk/ai"; import { schemaTask } from "@trigger.dev/sdk"; -import { tool, generateText } from "ai"; +import { tool, generateText, stepCountIs } from "ai"; import { openai } from "@ai-sdk/openai"; import { z } from "zod"; @@ -115,24 +115,25 @@ export const myAiTask = schemaTask({ run: async ({ text }) => { const { text: reply } = await generateText({ prompt: text, - model: openai("gpt-4o"), + model: openai("gpt-6-luna"), tools: { myTool, }, + stopWhen: stepCountIs(5), }); return reply; }, }); ``` -`experimental_toToolResultContent` and other tool-level options belong on **`tool({ ... })`**, not on `ai.toolExecute`: +`toModelOutput` and other tool-level options belong on **`tool({ ... })`**, not on `ai.toolExecute`: ```ts import { openai } from "@ai-sdk/openai"; import { Sandbox } from "@e2b/code-interpreter"; import { ai } from "@trigger.dev/sdk/ai"; import { schemaTask } from "@trigger.dev/sdk"; -import { generateObject, tool } from "ai"; +import { generateText, Output, tool } from "ai"; import { z } from "zod"; const chartTask = schemaTask({ @@ -142,17 +143,19 @@ const chartTask = schemaTask({ input: z.string().describe("The chart to generate"), }), run: async ({ input }) => { - const code = await generateObject({ - model: openai("gpt-4o"), - schema: z.object({ - code: z.string().describe("The Python code to execute"), + const { output } = await generateText({ + model: openai("gpt-6-luna"), + output: Output.object({ + schema: z.object({ + code: z.string().describe("The Python code to execute"), + }), }), system: `You are a helpful assistant that generates matplotlib code. End with plt.show().`, prompt: input, }); const sandbox = await Sandbox.create(); - const execution = await sandbox.runCode(code.object.code); + const execution = await sandbox.runCode(output.code); const firstResult = execution.results[0]; if (firstResult.png) { @@ -162,16 +165,26 @@ const chartTask = schemaTask({ }, }); +// Keep the executor in its own const so `output` below is typed from the task +const executeChart = ai.toolExecute(chartTask); + export const chartTool = tool({ description: chartTask.description ?? "", inputSchema: chartTask.schema!, - execute: ai.toolExecute(chartTask), - experimental_toToolResultContent: (result) => [ - { type: "image", data: result.chart, mimeType: "image/png" }, - ], + execute: executeChart, + toModelOutput: ({ output }) => ({ + type: "content", + value: [ + { type: "file", mediaType: "image/png", data: { type: "data", data: output.chart } }, + ], + }), }); ``` + + This sample uses AI SDK 7. On AI SDK 6, use `{ type: "image-data", data: output.chart, mediaType: "image/png" }` as the item in `value` instead of the `file` part. On AI SDK 5, pass `experimental_output: Output.object(...)` instead of `output` and read the result from `experimental_output`, and use `toModelOutput: (output) => ({ type: "content", value: [{ type: "media", data: output.chart, mediaType: "image/png" }] })`. + + Inside the task run, you can read tool execution context with **`ai.currentToolOptions()`** (and helpers like `ai.toolCallId()`, `ai.chatContext()` when running inside a [`chat.agent`](/ai-chat/overview)): ```ts diff --git a/docs/tasks/streams.mdx b/docs/tasks/streams.mdx index 611041092f2..fdd00e3e50f 100644 --- a/docs/tasks/streams.mdx +++ b/docs/tasks/streams.mdx @@ -402,7 +402,7 @@ export async function POST(req: Request) { const { messages, runId } = await req.json(); const result = streamText({ - model: openai("gpt-4o"), + model: openai("gpt-6-luna"), messages, }); @@ -686,7 +686,7 @@ export const generateAI = task({ id: "generate-ai", run: async (payload: { prompt: string }) => { const result = streamText({ - model: openai("gpt-4o"), + model: openai("gpt-6-luna"), prompt: payload.prompt, }); diff --git a/docs/webhooks/channels.mdx b/docs/webhooks/channels.mdx index cc9477ea217..ac7e3aee588 100644 --- a/docs/webhooks/channels.mdx +++ b/docs/webhooks/channels.mdx @@ -27,7 +27,7 @@ export const supportAgent = chat.agent({ }), ], run: async ({ messages, streamText }) => - streamText({ model: anthropic("claude-sonnet-4-5"), messages }), + streamText({ model: anthropic("claude-sonnet-5-5"), messages }), }); ``` diff --git a/docs/webhooks/human-in-the-loop.mdx b/docs/webhooks/human-in-the-loop.mdx index eb9b8279230..803e2045a0e 100644 --- a/docs/webhooks/human-in-the-loop.mdx +++ b/docs/webhooks/human-in-the-loop.mdx @@ -67,7 +67,7 @@ export const supportAgent = chat.agent({ tools: { requestApproval }, run: async ({ messages, tools, streamText }) => streamText({ - model: anthropic("claude-sonnet-4-5"), + model: anthropic("claude-sonnet-5-5"), messages, tools, system: diff --git a/docs/webhooks/linear.mdx b/docs/webhooks/linear.mdx index 9ea927b8837..56956edbe88 100644 --- a/docs/webhooks/linear.mdx +++ b/docs/webhooks/linear.mdx @@ -21,7 +21,7 @@ export const triage = chat.agent({ channels: [linear({ id: "linear", endpoint: linearEvents, token: process.env.LINEAR_ACCESS_TOKEN! })], tools: { searchDocs, createSubIssues }, run: async ({ messages, tools, signal, streamText }) => - streamText({ model: anthropic("claude-sonnet-4-5"), messages, tools, abortSignal: signal }), + streamText({ model: anthropic("claude-sonnet-5-5"), messages, tools, abortSignal: signal }), }); ``` diff --git a/docs/webhooks/session-routing.mdx b/docs/webhooks/session-routing.mdx index df268768e01..3d5b5df3fd5 100644 --- a/docs/webhooks/session-routing.mdx +++ b/docs/webhooks/session-routing.mdx @@ -107,7 +107,7 @@ export const orderAgent = chat.agent({ } }, run: async ({ messages, streamText }) => - streamText({ model: anthropic("claude-sonnet-4-5"), messages }), + streamText({ model: anthropic("claude-sonnet-5-5"), messages }), }); ``` diff --git a/docs/webhooks/slack.mdx b/docs/webhooks/slack.mdx index 81bd38665d2..c3cbcaa0983 100644 --- a/docs/webhooks/slack.mdx +++ b/docs/webhooks/slack.mdx @@ -13,6 +13,7 @@ import { webhooks } from "@trigger.dev/sdk"; import { chat } from "@trigger.dev/sdk/ai"; import { appMentions, slack, webhookSource } from "@trigger.dev/slack"; import { anthropic } from "@ai-sdk/anthropic"; +import { stepCountIs } from "ai"; const slackEvents = webhooks.endpoint.define({ id: "slack", source: webhookSource() }); @@ -28,7 +29,13 @@ export const support = chat.agent({ ], tools: { searchDocs, refundOrder }, run: async ({ messages, tools, signal, streamText }) => - streamText({ model: anthropic("claude-sonnet-4-5"), messages, tools, abortSignal: signal }), + streamText({ + model: anthropic("claude-sonnet-5-5"), + messages, + tools, + abortSignal: signal, + stopWhen: stepCountIs(10), + }), }); ```