VercelLogotypeVercelLogotype
LoginSign Up
Back to Templates

Lead Agent

An inbound lead qualification and research agent built with Next.js, AI SDK, Workflow DevKit, and the Vercel Slack Adapter.

DeployView Demo
Lead Agent demo screenshot

Lead Agent

An inbound lead qualification and research agent built with Next.js, AI SDK, Workflow DevKit, and the Vercel Slack Adapter. Hosted on the Vercel AI Cloud.

This is meant to serve as a reference architecture to be adapted to the needs of your specific organization.

Overview

Lead agent app that captures a lead in a contact sales form and then kicks off a qualification workflow and deep research agent. It integrates with Slack to send and receive messages for human-in-the-loop feedback.

  • Immediate Response - Returns a success response to the user upon submission
  • Workflows - Uses Workflow DevKit to kick off durable background tasks
    • Deep Research Agent - Conducts comprehensive research on the lead with a deep research agent
    • Qualify Lead - Uses generateObject to categorize the lead based on the lead data and research report
    • Write Email - Generates a personalized response email
    • Human-in-the-Loop - Sends to Slack for human approval before sending
    • Slack Webhook - Catches a webhook event from Slack to approve or deny the email

Deploy with Vercel

Architecture

User submits form
↓
start(workflow) ← (Workflow DevKit)
↓
Research agent ← (AI SDK Agent)
↓
Qualify lead ← (AI SDK generateObject)
↓
Generate email ← (AI SDK generateText)
↓
Slack approval (human-in-the-loop) ← (Slack integration)
↓
Send email (on approval)

Tech Stack

  • Framework: Next.js 16
  • Durable execution: Workflow DevKit
  • AI: Vercel AI SDK with AI Gateway
  • Human-in-the-Loop: Slack Bolt + Vercel Slack Bolt adapter
  • Web Search: Exa.ai

Slack Integration

This repo uses Slack's Bolt for JavaScript with the Vercel Slack Bolt adapter.

Slack's Bolt is the recommended way to build Slack apps with the latest platform features. While Bolt was designed for traditional long-running Node servers, Vercel's @vercel/slack-bolt adapter allows use of it in a serverless environment. Combining Slack's Bolt with Vercel's adapter reduces complexity and makes it easy to subscribe to Slack events and perform actions in your app.

Using this template

This repo contains various empty functions to serve as placeholders. To fully use this template, fill out empty functions in lib/services.ts.

Example: Add a custom implementation of searching your own knowledge base in queryKnowledgeBase.

Additionally, update prompts to meet the needs of your specific business function.

Getting Started

Prerequisites

  • Node.js 20+
  • pnpm (recommended) or npm
  • Slack workspace with bot token and signing secret
    • Reference the Vercel Slack agent template docs for creating a Slack app
    • You can set the permissions and configuration for your Slack app in the manifest.json file in the root of this repo. Paste this manifest file into the Slack dashboard when creating the app
    • Be sure to update the request URL for interactivity and event subscriptions to be your production domain URL
    • If Slack environment variables are not set, the app will still run with the Slack bot disabled
  • Vercel AI Gateway API Key
  • Exa API key

Installation

  1. Clone the repository:
git clone https://github.com/vercel-labs/lead-agent.git
cd lead-agent
  1. Install dependencies:
pnpm install
  1. Set up environment variables:
cp .env.example .env.local

Configure the following variables:

# Vercel AI Gateway API Key
AI_GATEWAY_API_KEY
# Slack Bot
SLACK_BOT_TOKEN
SLACK_SIGNING_SECRET
SLACK_CHANNEL_ID
# Exa API Key
EXA_API_KEY
  1. Run the development server:
pnpm dev
  1. Open http://localhost:3000 to see the application and submit a test lead.

Project Structure

lead-agent/
├── app/
│ ├── api/
│ │ ├── submit/ # Form submission endpoint that kicks off workflow
│ │ └── slack/ # Slack webhook handler (receives slack events)
│ └── page.tsx # Home page
├── lib/
│ ├── services.ts # Core business logic (qualify, research, email)
│ ├── slack.ts # Slack integration
│ └── types.ts # TypeScript schemas and types
├── components/
│ ├── lead-form.tsx # Main form component
└── workflows/
└── inbound/ # Inbound lead workflow
├── index.ts # Exported workflow function
└── steps.ts # Workflow steps

Key Features

Workflow durable execution with use workflow

This project uses Workflow DevKit to kick off a workflow that runs the agent, qualification, and other actions.

AI-Powered Qualification

Leads are automatically categorized (QUALIFIED, FOLLOW_UP, SUPPORT, etc.) using the latest OpenAI model via the Vercel AI SDK and generateObject. Reasoning is also provided for each qualification decision. Edit the qualification categories by changing the qualificationCategorySchema in lib/types.ts.

AI SDK Agent class

Uses the AI SDK Agent class to create an autonomous research agent. Create new tools for the Agent and edit prompts in lib/services.ts.

Human-in-the-Loop Workflow

Generated emails are sent to Slack with approve/reject buttons, ensuring human oversight before any outbound communication.

The Slack message is defined with Slack's Block Kit. It can be edited in lib/slack.ts.

Extensible Architecture

  • Add new qualification categories in the qualificationCategorySchema in types.ts
  • Adjust the prompts and configuration for all AI calls in lib/services.ts
  • Alter the agent by tuning parameters in lib/services.ts
  • Add new service functions if needed in lib/services.ts
  • Follow Vercel Workflow docs to add new steps to the workflow
  • Create new workflows for other qualification flows, outbound outreach, etc.

