# Business Workflows That Optimize Themselves

> Declarative TypeScript workflows with automatic execution, intelligent retry logic, and AI-powered optimization. Build complex multi-step processes with durable execution and automatic state persistence.

Canonical: https://workflows.do/

## In code

```ts
import { Workflows } from 'workflows.do'

// Declarative workflows with automatic retries
const workflow = Workflows.define({
  steps: [validateOrder, chargePayment, checkInventory, ship],
  retries: { max: 3, backoff: 'exponential' },
  durable: true
})

on.Order.created($ => workflow.execute({ order: $ }))

// AI optimizes workflows autonomously
on.Workflow.completed($ => $.AI.optimize.workflow($))
```

## Frequently asked questions

### How do workflows.do workflows differ from traditional automation tools?

Workflows.do uses declarative TypeScript—no visual builders, no XML, no proprietary DSLs. Just code that reads like business logic. Automatic execution, retry with exponential backoff, and monitoring built-in. Unlike Zapier or n8n, workflows run at the edge with <10ms latency and scale to millions of executions. Durable execution persists state automatically—workflows survive restarts, network failures, or hours-long waits.

### What happens if a step fails or times out?

Automatic retry with configurable policies: exponential backoff, max attempts, timeout per step. Dead letter queue captures permanently failed executions for manual review. Define compensation logic (sagas) for rollback scenarios: refund payment if inventory check fails. Circuit breakers prevent cascading failures by skipping steps that consistently fail. Full execution history and error diagnostics for debugging.

### Can workflows run for hours or days?

Yes. Durable execution with automatic state persistence to edge storage. Workflows can wait for external events (webhook received, human approval, scheduled time) without consuming resources. Pause execution, resume exactly where it stopped, even days later. Perfect for long-running business processes: multi-day approval chains, scheduled reports, or time-delayed actions.

### How do I test complex workflows locally?

Full local testing with Vitest or Jest—no cloud deployment required. Mock external services (APIs, databases, payment providers) using built-in mocking utilities. Simulate failures, timeouts, and retries to validate error handling. Time-travel debugging lets you inspect workflow state at any step. Record/replay production executions for regression testing. Dry-run mode executes workflows without side effects.

### Can AI agents modify workflows dynamically?

Yes. Workflows are semantic objects that agents can read, analyze, and optimize autonomously. Agents add error handling, insert monitoring steps, parallelize independent steps, add caching, or restructure workflows based on execution metrics. Agents can create new workflows from natural language descriptions. All agent modifications go through approval gates for safety. Rollback to previous workflow versions instantly.

## Part of Platform.do

workflows.do is one of the primitives of Platform.do, in the Workflows layer (triggers, steps and functions). Every .do shares one grammar, Business-as-Code, and one SDK.

- What is Business-as-Code? https://platform.do/business-as-code
- Platform.do: https://platform.do/
- Docs: https://docs.platform.do
