Combine the Vercel AI SDK's tool calling with Reloop to trigger intelligent, context-aware email notifications from any AI-powered Next.js application.
Why combine Vercel AI SDK with Reloop
The Vercel AI SDK makes it trivially easy to add tool calling to any Next.js app. Reloop gives you reliable, observable email delivery. Together, they let your AI decide when to send an email and what to say, while Reloop handles the infrastructure.
Setting up the tool
Define a notifyUser tool using the AI SDK's tool() helper and the Zod schema it expects:
1import { tool } from "ai";2import { z } from "zod";3import { Reloop } from "reloop-email";4
5const reloop = new Reloop(process.env.RELOOP_API_KEY!);6
7export const notifyUser = tool({8 description: "Send an email notification to the user about a task or event.",9 parameters: z.object({10 email: z.string().email(),11 subject: z.string(),12 message: z.string(),13 }),14 execute: async ({ email, subject, message }) => {15 await reloop.emails.send({16 from: "notifications@yourdomain.com",17 to: email,18 subject,19 html: `<p>${message}</p>`,20 });21 return { delivered: true };22 },23});Wiring it into a Server Action
1import { streamText } from "ai";2import { openai } from "@ai-sdk/openai";3
4export async function runAgent(prompt: string, userEmail: string) {5 return streamText({6 model: openai("gpt-4o"),7 prompt,8 tools: { notifyUser },9 });10}Example: a task completion agent
When a long-running background task finishes, the model can decide to notify the user by email rather than just returning a response. This keeps the user in the loop without polling.
Observability
Every email triggered by the AI agent appears in Reloop's logs with full metadata: subject, recipient, timestamp, delivery status. You can see exactly what your agent sent and when.
Read more
Build an AI Agent That Sends Emails on Your Behalf
Learn how to build an autonomous AI agent that composes and sends emails using tool calling, with Reloop handling delivery.

How to Send Email in Next.js App Router (2026)
Send transactional email from Next.js App Router with Reloop: complete Server Action and Route Handler examples, env setup, error handling, and Vercel deploy.
How to Use AI to Generate Transactional Email Templates
Use LLMs to generate, personalize, and iterate on transactional email templates, then send them reliably with Reloop.
I Let an AI Agent Read and Reply to My Emails. Here's How the Infrastructure Works.
Building an AI agent that reads and replies to email is easy in LangChain. Owning the send-and-receive layer is the hard part, and why open-source email infrastructure matters.
Ship your first email with Reloop
in minutes.
Open-source, deliverability-focused, and yours to self-host or run on Reloop Cloud. No lock-in, no rewrite later.