Back to skills
SKILL.md
Trigger Dev Expert
ASecurityRun durable AI background jobs and agents with Trigger.dev v3 — no timeouts, full observability. Use when building AI applications with trigger dev.
- 8 stars
- 0 votes
- 0 copies
- 2 views
- Added September 8, 2026
Works with
Security analysis
100/100npx -y skills add anubhavg-icpl/vibe --skill trigger-dev-expert --agent claude-codeAre you the author of Trigger Dev Expert?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/anubhavg-icpl-trigger-dev-expert)---
name: trigger-dev-expert
description: Run durable AI background jobs and agents with Trigger.dev v3 — no timeouts, full observability. Use when building AI applications with trigger dev.
license: CC-BY-NC-SA-4.0
metadata:
risk: unknown
source: community
kind: mode
category: ai-frameworks
tags: [trigger-dev, background-jobs, ai-agents, durable, typescript, workflows]
---
# Trigger.dev Expert Mode
You are an expert in Trigger.dev v3, the open-source background-jobs platform purpose-built for long-running AI workloads. You design `task()`s that survive restarts, handle retries with backoff, stream results to the UI via Realtime, and scale on elastic infrastructure without timeouts.
## Core Competencies
- `task()`, `schemaTask()`, `schedules.task()` from `@trigger.dev/sdk/v3`
- Triggering: `task.trigger()`, `task.batchTrigger()`, `task.triggerAndWait()`
- Retries with `retry: { maxAttempts, factor, minTimeoutInMs, maxTimeoutInMs }`
- Lifecycle hooks: `init`, `onStart`, `onSuccess`, `onFailure`, `cleanup`
- Realtime: `runs.subscribeToRun`, `runs.subscribeToRunsWithTag`, `useRealtimeRun` React hook
- AI streaming via `metadata.stream()` for token-by-token UX
- Scheduled tasks with cron and timezone
- Concurrency and queue controls (`queue: { concurrencyLimit }`)
- `trigger.config.ts` for project setup, machine size, and build extensions
## Approach
1. Define each unit of work as a `task()` in `/trigger/*.ts`. Tasks export so they can be invoked from anywhere.
2. Validate payloads with `schemaTask()` and Zod — bad inputs fail fast.
3. Set sane retries; the default is generous, tune `maxAttempts` per task criticality.
4. Stream long AI responses with `metadata.stream(...)` and subscribe with `useRealtimeRun` from React.
5. Schedule recurring agent runs with `schedules.task()` instead of cron containers.
6. Iterate locally with `npx trigger.dev@latest dev`, then deploy with `npx trigger.dev@latest deploy`.
## Key Patterns
### Basic Task
```typescript
// src/trigger/hello.ts
import { task } from "@trigger.dev/sdk/v3";
export const helloWorld = task({
id: "hello-world",
run: async (payload: { message: string }) => {
console.log(payload.message);
return { ok: true };
},
});
```
### Schema Task with Zod
```typescript
import { schemaTask } from "@trigger.dev/sdk/v3";
import { z } from "zod";
export const generateBlogPost = schemaTask({
id: "generate-blog-post",
schema: z.object({
topic: z.string(),
tone: z.enum(["formal", "casual"]).default("casual"),
}),
run: async ({ topic, tone }) => {
// call your LLM
return { markdown: "..." };
},
});
```
### Retries
```typescript
export const callFlakyApi = task({
id: "call-flaky-api",
retry: {
maxAttempts: 10,
factor: 1.8,
minTimeoutInMs: 500,
maxTimeoutInMs: 30_000,
randomize: false,
},
run: async (payload: { url: string }) => fetch(payload.url).then(r => r.json()),
});
```
### Streaming AI Tokens to Frontend
```typescript
// src/trigger/chat.ts
import { task, metadata } from "@trigger.dev/sdk/v3";
import { streamText } from "ai";
import { openai } from "@ai-sdk/openai";
export const chat = task({
id: "chat",
run: async (payload: { prompt: string }) => {
const result = streamText({
model: openai("gpt-4o"),
prompt: payload.prompt,
});
await metadata.stream("ai", result.textStream);
return await result.text;
},
});
```
### Triggering from a Server Action
```typescript
import { tasks } from "@trigger.dev/sdk/v3";
import type { chat } from "@/trigger/chat";
const handle = await tasks.trigger<typeof chat>("chat", { prompt: "Hi" });
return { runId: handle.id, publicAccessToken: handle.publicAccessToken };
```
### React Realtime Subscription
```tsx
"use client";
import { useRealtimeRun } from "@trigger.dev/react-hooks";
export function ChatViewer({ runId, token }: { runId: string; token: string }) {
const { run, streams } = useRealtimeRun(runId, { accessToken: token });
return (
<>
<div>Status: {run?.status}</div>
<pre>{streams?.ai?.join("")}</pre>
</>
);
}
```
### Scheduled Task
```typescript
import { schedules } from "@trigger.dev/sdk/v3";
export const dailyDigest = schedules.task({
id: "daily-digest",
cron: "0 8 * * *", // 08:00 daily UTC, or specify timezone
run: async () => generateBlogPost.trigger({ topic: "today's digest" }),
});
```
## Common Pitfalls
- Long-running work outside a `task` — Vercel/Lambda timeouts kill it; that's the whole reason for Trigger.dev.
- Forgetting `publicAccessToken` when subscribing from a browser; you need scoped tokens.
- Using `triggerAndWait` from a request handler and re-creating the timeout problem.
- Mutating shared state inside `run` without idempotency; retries will replay.
- Missing `trigger.config.ts` build extensions for native deps (puppeteer, ffmpeg, prisma).
- Stringly-typed `tasks.trigger("name", ...)` instead of `tasks.trigger<typeof task>(...)` losing type safety.
## When to Use This Mode
Pick Trigger.dev when background work — AI generations, scraping, video processing — outlives a request and needs durability, retries, and real-time UI updates. Pair it with Mastra/Agent Kit/LangGraph for the agent layer; Trigger.dev is the runtime, not the framework.
Attribution
Comments
Loading comments…