# Trigger.dev — Background Jobs for AI Agents > Open-source framework for long-running AI agent tasks, workflows, and scheduled jobs. Built-in retries and observability. 14K+ stars. ## Install Copy the content below into your project: # Trigger.dev — Background Jobs for AI Agents ## Quick Use ```bash npx trigger.dev@latest init ``` ```typescript import { task } from '@trigger.dev/sdk/v3'; export const aiResearchTask = task({ id: 'ai-research', maxDuration: 300, // 5 minutes retry: { maxAttempts: 3 }, run: async (payload: { topic: string }) => { // Step 1: Search the web const sources = await searchWeb(payload.topic); // Step 2: Summarize with LLM const summary = await callOpenAI( `Summarize these sources about ${payload.topic}: ${JSON.stringify(sources)}` ); // Step 3: Save results await saveToDatabase({ topic: payload.topic, summary, sources }); return { summary, sourceCount: sources.length }; }, }); ``` Trigger from your API: ```typescript await aiResearchTask.trigger({ topic: 'RAG best practices 2026' }); ``` --- ## Intro Trigger.dev is an open-source background job framework with 14,300+ GitHub stars purpose-built for long-running AI tasks. It handles what serverless functions can't — agent workflows that run for minutes or hours, multi-step pipelines with retries, scheduled batch processing, and event-driven automation. With built-in observability (trace every step), automatic retries, rate limiting, and concurrency control, Trigger.dev is the infrastructure layer between your AI logic and reliable production execution. Deploy your own or use their managed cloud. Works with: Node.js, TypeScript, OpenAI, Anthropic, any API, Vercel, Next.js, Express. Best for teams running AI agents, batch processing, or multi-step workflows that exceed serverless time limits. Setup time: under 5 minutes. --- ## Trigger.dev for AI Workloads ### Why Background Jobs for AI? Serverless functions have 10-60s time limits. AI workloads often need: - **Agent loops** that run for minutes (research, code generation) - **Batch processing** of 1000s of documents through LLMs - **Multi-step pipelines** with retries on each step - **Scheduled tasks** (daily report generation, model retraining) ### AI Agent Workflow Example ```typescript import { task } from '@trigger.dev/sdk/v3'; export const codingAgent = task({ id: 'coding-agent', maxDuration: 600, // 10 minutes run: async ({ issue }: { issue: string }) => { // Multi-step agent loop let plan = await callLLM(`Plan how to fix: ${issue}`); let code = await callLLM(`Write code for: ${plan}`); let tests = await runTests(code); // Retry loop if tests fail for (let i = 0; i < 3 && !tests.passed; i++) { code = await callLLM(`Fix failing tests: ${tests.errors}`); tests = await runTests(code); } return { code, testsPassed: tests.passed }; }, }); ``` ### Batch Processing ```typescript export const batchEmbed = task({ id: 'batch-embed', run: async ({ documents }: { documents: string[] }) => { const results = await Promise.all( documents.map(doc => callOpenAI(`Generate embedding for: ${doc.slice(0, 1000)}`) ) ); await saveEmbeddings(results); return { processed: documents.length }; }, }); // Trigger with 10,000 documents await batchEmbed.trigger({ documents: allDocs }); ``` ### Scheduled Jobs ```typescript import { schedules } from '@trigger.dev/sdk/v3'; export const dailyReport = schedules.task({ id: 'daily-ai-report', cron: '0 9 * * *', // Every day at 9 AM run: async () => { const metrics = await getYesterdayMetrics(); const report = await callLLM(`Generate daily AI usage report: ${JSON.stringify(metrics)}`); await sendEmail({ to: 'team@company.com', body: report }); }, }); ``` ### Built-in Observability Every task execution is traced: - Step-by-step execution timeline - Input/output for each step - Error details with stack traces - Duration and retry history - Cost tracking (if configured) --- ## FAQ **Q: What is Trigger.dev?** A: Trigger.dev is an open-source background job framework with 14,300+ GitHub stars for running long-duration AI tasks, multi-step workflows, batch processing, and scheduled jobs with built-in retries and observability. **Q: How is Trigger.dev different from n8n or Temporal?** A: Trigger.dev is code-first TypeScript (not visual/YAML). n8n is a visual workflow builder. Temporal is a distributed workflow engine for large teams. Trigger.dev is the simplest path from "I have a TypeScript function" to "it runs reliably in production." **Q: Is Trigger.dev free?** A: Yes, open-source under Apache-2.0. Self-host for free. Managed cloud has a free tier. --- ## Source & Thanks > Created by [Trigger.dev](https://github.com/triggerdotdev). Licensed under Apache-2.0. > > [trigger.dev](https://github.com/triggerdotdev/trigger.dev) — ⭐ 14,300+ --- ## 快速使用 ```bash npx trigger.dev@latest init ``` --- ## 简介 Trigger.dev 是一个拥有 14,300+ GitHub stars 的开源后台任务框架,专为长时间运行的 AI 任务设计。支持多步骤工作流、自动重试、定时任务和内置可观测性。 --- ## 来源与感谢 > Created by [Trigger.dev](https://github.com/triggerdotdev). Licensed under Apache-2.0. > > [trigger.dev](https://github.com/triggerdotdev/trigger.dev) — ⭐ 14,300+ --- Source: https://tokrepo.com/en/workflows/e82ebfc9-5607-40ff-98d3-1e9eabcdaa62 Author: Agent Toolkit