WorkflowsApr 3, 2026·2 min read

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.

TL;DR
Trigger.dev runs background jobs with durable execution and retries for AI agents.
§01

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.

§02

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.

§03

How to use

  1. Install and initialize:
npx trigger.dev@latest init
  1. 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 };
    }
});
  1. Trigger the job from your app:
import { processDocument } from './trigger/process-document';

await processDocument.trigger({ url: 'https://example.com/report.pdf' });
§04

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 };
    }
});
§05

Related on TokRepo

§06

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

What is durable execution?+

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.

Can I self-host Trigger.dev?+

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.

How does Trigger.dev handle rate limits?+

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.

Does Trigger.dev support scheduled jobs?+

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.

What observability does Trigger.dev provide?+

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)
🙏

Source & Thanks

Created by Trigger.dev. Licensed under Apache-2.0.

trigger.dev — ⭐ 14,300+

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.