You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(sdk,cli): bundle agent skills + docs in the SDK for zero-drift (#3937)
## Summary
`@trigger.dev/sdk` now ships the Trigger.dev agent skills and a curated
snapshot of the docs those skills cite. The skills that `trigger skills`
installs into your coding agent are thin pointers that read this bundled
content from `node_modules`, so the guidance always matches the SDK
version installed in your project. Previously the full skill text was
copied into your repo at install time and went stale until you
reinstalled after an upgrade.
## How it works
The SDK's `files[]` now includes `skills/` (the full skill text) and
`docs/` (a curated snapshot generated at build time). The docs manifest
is derived from each skill's own `sources:` frontmatter, so a skill only
ships the docs it references, and a skill that cites a missing doc fails
the build.
The CLI installs thin skills whose body points the agent at
`node_modules/@trigger.dev/sdk/skills/<name>/SKILL.md` and
`node_modules/@trigger.dev/sdk/docs/`. They keep the high-value "Common
mistakes" anti-patterns inline so the trigger and the guardrails survive
even if the agent does not follow the pointer. `getting-started` stays
self-contained in the CLI because it runs before the SDK is installed.
`@trigger.dev/sdk` now bundles the Trigger.dev agent skills and a curated snapshot of the docs those skills reference. The skills that `trigger skills` installs into your coding agent read this content from node_modules, so the guidance your AI assistant follows is pinned to the SDK version installed in your project and stays current across upgrades instead of going stale until the next reinstall.
Copy file name to clipboardExpand all lines: packages/cli-v3/skills/authoring-chat-agent/SKILL.md
+6-241Lines changed: 6 additions & 241 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,242 +10,16 @@ description: >
10
10
streamText route to chat.agent.
11
11
type: core
12
12
library: trigger.dev
13
-
library_version: "{{TRIGGER_SDK_VERSION}}"
14
-
sources:
15
-
- docs/ai-chat/overview.mdx
16
-
- docs/ai-chat/quick-start.mdx
17
-
- docs/ai-chat/how-it-works.mdx
18
-
- docs/ai-chat/backend.mdx
19
-
- docs/ai-chat/frontend.mdx
20
-
- docs/ai-chat/reference.mdx
21
-
- docs/ai-chat/types.mdx
22
-
- docs/ai-chat/tools.mdx
23
-
- docs/ai-chat/lifecycle-hooks.mdx
24
-
- docs/ai-chat/error-handling.mdx
25
13
---
26
14
27
-
# Authoring a chatagent
15
+
# Authoring a chat.agent
28
16
29
-
A `chat.agent` runs an entire conversation as one long-lived Trigger.dev task. It wakes when a
30
-
message arrives, freezes when none do, and in-memory state survives page refreshes, deploys, idle
31
-
gaps, and crashes. Your code is the loop you would write anyway: messages in, `streamText` out.
32
-
There are no API routes. The frontend talks to the agent through a `TriggerChatTransport`, so
33
-
history accumulates server-side and the client ships only the new message each turn.
17
+
The full, version-pinned reference ships **inside your installed `@trigger.dev/sdk`**. Read it before writing code — it always matches the SDK version in this project, so it never drifts:
34
18
35
-
Works with Vercel AI SDK v5, v6, or v7. On v7 also install `@ai-sdk/otel` so model calls are traced
36
-
(the SDK registers it for you).
19
+
-**Skill:**`node_modules/@trigger.dev/sdk/skills/authoring-chat-agent/SKILL.md` — the per-turn run loop, `chat.toStreamTextOptions()`, the two server actions, typed tools/data parts, and the React transport.
20
+
-**Docs:**the full, version-pinned docs ship bundled at `node_modules/@trigger.dev/sdk/docs/ai-chat/`; the skill above lists the exact pages it draws from in its `sources:` frontmatter. Grep for an API, e.g. `grep -rl "toStreamTextOptions" node_modules/@trigger.dev/sdk/docs/`.
37
21
38
-
## Setup
39
-
40
-
Three pieces: the agent task, two server actions, and the frontend transport.
41
-
42
-
### 1. Define the agent
43
-
44
-
```ts trigger/chat.ts
45
-
import { chat } from"@trigger.dev/sdk/ai";
46
-
import { streamText, stepCountIs } from"ai";
47
-
import { anthropic } from"@ai-sdk/anthropic";
48
-
49
-
exportconst myChat =chat.agent({
50
-
id: "my-chat",
51
-
run: async ({ messages, signal }) =>
52
-
streamText({
53
-
// Spread this FIRST. See "Common mistakes".
54
-
...chat.toStreamTextOptions(),
55
-
model: anthropic("claude-sonnet-4-5"),
56
-
messages,
57
-
abortSignal: signal,
58
-
stopWhen: stepCountIs(15),
59
-
}),
60
-
});
61
-
```
62
-
63
-
`run` receives `messages` already converted to `ModelMessage[]` (the SDK converts the frontend's
64
-
`UIMessage[]` for you) plus a `signal` that aborts on stop or cancel. Returning the
65
-
`StreamTextResult` auto-pipes it to the frontend.
66
-
67
-
### 2. Add two server actions
68
-
69
-
Both run on your server, so the browser never holds your environment secret key. This is also
70
-
where per-user / per-plan authorization and any paired DB writes live.
71
-
72
-
```ts app/actions.ts
73
-
"use server";
74
-
import { auth } from"@trigger.dev/sdk";
75
-
import { chat } from"@trigger.dev/sdk/ai";
76
-
77
-
// Creates the Session + first run, returns a session PAT. Idempotent on (env, chatId).
### 6. Migrating from a plain AI SDK `streamText` route
242
-
243
-
There is no API route in this model. The transport replaces the route round-trip, so:
244
-
245
-
- Delete the route handler. Move per-request auth into the two server actions from Setup step 2.
246
-
- Move the `streamText` call into `run`. It already receives pre-converted `ModelMessage[]`.
247
-
- Return the `StreamTextResult` (it auto-pipes) and add `...chat.toStreamTextOptions()` first.
248
-
- On the client, swap the `api` URL for `useTriggerChatTransport`; `useChat` stays the same shape.
22
+
If those paths don't exist, `@trigger.dev/sdk` isn't installed yet — install it first. In a non-hoisted layout, resolve the package with `node -p "require.resolve('@trigger.dev/sdk/package.json')"` and read `skills/` + `docs/` beside it.
249
23
250
24
## Common mistakes
251
25
@@ -283,13 +57,4 @@ There is no API route in this model. The transport replaces the route round-trip
283
57
284
58
## References
285
59
286
-
-`chat-agent-advanced` skill - lifecycle hooks in depth, sessions, raw-task primitives
0 commit comments