Temporal-Gen Natural Language Workflows
Define production-grade Temporal workflows using natural language with AI code generation.
Workflow Steps
- 1
Install Temporal server
- 2
Install Temporal-Gen CLI
- 3
Describe workflow in natural language
- 4
Review generated code
- 5
Deploy to Temporal
Download
Documentation
Temporal-Gen: Natural Language Workflow Definition
Overview
Temporal-Gen is an AI-powered extension for Temporal, the distributed workflow orchestration engine. Released as a preview in July 2026 with over 1,100 GitHub stars on launch day, Temporal-Gen enables developers to define complex workflows using natural language instead of traditional code.
With Temporal-Gen, you can describe workflows in plain English: "Every 5 minutes, check inventory levels and trigger a restock order and manager notification if below threshold." The AI engine automatically generates production-grade TypeScript or Go workflow code that integrates with Temporal's reliability guarantees.
Features
- Natural Language Workflow Definition: Describe workflows in plain English
- Auto Code Generation: Generate TypeScript or Go workflow code automatically
- Breakpoint Replay: Resume workflows from any point after failure
- Intelligent Error Recovery: Agent auto-adjusts parameters on Activity failures
- Fallback API Switching: Automatically switch to backup APIs when primary fails
- Temporal Reliability: Inherits Temporal's strong consistency and fault tolerance
- TypeScript and Go Support: Generate workflows in either language
- Preview Mode: Test workflows before production deployment
Installation
# Install Temporal-Gen via npm
npm install -g @temporalio/gen
# Or via Go
go install github.com/temporalio/temporal-gen/cmd/temporal-gen@latest
# Start Temporal server locally
docker run -p 7233:7233 temporalio/auto-setup
Quick Start
Define a Workflow in Natural Language
# Via CLI
temporal-gen workflow "Every 5 minutes check inventory, if below threshold trigger restock and notify manager"
# Generated TypeScript code:
```typescript
import { proxyActivities, Workflow } from '@temporalio/workflow';
const { checkInventory, triggerRestock, notifyManager } = proxyActivities({
checkInventory: { startToCloseTimeout: '30 seconds' },
triggerRestock: { startToCloseTimeout: '60 seconds' },
notifyManager: { startToCloseTimeout: '30 seconds' }
});
export async function inventoryCheckWorkflow(threshold: number): Promise<void> {
while (true) {
const inventory = await checkInventory();
if (inventory.currentLevel < threshold) {
const restockOrder = await triggerRestock({
item: inventory.itemId,
quantity: threshold - inventory.currentLevel
});
await notifyManager({
subject: 'Inventory Restock Triggered',
body: `Restock order ${restockOrder.id} placed for ${inventory.itemId}`
});
}
await Workflow.sleep(5 * 60 * 1000); // 5 minutes
}
}
Core Concepts
Workflow Definition Syntax
# Simple scheduled workflow
temporal-gen workflow "Every hour fetch data from API and process it"
# Conditional workflow
temporal-gen workflow "If error occurs during payment processing, retry 3 times with exponential backoff, then notify support"
# Multi-step workflow
temporal-gen workflow "Process order: validate, check inventory, charge payment, update inventory, send confirmation"
Intelligent Error Recovery
Temporal-Gen includes an AI agent that automatically handles failures:
// Auto-generated with error recovery
export async function resilientPaymentWorkflow(order: Order): Promise<void> {
let paymentStatus = null;
for (let attempt = 1; attempt <= 3; attempt++) {
try {
paymentStatus = await chargePayment(order.id, order.amount);
break; // Success, exit loop
} catch (error) {
if (error.code === 'INSUFFICIENT_FUNDS') {
// Notify customer to try different payment method
await notifyCustomer({
order: order.id,
message: 'Payment failed: insufficient funds'
});
throw error;
}
// AI agent: Adjust parameters and retry
const adjustedAmount = await aiAdjustPaymentParams(order.amount, error);
await Workflow.sleep(Math.pow(2, attempt) * 1000); // Exponential backoff
}
}
}
Breakpoint Replay
// Resume workflow from any point
export async function resumableWorkflow(input: any): Promise<void> {
const step1 = await stepOne(input);
// Workflow can be paused here and resumed later
await Workflow.condition(() => resumeSignal, 5 * 60 * 1000);
const step2 = await stepTwo(step1);
const step3 = await stepThree(step2);
}
Advanced Features
Complex Workflow Definition
# Multi-condition workflow with fallback
temporal-gen workflow \
"Every 15 minutes check server health. If CPU > 80%, scale up. If memory > 90%, restart service. If both, alert on-call engineer with severity high"
Generated code includes:
- Parallel condition checking
- Conditional scaling actions
- Service restart with health verification
- Multi-channel alerting
Fallback API Switching
// Auto-generated with fallback API support
export async function resilientDataFetchWorkflow(url: string): Promise<Data> {
const primaryApi = new ApiClient(url);
const fallbackApi = new ApiClient(url.replace('.com', '-backup.io'));
try {
return await primaryApi.fetch();
} catch (error) {
console.warn('Primary API failed, switching to fallback');
return await fallbackApi.fetch();
}
}
Agent-Driven Error Recovery
// AI agent automatically adjusts parameters
export async function intelligentRetryWorkflow(params: any): Promise<void> {
const aiRecoveryAgent = new AIRecoveryAgent();
for (let attempt = 1; attempt <= 5; attempt++) {
try {
await executeActivity(params);
break;
} catch (error) {
// AI agent analyzes error and suggests parameter adjustments
const adjustedParams = await aiRecoveryAgent.analyzeError(error, params);
params = adjustedParams;
await Workflow.sleep(exponentialBackoff(attempt));
}
}
}
Examples
Example 1: Order Processing Workflow
temporal-gen workflow \
"Process order: validate customer info, check inventory, charge payment, update inventory, send confirmation email, and log to database"
Example 2: Data Processing Pipeline
temporal-gen workflow \
"Every hour: fetch data from API, transform data, validate schema, load to database, and if errors occur, send alert to data engineering team"
Example 3: Customer Onboarding
temporal-gen workflow \
"New customer onboarding: verify identity, create account, send welcome email, provision resources, and if any step fails, notify customer support with error details"
TypeScript SDK
import { Workflow } from '@temporalio/workflow';
import { Activity } from '@temporalio/activities';
// Generated workflow with Temporal-Gen
export class InventoryCheckWorkflow {
@Activity({
scheduleToCloseTimeout: '30 seconds',
retry: {
maximumAttempts: 3,
initialInterval: '5 seconds'
}
})
async checkInventory(): Promise<Inventory> {
// Activity implementation
}
@Workflow
async execute(threshold: number): Promise<void> {
// Workflow logic
}
}
Go SDK
package workflows
import (
"context"
"time"
"go.temporal.io/sdk/workflow"
)
// Generated workflow with Temporal-Gen
type InventoryCheckWorkflow struct {
threshold int
}
func (w *InventoryCheckWorkflow) Execute(ctx workflow.Context, threshold int) error {
ao := workflow.ActivityOptions{
StartToCloseTimeout: 30 * time.Second,
RetryPolicy: &temporal.RetryPolicy{
MaximumAttempts: 3,
InitialInterval: 5 * time.Second,
},
}
ctx = workflow.WithActivityOptions(ctx, ao)
for {
var inventory Inventory
err := workflow.ExecuteActivity(ctx, CheckInventory).Get(ctx, &inventory)
if err != nil {
return err
}
if inventory.CurrentLevel < w.threshold {
// Trigger restock
}
// Sleep for 5 minutes
workflow.Sleep(ctx, 5*time.Minute)
}
}
Pros
- ✅ Natural Language Definition: No workflow code expertise required
- ✅ Temporal Reliability: Inherits Temporal's fault tolerance and consistency
- ✅ Intelligent Error Recovery: AI-driven parameter adjustment and fallback switching
- ✅ Breakpoint Replay: Resume workflows from any point
- ✅ Dual-Language Support: TypeScript and Go generation
- ✅ Preview Testing: Test before production deployment
Cons
- ✅ Preview Status: Not yet recommended for production
- ✅ Complex Workflows: May struggle with highly complex business logic
- ✅ Temporal Dependency: Requires Temporal server infrastructure
- ✅ New Project: Limited community and documentation
When to Use
- Rapid Prototyping: Quickly test workflow ideas without coding
- Non-Technical Stakeholders: Business users define workflows in plain language
- Complex Error Handling: Leverage AI-driven error recovery
- Resilient Systems: Use Temporal's reliability guarantees
- Multi-Language Teams: Generate workflows in TypeScript or Go
- Learning Workflows: Understand workflow concepts through natural language
