
A Slack Agent template built with Workflow DevKit's DurableAgent, AI SDK tools, Bolt for JavaScript (TypeScript), and the Nitro server framework.
Before getting started, make sure you have a development workspace where you have permissions to install apps. You can use a developer sandbox or create a workspace.
git clone https://github.com/vercel-partner-solutions/slack-agent-template && cd slack-agent-template && pnpm install
manifest.json into the text box that says "Paste your manifest code here" (JSON tab) and click NextSLACK_BOT_TOKENSLACK_SIGNING_SECRETAI_GATEWAY_API_KEY to your .env file. You can get one hereNGROK_AUTH_TOKEN to your .env file. You can get one hereslack app linkupdate the manifest source to remote select yesLocal when prompted.slack/config.json and update your manifest source to local{"manifest": {"source": "local"},"project_id": "<project-id-added-by-slack-cli>"}
slack run. If prompted, select the workspace you'd like to grant access to
yes if asked "Update app settings with changes to the local manifest?"SLACK_BOT_TOKENSLACK_SIGNING_SECRETrequest_url and url fields use https://<your-app-domain>/api/slack/eventsmanifest.jsonmanifest.json is a configuration for Slack apps. With a manifest, you can create an app with a pre-defined configuration, or adjust the configuration of an existing app.
/server/app.ts/server/app.ts is the entry point of the application. This file is kept minimal and primarily serves to route inbound requests.
/server/lib/aiContains the AI agent implementation:
agent.ts — Creates the DurableAgent from Workflow with system instructions and available tools. The agent automatically handles tool calling loops until it has enough context to respond.
tools.ts — Tool definitions using AI SDK's tool function:
getChannelMessages — Fetches recent messages from a Slack channelgetThreadMessages — Fetches messages from a specific threadjoinChannel — Joins a public Slack channel (with Human-in-the-Loop approval)searchChannels — Searches for channels by name, topic, or purpose/server/listenersEvery incoming request is routed to a "listener". Inside this directory, we group each listener based on the Slack Platform feature used:
/listeners/assistant — Handles Slack Assistant events (thread started, user message, context changed)/listeners/actions — Handles interactive component actions (buttons, menus) including HITL approval handlers/listeners/shortcuts — Handles incoming Shortcuts requests/listeners/views — Handles View submissions/listeners/events — Handles Slack events like app mentions and home tab opens/server/apiThis is your Nitro server API directory. Contains events.post.ts which matches the request URL defined in your manifest.json. Nitro uses file-based routing for incoming requests. Learn more here.
The core agent loop is implemented as a durable workflow using Workflow DevKit. When a user sends a message, the workflow orchestrates the agent's response with automatic retry handling and streaming support.
┌─────────────────────────────────────────────────────────────────┐│ Chat Workflow │├─────────────────────────────────────────────────────────────────┤│ ││ User Message ──▶ assistantUserMessage listener ││ │ ││ ▼ ││ ┌─────────────────────┐ ││ │ start(chatWorkflow)│ ││ │ with messages + │ ││ │ context │ ││ └─────────────────────┘ ││ │ ││ ▼ ││ ┌─────────────────────┐ ││ │ createSlackAgent() │ ││ │ with tools │ ││ └─────────────────────┘ ││ │ ││ ▼ ││ ┌─────────────────────┐ ││ │ agent.stream() │──▶ Tool calls ││ │ generates response │ (may loop) ││ └─────────────────────┘ ││ │ ││ ▼ ││ ┌─────────────────────┐ ││ │ Stream chunks to │ ││ │ Slack via │ ││ │ chatStream() │ ││ └─────────────────────┘ ││ │ ││ ▼ ││ User sees response ││ │└─────────────────────────────────────────────────────────────────┘
Key files:
/server/lib/ai/workflows/chat.ts — The durable workflow definition using "use workflow" directive/server/lib/ai/agent.ts — Creates the DurableAgent with system prompt and tools/server/listeners/assistant/assistantUserMessage.ts — Listener that starts the workflow and streams responsesHow it works:
assistantUserMessage listener collects thread context and starts the workflowchatWorkflow creates the agent and calls agent.stream() with the messages"use step" for durability)chatStream()This template demonstrates a production-ready Human-in-the-Loop pattern using Workflow DevKit's defineHook primitive. When the agent needs to perform sensitive actions (like joining a channel), it pauses execution and waits for user approval.
┌─────────────────────────────────────────────────────────────────┐│ HITL Flow │├─────────────────────────────────────────────────────────────────┤│ ││ User Request ──▶ Agent ──▶ joinChannel Tool ││ │ ││ ▼ ││ ┌─────────────────────┐ ││ │ Send Slack message │ ││ │ with Approve/Reject│ ││ │ buttons │ ││ └─────────────────────┘ ││ │ ││ ▼ ││ ┌─────────────────────┐ ││ │ Workflow PAUSES │ ││ │ (no compute used) │◀── await hook ││ └─────────────────────┘ ││ │ ││ User clicks button ││ │ ││ ▼ ││ ┌─────────────────────┐ ││ │ Action handler │ ││ │ calls hook.resume()│ ││ └─────────────────────┘ ││ │ ││ ▼ ││ ┌─────────────────────┐ ││ │ Workflow RESUMES │ ││ │ with approval data │ ││ └─────────────────────┘ ││ │ ││ ▼ ││ Agent responds ││ │└─────────────────────────────────────────────────────────────────┘
Key files:
/server/lib/ai/workflows/hooks.ts — Hook definitions for HITL workflows (e.g., channelJoinApprovalHook)/server/lib/ai/tools.ts — Tool definitions including joinChannel which uses the approval hook/server/lib/slack/blocks.ts — Slack Block Kit UI for approval buttons/server/listeners/actions/channel-join-approval.ts — Action handler that resumes the workflowHow it works:
joinChannel tool is called by the agentchannelJoinApprovalHook.create() creates a hook instance and the workflow pauses at await hookhook.resume() with the decisionThis pattern can be extended for any action requiring human approval (e.g., sending messages, modifying data, external API calls).
Edit the system prompt in /server/lib/ai/agent.ts to change how your agent behaves, responds, and uses tools.
/server/lib/ai/tools.ts using AI SDK's tool function:import { tool } from "ai";import { z } from "zod";import type { SlackAgentContextInput } from "~/lib/ai/context";const myNewTool = tool({description: "Description of what this tool does",inputSchema: z.object({param: z.string().describe("Parameter description"),}),execute: async ({ param }, { experimental_context }) => {"use step"; // Required for Workflow's durable execution// Dynamic imports inside step to avoid bundling Node.js modules in workflowconst { WebClient } = await import("@slack/web-api");const ctx = experimental_context as SlackAgentContextInput;const client = new WebClient(ctx.token);// Tool implementationreturn { result: "..." };},});
slackTools export in /server/lib/ai/tools.ts/server/lib/ai/agent.ts to describe when to use the new toolLearn more about building agents with the AI SDK in the Agents documentation.
To add approval workflows to your own tools:
/server/lib/ai/workflows/hooks.ts:import { defineHook } from "workflow";import { z } from "zod";export const myApprovalHook = defineHook({schema: z.object({approved: z.boolean(),// Add any additional data you need}),});
"use step"), create and await the hook:execute: async ({ param }, { toolCallId, experimental_context }) => {const ctx = experimental_context as SlackAgentContextInput;// Send approval UI to user (in a step)await sendApprovalMessage(ctx, toolCallId);// Create hook and wait for approval (in workflow context)const hook = myApprovalHook.create({ token: toolCallId });const { approved } = await hook;if (!approved) {return { success: false, message: "User declined" };}// Perform the action (in a step)return await performAction(ctx);};
hook.resume() when the user respondsLearn more about hooks in the Workflow DevKit documentation.