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.
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.
generateObject
to categorize the lead based on the lead data and research report
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)
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.
manifest.json
file in the root of this repo. Paste this manifest file into the Slack dashboard when creating the app
git clone https://github.com/vercel-labs/lead-agent.gitcd lead-agent
pnpm install
cp .env.example .env.local
Configure the following variables:
# Vercel AI Gateway API KeyAI_GATEWAY_API_KEY# Slack BotSLACK_BOT_TOKENSLACK_SIGNING_SECRETSLACK_CHANNEL_ID# Exa API KeyEXA_API_KEY
pnpm dev
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
use workflow
This project uses Workflow DevKit to kick off a workflow that runs the agent, qualification, and other actions.
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
.
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
.
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
.
qualificationCategorySchema
in types.ts
lib/services.ts
lib/services.ts
lib/services.ts
MIT