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.
What it is
Trigger.dev is an open-source platform for running background jobs with durable execution. It handles long-running tasks, automatic retries, scheduled jobs, and provides observability for every run. The TypeScript-first SDK makes it straightforward to define jobs that survive server restarts and network failures.
It targets developers building AI agent workflows, data pipelines, and any application with tasks that take more than a few seconds and need reliability guarantees.
How it saves time or tokens
Trigger.dev solves the reliability problem for AI agent tasks. LLM calls can be slow, fail due to rate limits, or time out. Instead of building retry logic, queue management, and failure handling from scratch, Trigger.dev handles all of this. Each step in a job is checkpointed, so if a step fails, the job resumes from the last successful step rather than restarting from the beginning. This saves both time and tokens.
How to use
- Install and initialize:
npx trigger.dev@latest init
- Define a background job:
import { task } from '@trigger.dev/sdk/v3';
export const processDocument = task({
id: 'process-document',
run: async (payload: { url: string }) => {
// Step 1: Fetch document
const doc = await fetch(payload.url).then(r => r.text());
// Step 2: Send to LLM for analysis
const analysis = await analyzeWithLLM(doc);
// Step 3: Store results
await saveToDatabase(analysis);
return { status: 'complete', analysis };
}
});
- Trigger the job from your app:
import { processDocument } from './trigger/process-document';
await processDocument.trigger({ url: 'https://example.com/report.pdf' });
Example
import { task } from '@trigger.dev/sdk/v3';
import OpenAI from 'openai';
const openai = new OpenAI();
export const aiResearchAgent = task({
id: 'ai-research-agent',
retry: { maxAttempts: 3, minTimeoutInMs: 1000 },
run: async (payload: { topic: string }) => {
// Step 1: Generate research plan
const plan = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: `Create a research plan for: ${payload.topic}` }]
});
// Step 2: Execute each research step
const results = [];
for (const step of plan.choices[0].message.content.split('\n')) {
const research = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: `Research: ${step}` }]
});
results.push(research.choices[0].message.content);
}
// Step 3: Synthesize findings
const synthesis = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: `Synthesize: ${results.join('\n')}` }]
});
return { report: synthesis.choices[0].message.content };
}
});
Related on TokRepo
- AI tools for automation -- Workflow automation tools
- AI tools for agents -- AI agent frameworks and tools
Common pitfalls
- Durable execution means each step is persisted. Very granular steps (hundreds per job) increase storage and overhead. Group related operations into logical steps.
- Self-hosting Trigger.dev requires PostgreSQL and a worker process. The cloud version handles infrastructure for you.
- Long-running LLM calls should have explicit timeouts. Without timeouts, a stuck API call can hold a worker indefinitely.
Frequently Asked Questions
Durable execution means each step in a job is checkpointed to persistent storage. If the job fails at step 3, it resumes from step 3 on retry rather than restarting from step 1. This prevents duplicate work and wasted API calls. Trigger.dev implements this transparently.
Yes. Trigger.dev is open-source and self-hostable. You need PostgreSQL and a Node.js runtime. The self-hosted version includes the full dashboard, job monitoring, and all features. Docker deployment is supported for containerized environments.
Trigger.dev provides built-in retry with exponential backoff. When an LLM API returns a 429 (rate limit) error, the job automatically waits and retries. You configure max attempts, timeout intervals, and backoff strategies per task.
Yes. You can define cron-based schedules for recurring jobs. This is useful for periodic AI tasks like daily report generation, scheduled model evaluations, or batch processing. Schedules are configured in the task definition.
Trigger.dev includes a web dashboard that shows every job run with status, duration, step-by-step execution trace, errors, and retry history. You can filter by job type, status, and time range. This makes debugging failed AI agent workflows straightforward.
Citations (3)
- Trigger.dev GitHub Repository— Trigger.dev provides durable execution for background jobs
- Trigger.dev Documentation— Trigger.dev supports retries, scheduling, and step-based checkpointing
- Temporal Durable Execution— Durable execution patterns improve reliability of distributed systems
Related on TokRepo
Source & Thanks
Created by Trigger.dev. Licensed under Apache-2.0.
trigger.dev — ⭐ 14,300+