License

MIT

GitHub Repovercel-labs/lead-agent
LicenseView License
Use Cases
AI
Stack
Next.jsTailwind

Related Templates

Get Started

  • Templates
  • Supported frameworks
  • Marketplace
  • Domains

Build

  • Next.js on Vercel
  • Turborepo
  • v0

Scale

  • Content delivery network
  • Fluid compute
  • CI/CD
  • Observability
  • AI GatewayNew
  • Vercel AgentNew

Secure

  • Platform security
  • Web Application Firewall
  • Bot management
  • BotID
  • SandboxNew

Resources

  • Pricing
  • Customers
  • Enterprise
  • Articles
  • Startups
  • Solution partners

Learn

  • Docs
  • Blog
  • Changelog
  • Knowledge Base
  • Academy
  • Community

Frameworks

  • Next.js
  • Nuxt
  • Svelte
  • Nitro
  • Turbo

SDKs

  • AI SDK
  • Workflow SDKNew
  • Flags SDK
  • Chat SDK
  • Streamdown AINew

Use Cases

  • Composable commerce
  • Multi-tenant platforms
  • Web apps
  • Marketing sites
  • Platform engineers
  • Design engineers

Company

  • About
  • Careers
  • Help
  • Press
  • Legal
  • Privacy Policy

Community

  • Open source program
  • Events
  • Shipped on Vercel
  • GitHub
  • LinkedIn
  • X
  • YouTube

Loading status…

Select a display theme:
    • AI Cloud
      • v0

        Build applications with AI

      • AI SDK

        The AI Toolkit for TypeScript

      • AI Gateway

        One endpoint, all your models

      • Vercel Agent

        An agent that knows your stack

      • Sandbox

        AI workflows in live environments

    • Core Platform
      • CI/CD

        Helping teams ship 6× faster

      • Content Delivery

        Fast, scalable, and reliable

      • Fluid Compute

        Servers, in serverless form

      • Observability

        Trace every step

    • Security
      • Bot Management

        Scalable bot protection

      • BotID

        Invisible CAPTCHA

      • Platform Security

        DDoS Protection, Firewall

      • Web Application Firewall

        Granular, custom protection

    • Company
      • Customers

        Trusted by the best teams

      • Blog

        The latest posts and changes

      • Changelog

        See what shipped

      • Press

        Read the latest news

      • Events

        Join us at an event

    • Learn
      • Docs

        Vercel documentation

      • Academy

        Linear courses to level up

      • Knowledge Base

        Find help quickly

      • Community

        Join the conversation

    • Open Source
      • Next.js

        The native Next.js platform

      • Nuxt

        The progressive web framework

      • Svelte

        The web’s efficient UI framework

      • Turborepo

        Speed with Enterprise scale

    • Use Cases
      • AI Apps

        Deploy at the speed of AI

      • Composable Commerce

        Power storefronts that convert

      • Marketing Sites

        Launch campaigns fast

      • Multi-tenant Platforms

        Scale apps with one codebase

      • Web Apps

        Ship features, not infrastructure

    • Tools
      • Marketplace

        Extend and automate workflows

      • Templates

        Jumpstart app development

      • Partner Finder

        Get help from solution partners

    • Users
      • Platform Engineers

        Automate away repetition

      • Design Engineers

        Deploy for every idea

  • Enterprise
  • Pricing
Log InContact
Sign Up
Sign Up
Back to Templates
DeployView Demo

Chat SDK Knowledge Agent

Open source file-system and knowledge based agent template. Build AI agents that stay up to date with your knowledge base.
Chat SDK Knowledge Agent

Sales Call Summary AI Agent

Build an AI agent to analyze sales call data using Vercel Sandbox and AI SDK. Features secure code execution and durable workflows.
Sales Call Summary AI Agent

Markdown to agents, HTML to humans

Demo project for delivering markdown to agents and HTML to humans.
Markdown to agents, HTML to humans
v0

Build applications with AI

AI SDK

The AI Toolkit for TypeScript

AI Gateway

One endpoint, all your models

Vercel Agent

An agent that knows your stack

Sandbox

AI workflows in live environments

CI/CD

Helping teams ship 6× faster

Content Delivery

Fast, scalable, and reliable

Fluid Compute

Servers, in serverless form

Observability

Trace every step

Bot Management

Scalable bot protection

BotID

Invisible CAPTCHA

Platform Security

DDoS Protection, Firewall

Web Application Firewall

Granular, custom protection

Customers

Trusted by the best teams

Blog

The latest posts and changes

Changelog

See what shipped

Press

Read the latest news

Events

Join us at an event

Docs

Vercel documentation

Academy

Linear courses to level up

Knowledge Base

Find help quickly

Community

Join the conversation

Next.js

The native Next.js platform

Nuxt

The progressive web framework

Svelte

The web’s efficient UI framework

Turborepo

Speed with Enterprise scale

AI Apps

Deploy at the speed of AI

Composable Commerce

Power storefronts that convert

Marketing Sites

Launch campaigns fast

Multi-tenant Platforms

Scale apps with one codebase

Web Apps

Ship features, not infrastructure

Marketplace

Extend and automate workflows

Templates

Jumpstart app development

Partner Finder

Get help from solution partners

Platform Engineers

Automate away repetition

Design Engineers

Deploy for every idea