This example shows how to use Workflow to make AI agents more reliable and production-ready by adding automatic retries, resume capabilities, and fault tolerance to AI SDK applications. It showcases a conversational flight booking assistant that can search flights, check status, and book tickets—all while being resilient to network failures and LLM errors.
- An API key from Vercel AI Gateway
-
Clone this example and install dependencies:
git clone https://github.com/vercel/workflow-examples cd workflow-examples/flight-booking-app pnpm install -
Create a
.env.localfile:touch .env.local
-
Add your API key to the
.env.localfile:AI_GATEWAY_API_KEY=your_api_key_here
-
Start the development server:
pnpm dev
-
Open http://localhost:3000 to see the app
Deploy directly to Vercel, no additional configuration is needed. Workflow works out of the box.
For non-Vercel deployments, you can configure a PostgreSQL World to handle workflow state persistence.
-
Set up a PostgreSQL database (Supabase, Neon, etc.)
-
Add environment variables:
WORKFLOW_TARGET_WORLD="@workflow/world-postgres" WORKFLOW_POSTGRES_URL="postgres://postgres:password@db.yourdb.co:5432/postgres" WORKFLOW_POSTGRES_JOB_PREFIX="workflow_" WORKFLOW_POSTGRES_WORKER_CONCURRENCY=10
-
Create the database schema:
pnpm exec workflow-postgres-setup -
Start the PostgreSQL World:
In your Next.js instrumentation.ts:
export async function register() {
if (process.env.NEXT_RUNTIME !== "edge") {
console.log("Starting workflow workers...");
import("workflow/runtime").then(async ({ getWorld }) => {
console.log("Starting Postgres World...");
await getWorld().start?.();
});
console.log("Workflow workers started!");
}
}- Deploy to your platform of choice
Learn more about the Workflow PostgreSQL World here.
- DurableAgent -
@workflow/ai'sDurableAgentprovides automatic retries, fault tolerance, and stream reconnection for AI SDK applications - Multi-turn conversations - Agent maintains conversation state across tool-calling loops and multiple LLM interactions
- Stream reconnection - Client can reconnect to in-progress workflows using
WorkflowChatTransportafter network failures - Tool execution - Five flight booking tools (search, status check, airport info, booking, baggage) showing real-world agent patterns
- PostgreSQL World - Optional PostgreSQL backend for custom deployment needs beyond Vercel (Railway, Render, etc.)
This project uses the following stack:
- Next.js 15 (App Router)
- Vercel AI SDK with
streamTextand tools - Workflow DevKit for durability
- Tailwind CSS for styling