Skip to content

Commit eedde27

Browse files
authored
chore: rewrite v4.5.0 release content around AI Agents (#3629)
## Summary Refocuses the v4.5.0 changeset and server-changes content on the public-facing AI features story, replacing the pre-release-internal diff framing that had accumulated in `.changeset/` and `.server-changes/`. Pairs with the RC support PR — the next bot regeneration will pick up this content. ## What's in here ### Changeset rewrites - **`chat-agent.md` rewritten as the headline AI Agents entry** — written from the `docs/ai-chat/` surface (not from internal pre-release diffs). Covers useChat integration, multi-turn durability via Sessions, lifecycle hooks, stop generation, tool approvals (HITL), pending messages + background injection, actions, typed state primitives, `chat.toStreamTextOptions()`, multi-tab coordination, network resilience, and the first-turn fast path (`chat.headStart`). - **New `ai-prompts.md`** — announces the Prompts feature publicly for the first time. Code-defined templates, deploy-versioning, dashboard overrides, AI SDK telemetry integration, `chat.agent` integration via `chat.prompt.set()` + `chat.toStreamTextOptions()`, full management SDK. - **`sessions-primitive.md` expanded** — calls out `tasks.triggerAndSubscribe()` and `sessions.list` as standalone primitives (not just chat.agent infrastructure). - **`chat-agent-on-boot-hook.md` trimmed** — drops "if you previously…" pre-release migration framing. - **Deletes 4 changesets** that described pre-release-internal migrations or were circular ("groundwork for the upcoming chat.agent" — chat.agent ships in the same release). ### Server-changes rewrites (`.server-changes/`) Five new entries for the dashboard surface of the AI feature set: - Agents list page - Agent Playground - Sessions dashboard - Prompts dashboard (list with usage sparklines + detail with template / Generations / Metrics / Versions tabs + override UI) - Models registry (provider-grouped catalog with cross-tenant usage metrics) - AI generation span inspector on run traces - Runs list Task source filter (Standard / Scheduled / Agent) - Run-detail Agent view (segmented control) Each entry is 1–2 sentences, no bullets, no implementation file paths — fits as a single bullet in a future changelog. Three older `.server-changes/` files were merged or split into the cleaner taxonomy above and deleted. ## Out of scope Non-AI-feature server-changes (admin-tabs, queue-length-cap fix, worker-deployment race, streamdown upgrade, etc.) and changesets (idempotency-key cap, sigsegv retry, locals-key fix, plugin auth, region filters, etc.) are untouched.
1 parent dfa3ede commit eedde27

19 files changed

Lines changed: 135 additions & 116 deletions

.changeset/ai-prompts.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
"@trigger.dev/sdk": minor
3+
---
4+
5+
**AI Prompts** — define prompt templates as code alongside your tasks, version them on deploy, and override the text or model from the dashboard without redeploying. Prompts integrate with the Vercel AI SDK via `toAISDKTelemetry()` (links every generation span back to the prompt) and with `chat.agent` via `chat.prompt.set()` + `chat.toStreamTextOptions()`.
6+
7+
```ts
8+
import { prompts } from "@trigger.dev/sdk";
9+
import { generateText } from "ai";
10+
import { openai } from "@ai-sdk/openai";
11+
import { z } from "zod";
12+
13+
export const supportPrompt = prompts.define({
14+
id: "customer-support",
15+
model: "gpt-4o",
16+
config: { temperature: 0.7 },
17+
variables: z.object({
18+
customerName: z.string(),
19+
plan: z.string(),
20+
issue: z.string(),
21+
}),
22+
content: `You are a support agent for Acme.
23+
24+
Customer: {{customerName}} ({{plan}} plan)
25+
Issue: {{issue}}`,
26+
});
27+
28+
const resolved = await supportPrompt.resolve({
29+
customerName: "Alice",
30+
plan: "Pro",
31+
issue: "Can't access billing",
32+
});
33+
34+
const result = await generateText({
35+
model: openai(resolved.model ?? "gpt-4o"),
36+
system: resolved.text,
37+
prompt: "Can't access billing",
38+
...resolved.toAISDKTelemetry(),
39+
});
40+
```
41+
42+
**What you get:**
43+
44+
- **Code-defined, deploy-versioned templates** — define with `prompts.define({ id, model, config, variables, content })`. Every deploy creates a new version visible in the dashboard. Mustache-style placeholders (`{{var}}`, `{{#cond}}...{{/cond}}`) with Zod / ArkType / Valibot-typed variables.
45+
- **Dashboard overrides** — change a prompt's text or model from the dashboard without redeploying. Overrides take priority over the deployed "current" version and are environment-scoped (dev / staging / production independent).
46+
- **Resolve API**`prompt.resolve(vars, { version?, label? })` returns the compiled `text`, resolved `model`, `version`, and labels. Standalone `prompts.resolve<typeof handle>(slug, vars)` for cross-file resolution with full type inference on slug and variable shape.
47+
- **AI SDK integration** — spread `resolved.toAISDKTelemetry({ ...extra })` into any `generateText` / `streamText` call and every generation span links to the prompt in the dashboard alongside its input variables, model, tokens, and cost.
48+
- **`chat.agent` integration**`chat.prompt.set(resolved)` stores the resolved prompt run-scoped; `chat.toStreamTextOptions({ registry })` pulls `system`, `model` (resolved via the AI SDK provider registry), `temperature` / `maxTokens` / etc., and telemetry into a single spread for `streamText`.
49+
- **Management SDK**`prompts.list()`, `prompts.versions(slug)`, `prompts.promote(slug, version)`, `prompts.createOverride(slug, body)`, `prompts.updateOverride(slug, body)`, `prompts.removeOverride(slug)`, `prompts.reactivateOverride(slug, version)`.
50+
- **Dashboard** — prompts list with per-prompt usage sparklines; per-prompt detail with Template / Details / Versions / Generations / Metrics tabs. AI generation spans get a custom inspector showing the linked prompt's metadata, input variables, and template content alongside model, tokens, cost, and the message thread.
51+
52+
See [/docs/ai/prompts](https://trigger.dev/docs/ai/prompts) for the full reference — template syntax, version resolution order, override workflow, and type utilities (`PromptHandle`, `PromptIdentifier`, `PromptVariables`).

.changeset/chat-actions-no-turn.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

.changeset/chat-agent-delta-wire-snapshots.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

.changeset/chat-agent-on-boot-hook.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ export const myChat = chat.agent({
1818
});
1919
```
2020

21-
If you previously initialized `chat.local` in `onChatStart`, move it to `onBoot` `onChatStart` is once-per-chat and won't fire on a continuation, leaving `chat.local` uninitialized when `run()` tries to use it. See the upgrade guide for the migration pattern.
21+
Use `onBoot` (not `onChatStart`) for state setup that must run every time a worker picks up the chat `onChatStart` fires once per chat and won't run on continuation, leaving `chat.local` uninitialized when `run()` tries to use it.

.changeset/chat-agent.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"@trigger.dev/core": patch
44
---
55

6-
Run AI chats as durable Trigger.dev tasks. Define the agent in one function, wire `useChat` to it from React, and the conversation survives page refreshes, network blips, and process restarts — with built-in support for tools, HITL approvals, multi-turn state, and stop-mid-stream cancellation.
6+
**AI Agents** — run AI SDK chat completions as durable Trigger.dev agents instead of fragile API routes. Define an agent in one function, point `useChat` at it from React, and the conversation survives page refreshes, network blips, and process restarts.
77

88
```ts
99
import { chat } from "@trigger.dev/sdk/ai";
@@ -21,10 +21,24 @@ export const myChat = chat.agent({
2121
import { useChat } from "@ai-sdk/react";
2222
import { useTriggerChatTransport } from "@trigger.dev/sdk/chat/react";
2323

24-
const transport = useTriggerChatTransport({ task: "my-chat", accessToken });
24+
const transport = useTriggerChatTransport({ task: "my-chat", accessToken, startSession });
2525
const { messages, sendMessage } = useChat({ transport });
2626
```
2727

28-
Lifecycle hooks (`onPreload`, `onTurnStart`, `onTurnComplete`, etc.) cover the common needs around persistence, validation, and post-turn work. `chat.store` gives you a typed shared-data slot the agent and client both read and write. `chat.endRun()` exits cleanly when the agent decides it's done. The transport's `watch` mode lets a dashboard tab observe a run without driving it.
28+
**What you get:**
2929

30-
Drops the pre-Sessions chat stream constants (`CHAT_STREAM_KEY`, `CHAT_MESSAGES_STREAM_ID`, `CHAT_STOP_STREAM_ID`) — migrate to `sessions.open(id).out` / `.in`.
30+
- **AI SDK `useChat` integration** — a custom [`ChatTransport`](https://sdk.vercel.ai/docs/ai-sdk-ui/transport) (`useTriggerChatTransport`) plugs straight into Vercel AI SDK's `useChat` hook. Text streaming, tool calls, reasoning, and `data-*` parts all work natively over Trigger.dev's realtime streams. No custom API routes needed.
31+
- **First-turn fast path (`chat.headStart`)** — opt-in handler that runs the first turn's `streamText` step in your warm server process while the agent run boots in parallel, cutting cold-start TTFC by roughly half (measured 2801ms → 1218ms on `claude-sonnet-4-6`). The agent owns step 2+ (tool execution, persistence, hooks) so heavy deps stay where they belong. Web Fetch handler works natively in Next.js, Hono, SvelteKit, Remix, Workers, etc.; bridge to Express/Fastify/Koa via `chat.toNodeListener`. New `@trigger.dev/sdk/chat-server` subpath.
32+
- **Multi-turn durability via Sessions** — every chat is backed by a durable Session that outlives any individual run. Conversations resume across page refreshes, idle timeout, crashes, and deploys; `resume: true` reconnects via `lastEventId` so clients only see new chunks. `sessions.list` enumerates chats for inbox-style UIs.
33+
- **Auto-accumulated history, delta-only wire** — the backend accumulates the full conversation across turns; clients only ship the new message each turn. Long chats never hit the 512 KiB body cap. Register `hydrateMessages` to be the source of truth yourself.
34+
- **Lifecycle hooks**`onPreload`, `onChatStart`, `onValidateMessages`, `hydrateMessages`, `onTurnStart`, `onBeforeTurnComplete`, `onTurnComplete`, `onChatSuspend`, `onChatResume` — for persistence, validation, and post-turn work.
35+
- **Stop generation** — client-driven `transport.stopGeneration(chatId)` aborts mid-stream; the run stays alive for the next message, partial response is captured, and aborted parts (stuck `partial-call` tools, in-progress reasoning) are auto-cleaned.
36+
- **Tool approvals (HITL)** — tools with `needsApproval: true` pause until the user approves or denies via `addToolApprovalResponse`. The runtime reconciles the updated assistant message by ID and continues `streamText`.
37+
- **Steering and background injection**`pendingMessages` injects user messages between tool-call steps so users can steer the agent mid-execution; `chat.inject()` + `chat.defer()` adds context from background work (self-review, RAG, safety checks) between turns.
38+
- **Actions** — non-turn frontend commands (undo, rollback, regenerate, edit) sent via `transport.sendAction`. Fire `hydrateMessages` + `onAction` only — no turn hooks, no `run()`. `onAction` can return a `StreamTextResult` for a model response, or `void` for side-effect-only.
39+
- **Typed state primitives**`chat.local<T>` for per-run state accessible from hooks, `run()`, tools, and subtasks (auto-serialized through `ai.toolExecute`); `chat.store` for typed shared data between agent and client; `chat.history` for reading and mutating the message chain; `clientDataSchema` for typed `clientData` in every hook.
40+
- **`chat.toStreamTextOptions()`** — one spread into `streamText` wires up versioned system [Prompts](https://trigger.dev/docs/ai/prompts), model resolution, telemetry metadata, compaction, steering, and background injection.
41+
- **Multi-tab coordination**`multiTab: true` + `useMultiTabChat` prevents duplicate sends and syncs state across browser tabs via `BroadcastChannel`. Non-active tabs go read-only with live updates.
42+
- **Network resilience** — built-in indefinite retry with bounded backoff, reconnect on `online` / tab refocus / bfcache restore, `Last-Event-ID` mid-stream resume. No app code needed.
43+
44+
See [/docs/ai-chat](https://trigger.dev/docs/ai-chat/overview) for the full surface — quick start, three backend approaches (`chat.agent`, `chat.createSession`, raw task), persistence and code-sandbox patterns, type-level guides, and API reference.

.changeset/chat-head-start.md

Lines changed: 0 additions & 34 deletions
This file was deleted.

.changeset/chat-ready-core-additions.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/sessions-primitive.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,24 @@
33
"@trigger.dev/core": patch
44
---
55

6-
Adds the Sessions primitive — a durable, run-aware stream channel keyed
7-
on a stable `externalId`. Public SDK additions: `tasks.triggerAndSubscribe()`
8-
and the `chat.agent` runtime built on top of Sessions. See
9-
https://trigger.dev/docs/ai-chat/overview for the full feature surface.
6+
**Sessions** — a durable, run-aware stream channel keyed on a stable `externalId`. A Session is the unit of state that owns a multi-run conversation: messages flow through `.in`, responses through `.out`, both survive run boundaries. Sessions back the new `chat.agent` runtime, and you can build on them directly for any pattern that needs durable bi-directional streaming across runs.
7+
8+
```ts
9+
import { sessions, tasks } from "@trigger.dev/sdk";
10+
11+
// Trigger a task and subscribe to its session output in one call
12+
const { runId, stream } = await tasks.triggerAndSubscribe("my-task", payload, {
13+
externalId: "user-456",
14+
});
15+
16+
for await (const chunk of stream) {
17+
// ...
18+
}
19+
20+
// Enumerate existing sessions (powers inbox-style UIs without a separate index)
21+
for await (const s of sessions.list({ type: "chat.agent", tag: "user:user-456" })) {
22+
console.log(s.id, s.externalId, s.createdAt, s.closedAt);
23+
}
24+
```
25+
26+
See [/docs/ai-chat/overview](https://trigger.dev/docs/ai-chat/overview) for the full surface — Sessions powers the durable, resumable chat runtime described there.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: feature
4+
---
5+
6+
New Agent Playground for testing `chat.agent` tasks interactively — multi-turn chat with tool-call visualization, a side panel for payload / schema / clientData configuration, and trigger-config controls for `maxDuration`, version pin, and region.

.server-changes/agent-view-sessions.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)