home / skills / andrelandgraf / fullstackrecipes / ai-agent-workflow

ai-agent-workflow skill

/skills/ai-agent-workflow

This skill helps build resumable multi-agent workflows with durable execution and automatic stream recovery across client reconnections.

npx playbooks add skill andrelandgraf/fullstackrecipes --skill ai-agent-workflow

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.9 KB
---
name: ai-agent-workflow
description: Build resumable multi-agent workflows with durable execution, tool loops, and automatic stream recovery on client reconnection.
---

# Multi-Agent Workflows

Build resumable multi-agent workflows with durable execution, tool loops, and automatic stream recovery on client reconnection.

## Prerequisites

Complete these recipes first (in order):

### Type-Safe Environment Configuration

Type-safe environment variable validation using Zod with a Drizzle-like schema API. Supports server/public fields, feature flags, either-or constraints, and client-side protection.

```bash
curl -H "Accept: text/markdown" https://fullstackrecipes.com/api/recipes/config-schema-setup
```

### Neon + Drizzle Setup

Connect a Next.js app to Neon Postgres using Drizzle ORM with optimized connection pooling for Vercel serverless functions.

```bash
curl -H "Accept: text/markdown" https://fullstackrecipes.com/api/recipes/neon-drizzle-setup
```

### Better Auth Setup

Add user authentication using Better Auth with Drizzle ORM and Neon Postgres. Base setup with email/password authentication.

```bash
curl -H "Accept: text/markdown" https://fullstackrecipes.com/api/recipes/better-auth-setup
```

### AI Chat Persistence with Neon

Persist AI chat conversations to Neon Postgres with full support for AI SDK message parts including tools, reasoning, and streaming. Uses UUID v7 for chronologically-sortable IDs.

```bash
curl -H "Accept: text/markdown" https://fullstackrecipes.com/api/recipes/ai-chat-persistence
```

### Pino Logging Setup

Configure structured logging with Pino. Outputs human-readable colorized logs in development and structured JSON in production for log aggregation services.

```bash
curl -H "Accept: text/markdown" https://fullstackrecipes.com/api/recipes/pino-logging-setup
```

## Cookbook - Complete These Recipes in Order

### Workflow Development Kit Setup

Install and configure the Workflow Development Kit for resumable, durable AI agent workflows with step-level persistence, stream resumption, and agent orchestration.

```bash
curl -H "Accept: text/markdown" https://fullstackrecipes.com/api/recipes/workflow-setup
```

### Resumable AI Response Streams

Add automatic stream recovery to AI chat with WorkflowChatTransport, start/resume API endpoints, and the useResumableChat hook.

```bash
curl -H "Accept: text/markdown" https://fullstackrecipes.com/api/recipes/resumable-ai-streams
```

### Custom Durable Agent

Build a custom durable AI agent with full control over streamText options, provider configs, and tool loops. Compatible with the Workflow Development Kit.

```bash
curl -H "Accept: text/markdown" https://fullstackrecipes.com/api/recipes/custom-durable-agent
```

### Working with Workflows

Create and run durable workflows with steps, streaming, and agent execution. Covers starting, resuming, and persisting workflow results.

```bash
curl -H "Accept: text/markdown" https://fullstackrecipes.com/api/recipes/using-workflows
```

Overview

This skill builds resumable, multi-agent AI workflows with durable execution, tool loops, and automatic stream recovery when clients reconnect. It provides step-level persistence, streaming resumption, and orchestration primitives so long-running or interactive flows survive restarts and network drops. The goal is reliable, production-ready agent orchestration for full-stack web AI apps.

How this skill works

The skill wires a Workflow Development Kit into your TypeScript stack to persist workflow steps and agent state to a database. It captures streaming output and saves offsets so chat or agent streams can resume automatically on reconnect. Custom durable agents and tool loops run under durable execution semantics, and APIs/hooks let the client start, pause, resume, and monitor workflows.

When to use it

  • Coordinating multiple AI agents that must share state across steps
  • Long-running or multi-step automations that must survive server restarts
  • Interactive chat experiences that require stream resumption on client reconnect
  • Workflows that call external tools repeatedly and need durable retry/looping
  • Persisting provenance and results of agent executions for auditing or debugging

Best practices

  • Set up type-safe env configuration and database (Neon + Drizzle) before integrating workflows
  • Persist chat and step outputs with UUID v7-style IDs for chronological ordering
  • Use structured logging (Pino) to capture workflow lifecycle events and errors
  • Design steps to be idempotent so resumed execution is safe after partial runs
  • Expose explicit start/resume endpoints and use a client hook for automatic reconnection

Example use cases

  • A multi-agent research assistant that spawns separate agents for retrieval, synthesis, and summarization and resumes after network drops
  • An automated onboarding pipeline that runs identity checks, data enrichment, and email sequences with durable retries
  • A customer support chat that streams draft responses from an agent and resumes streaming when a user reconnects
  • An ETL-style workflow where agents call external APIs and loop tools until data quality checks pass
  • A content-generation pipeline that persists intermediate drafts and allows manual review before continuing

FAQ

Do I need a specific database?

You should use a transactional database that supports connection pooling in serverless environments; Neon Postgres with Drizzle is the recommended pattern here.

How does stream recovery work on reconnect?

The system saves stream offsets and partial outputs to the workflow store. When a client reconnects, the hook or API resumes the stream from the saved offset so the user sees continuity.