Overview
GTM Feedback uses Workflow DevKit (use workflow) for durable execution of background tasks.
Workflows are long-running processes that can be paused, resumed, and retried automatically. They’re perfect for AI operations, external API calls, and multi-step processes.
What are Workflows?
Workflows provide durable execution for:- AI-powered processing - Semantic matching, request creation, insights generation
- External integrations - Slack notifications, webhook calls
- Multi-step orchestration - Fan-out/fan-in patterns, sequential steps
- Resilient operations - Automatic retries, error recovery
Feedback Processing
Match feedback to feature requests using AI agents
Request Creation
Generate new feature requests from feedback
Insights Generation
Analyze product areas and generate reports
Slack Integration
Send notifications and approval requests
Workflow Structure
Workflows are located inapps/www/src/workflows/ organized by domain:
Creating a Workflow
Basic Workflow Pattern
Every workflow function must include the"use workflow" directive:
Real-World Example: Area Insights
Fromworkflows/area-insights/index.ts:
Workflow Patterns
Pattern 1: Parallel Execution (Fan-out)
Execute multiple steps in parallel:Pattern 2: Sequential Execution
Execute steps one after another:Pattern 3: Conditional Execution
Execute steps based on conditions:Pattern 4: Error Recovery
Handle errors gracefully:Workflow Steps
Organize complex logic into reusable steps:Testing Workflows Locally
Trigger a workflow
Workflows can be triggered from:
- API routes -
POST /api/workflows/my-workflow - Server actions - Call workflow from an action
- Cron jobs - Scheduled execution
- Event handlers - Slack events, webhooks
Workflow Execution & Monitoring
Triggering Workflows
- From API Routes
- From Server Actions
- From Cron Jobs
app/api/workflows/my-workflow/route.ts
Monitoring Best Practices
Structured Logging
Use consistent log levels and structured data
Error Tracking
Log errors with context for debugging
Duration Tracking
Measure and log execution time
Result Reporting
Return meaningful status and results
AI Integration in Workflows
Many workflows use AI agents frompackages/ai/src/agents/:
Common Workflow Operations
Revalidate Next.js paths
Revalidate Next.js paths
Invalidate cache after mutations:
Call external APIs
Call external APIs
Make HTTP requests to external services:
Send Slack notifications
Send Slack notifications
Integrate with Slack:
Process in batches
Process in batches
Handle large datasets efficiently:
Best Practices
Always use 'use workflow'
Required directive at the top of workflow functions
Structured logging
Use consistent logger with workflow name
Error handling
Catch errors and return meaningful status
Idempotency
Design workflows to be safely retried
Small steps
Break complex workflows into focused steps
Type safety
Define clear TypeScript types for args and returns
Next Steps
Contributing
Read contribution guidelines
Workflow DevKit
Learn more about Workflow DevKit