diff --git a/docs/docs.json b/docs/docs.json new file mode 100644 index 0000000000..8649b22cb2 --- /dev/null +++ b/docs/docs.json @@ -0,0 +1,484 @@ +{ + "$schema": "https://mintlify.com/docs.json", + "theme": "maple", + "name": "Trigger.dev", + "description": "Trigger.dev is an open source background jobs framework that lets you write reliable workflows in plain async code. Run long-running AI tasks, handle complex background jobs, and build AI agents with built-in queuing, automatic retries, and real-time monitoring. No timeouts, elastic scaling, and zero infrastructure management required.", + "colors": { + "primary": "#A8FF53", + "light": "#A8FF53", + "dark": "#A8FF53" + }, + "favicon": "/images/favicon.png", + "navigation": { + "dropdowns": [ + { + "dropdown": "Documentation", + "description": "Resources for Trigger.dev", + "icon": "book-open", + "groups": [ + { + "group": "Getting started", + "pages": ["introduction", "quick-start", "video-walkthrough", "how-it-works", "limits"] + }, + { + "group": "Fundamentals", + "pages": [ + { + "group": "Tasks", + "pages": ["tasks/overview", "tasks/schemaTask", "tasks/scheduled"] + }, + "triggering", + "runs", + "apikeys", + { + "group": "Configuration", + "pages": ["config/config-file", "config/extensions/overview"] + } + ] + }, + { + "group": "Development", + "pages": ["cli-dev", "run-tests"] + }, + { + "group": "Deployment", + "pages": [ + "cli-deploy", + "deploy-environment-variables", + "github-actions", + { + "group": "Deployment integrations", + "pages": ["vercel-integration"] + } + ] + }, + { + "group": "Writing tasks", + "pages": [ + "writing-tasks-introduction", + "logging", + "errors-retrying", + { + "group": "Wait", + "pages": ["wait", "wait-for", "wait-until", "wait-for-event", "wait-for-request"] + }, + "queue-concurrency", + "versioning", + "machines", + "idempotency", + "replaying", + "runs/max-duration", + "tags", + "runs/metadata", + "run-usage", + "context", + "bulk-actions", + "examples" + ] + }, + { + "group": "Frontend usage", + "pages": [ + "frontend/overview", + { + "group": "React hooks", + "pages": [ + "frontend/react-hooks/overview", + "frontend/react-hooks/realtime", + "frontend/react-hooks/triggering" + ] + } + ] + }, + { + "group": "Realtime API", + "pages": [ + "realtime/overview", + "realtime/streams", + "realtime/react-hooks", + "realtime/subscribe-to-run", + "realtime/subscribe-to-runs-with-tag", + "realtime/subscribe-to-batch" + ] + }, + { + "group": "API reference", + "pages": [ + "management/overview", + { + "group": "Tasks API", + "pages": ["management/tasks/trigger", "management/tasks/batch-trigger"] + }, + { + "group": "Runs API", + "pages": [ + "management/runs/list", + "management/runs/retrieve", + "management/runs/replay", + "management/runs/cancel", + "management/runs/reschedule", + "management/runs/update-metadata" + ] + }, + { + "group": "Schedules API", + "pages": [ + "management/schedules/list", + "management/schedules/create", + "management/schedules/retrieve", + "management/schedules/update", + "management/schedules/delete", + "management/schedules/deactivate", + "management/schedules/activate", + "management/schedules/timezones" + ] + }, + { + "group": "Env Vars API", + "pages": [ + "management/envvars/list", + "management/envvars/import", + "management/envvars/create", + "management/envvars/retrieve", + "management/envvars/update", + "management/envvars/delete" + ] + }, + { + "group": "Projects API", + "pages": ["management/projects/runs"] + } + ] + }, + { + "group": "CLI", + "pages": [ + "cli-introduction", + { + "group": "Commands", + "pages": [ + "cli-login-commands", + "cli-init-commands", + "cli-dev-commands", + "cli-deploy-commands", + "cli-whoami-commands", + "cli-logout-commands", + "cli-list-profiles-commands", + "cli-update-commands" + ] + } + ] + }, + { + "group": "Open source", + "pages": [ + "open-source-self-hosting", + "open-source-contributing", + "github-repo", + "changelog", + "roadmap" + ] + }, + { + "group": "Troubleshooting", + "pages": [ + "troubleshooting", + "upgrading-packages", + "upgrading-beta", + "troubleshooting-alerts", + "troubleshooting-uptime-status", + "troubleshooting-github-issues", + "request-feature" + ] + }, + { + "group": "Help", + "pages": ["community", "help-slack", "help-email"] + } + ] + }, + { + "dropdown": "Guides & examples", + "description": "A great way to get started", + "icon": "book", + "groups": [ + { + "group": "Introduction", + "pages": ["guides/introduction"] + }, + { + "group": "Frameworks", + "pages": [ + "guides/frameworks/bun", + "guides/frameworks/nextjs", + "guides/frameworks/nodejs", + "guides/frameworks/remix" + ] + }, + { + "group": "Guides", + "pages": [ + { + "group": "AI Agents", + "icon": { + "name": "microchip-ai", + "style": "regular" + }, + "pages": [ + "guides/ai-agents/overview", + "guides/ai-agents/generate-translate-copy", + "guides/ai-agents/route-question", + "guides/ai-agents/respond-and-check-content", + "guides/ai-agents/verify-news-article", + "guides/ai-agents/translate-and-refine" + ] + }, + "guides/frameworks/drizzle", + "guides/frameworks/prisma", + "guides/frameworks/sequin", + { + "group": "Supabase", + "icon": { + "name": "bolt", + "style": "solid" + }, + "pages": [ + "guides/frameworks/supabase-guides-overview", + "guides/frameworks/supabase-edge-functions-basic", + "guides/frameworks/supabase-edge-functions-database-webhooks" + ] + }, + { + "group": "Webhooks", + "icon": { + "name": "webhook", + "style": "solid" + }, + "pages": [ + "guides/frameworks/webhooks-guides-overview", + "guides/frameworks/nextjs-webhooks", + "guides/frameworks/remix-webhooks", + "guides/examples/stripe-webhook" + ] + } + ] + }, + { + "group": "Example projects", + "pages": [ + "guides/example-projects/realtime-fal-ai", + "guides/example-projects/batch-llm-evaluator", + "guides/example-projects/realtime-csv-importer", + "guides/example-projects/vercel-ai-sdk-image-generator" + ] + }, + { + "group": "Example tasks", + "pages": [ + "guides/examples/dall-e3-generate-image", + "guides/examples/deepgram-transcribe-audio", + "guides/examples/fal-ai-image-to-cartoon", + "guides/examples/fal-ai-realtime", + "guides/examples/ffmpeg-video-processing", + "guides/examples/firecrawl-url-crawl", + "guides/examples/libreoffice-pdf-conversion", + "guides/examples/open-ai-with-retrying", + "guides/examples/pdf-to-image", + "guides/examples/puppeteer", + "guides/examples/scrape-hacker-news", + "guides/examples/sentry-error-tracking", + "guides/examples/sharp-image-processing", + "guides/examples/supabase-database-operations", + "guides/examples/supabase-storage-upload", + "guides/examples/react-pdf", + "guides/examples/resend-email-sequence", + "guides/examples/vercel-ai-sdk", + "guides/examples/vercel-sync-env-vars" + ] + }, + { + "group": "Migrations", + "pages": ["guides/use-cases/upgrading-from-v2"] + } + ] + } + ] + }, + "logo": { + "light": "/logo/light.png", + "dark": "/logo/dark.png", + "href": "https://trigger.dev" + }, + "api": { + "openapi": ["openapi.yml", "v3-openapi.yaml"], + "playground": { + "display": "simple" + } + }, + "appearance": { + "default": "dark", + "strict": true + }, + "background": { + "color": { + "light": "#fff", + "dark": "#121317" + } + }, + "navbar": { + "primary": { + "type": "github", + "href": "https://github.com/triggerdotdev/trigger.dev" + } + }, + "footer": { + "socials": { + "x": "https://twitter.com/triggerdotdev", + "github": "https://github.com/triggerdotdev", + "linkedin": "https://www.linkedin.com/company/triggerdotdev" + }, + "links": [ + { + "header": "Developers", + "items": [ + { + "label": "Changelog", + "href": "https://trigger.dev/changelog" + }, + { + "label": "Contributing", + "href": "https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md" + }, + { + "label": "Open source", + "href": "https://github.com/triggerdotdev/trigger.dev?tab=Apache-2.0-1-ov-file#readme" + }, + { + "label": "GitHub", + "href": "https://github.com/triggerdotdev/trigger.dev" + }, + { + "label": "OSS Friends", + "href": "https://trigger.dev/oss-friends" + } + ] + }, + { + "header": "Product", + "items": [ + { + "label": "Pricing", + "href": "https://trigger.dev/pricing" + }, + { + "label": "How it works", + "href": "https://trigger.dev/#how-it-works" + }, + { + "label": "Features", + "href": "https://trigger.dev/product" + }, + { + "label": "Roadmap", + "href": "https://feedback.trigger.dev/roadmap" + }, + { + "label": "FAQs", + "href": "https://trigger.dev/pricing#faqs" + }, + { + "label": "Uptime status", + "href": "https://status.trigger.dev/" + } + ] + }, + { + "header": "Company", + "items": [ + { + "label": "Blog", + "href": "https://trigger.dev/blog" + }, + { + "label": "Contact", + "href": "https://trigger.dev/contact" + }, + { + "label": "Careers", + "href": "https://trigger.dev/jobs" + }, + { + "label": "Privacy", + "href": "https://trigger.dev/legal/privacy" + }, + { + "label": "Terms of service", + "href": "https://trigger.dev/legal" + } + ] + } + ] + }, + "redirects": [ + { + "source": "/v3/feature-matrix", + "destination": "https://feedback.trigger.dev/roadmap" + }, + { + "source": "/v3/upgrading-from-v2", + "destination": "/guides/use-cases/upgrading-from-v2" + }, + { + "source": "/v3/open-source-self-hosting", + "destination": "/open-source-self-hosting" + }, + { + "source": "/v3/:slug*", + "destination": "/:slug*" + }, + { + "source": "/reattempting-replaying", + "destination": "/replaying" + }, + { + "source": "/tasks-overview", + "destination": "/tasks/overview" + }, + { + "source": "/tasks-scheduled", + "destination": "/tasks/scheduled" + }, + { + "source": "/trigger-folder", + "destination": "/config/config-file" + }, + { + "source": "/trigger-config", + "destination": "/config/config-file" + }, + { + "source": "/guides/frameworks/introduction", + "destination": "/guides/introduction" + }, + { + "source": "/guides/examples/intro", + "destination": "/guides/introduction" + }, + { + "source": "/examples/:slug*", + "destination": "/guides/examples/:slug*" + }, + { + "source": "/realtime", + "destination": "/realtime/overview" + }, + { + "source": "/runs-and-attempts", + "destination": "/runs" + }, + { + "source": "/frontend/react-hooks", + "destination": "/frontend/react-hooks/overview" + } + ] +} diff --git a/docs/guides/ai-agents/evaluator-optimizer.png b/docs/guides/ai-agents/evaluator-optimizer.png new file mode 100644 index 0000000000..4ec95643cf Binary files /dev/null and b/docs/guides/ai-agents/evaluator-optimizer.png differ diff --git a/docs/guides/ai-agents/generate-translate-copy.mdx b/docs/guides/ai-agents/generate-translate-copy.mdx new file mode 100644 index 0000000000..127cb028ea --- /dev/null +++ b/docs/guides/ai-agents/generate-translate-copy.mdx @@ -0,0 +1,120 @@ +--- +title: "Generate and translate copy" +sidebarTitle: "Generate & translate copy" +description: "Create an AI agent workflow that generates and translates copy" +--- + +## Overview + +**Prompt chaining** is an AI workflow pattern that decomposes a complex task into a sequence of steps, where each LLM call processes the output of the previous one. This approach trades off latency for higher accuracy by making each LLM call an easier, more focused task, with the ability to add programmatic checks between steps to ensure the process remains on track. + +![Generating and translating copy](/guides/ai-agents/prompt-chaining.png) + +## Example task + +In this example, we'll create a workflow that generates and translates copy. This approach is particularly effective when tasks require different models or approaches for different inputs. + +**This task:** + +- Uses `generateText` from [Vercel's AI SDK](https://sdk.vercel.ai/docs/introduction) to interact with OpenAI models +- Uses `experimental_telemetry` to provide LLM logs +- Generates marketing copy based on subject and target word count +- Validates the generated copy meets word count requirements (±10 words) +- Translates the validated copy to the target language while preserving tone + +```typescript +import { openai } from "@ai-sdk/openai"; +import { task } from "@trigger.dev/sdk/v3"; +import { generateText } from "ai"; + +export interface TranslatePayload { + marketingSubject: string; + targetLanguage: string; + targetWordCount: number; +} + +export const generateAndTranslateTask = task({ + id: "generate-and-translate-copy", + maxDuration: 300, // Stop executing after 5 mins of compute + run: async (payload: TranslatePayload) => { + // Step 1: Generate marketing copy + const generatedCopy = await generateText({ + model: openai("o1-mini"), + messages: [ + { + role: "system", + content: "You are an expert copywriter.", + }, + { + role: "user", + content: `Generate as close as possible to ${payload.targetWordCount} words of compelling marketing copy for ${payload.marketingSubject}`, + }, + ], + experimental_telemetry: { + isEnabled: true, + functionId: "generate-and-translate-copy", + }, + }); + + // Gate: Validate the generated copy meets the word count target + const wordCount = generatedCopy.text.split(/\s+/).length; + + if ( + wordCount < payload.targetWordCount - 10 || + wordCount > payload.targetWordCount + 10 + ) { + throw new Error( + `Generated copy length (${wordCount} words) is outside acceptable range of ${ + payload.targetWordCount - 10 + }-${payload.targetWordCount + 10} words` + ); + } + + // Step 2: Translate to target language + const translatedCopy = await generateText({ + model: openai("o1-mini"), + messages: [ + { + role: "system", + content: `You are an expert translator specializing in marketing content translation into ${payload.targetLanguage}.`, + }, + { + role: "user", + content: `Translate the following marketing copy to ${payload.targetLanguage}, maintaining the same tone and marketing impact:\n\n${generatedCopy}`, + }, + ], + experimental_telemetry: { + isEnabled: true, + functionId: "generate-and-translate-copy", + }, + }); + + return { + englishCopy: generatedCopy, + translatedCopy, + }; + }, +}); +``` + +## Run a test + +On the Test page in the dashboard, select the `generate-and-translate-copy` task and include a payload like the following: + +```json +{ + marketingSubject: "The controversial new Jaguar electric concept car", + targetLanguage: "Spanish", + targetWordCount: 100, +} +``` + +This example payload generates copy and then translates it using sequential LLM calls. The translation only begins after the generated copy has been validated against the word count requirements. + +