
Template details
AI SDK Slackbot
Open-source Slack chatbot built on Vercel's AI SDK, with policy-gated tools for weather, web search, and bash.
About this template
The AI SDK Slackbot is an open-source TypeScript template for building an AI-powered Slack assistant that uses Vercel's AI SDK to support any LLM provider and gates every tool call with Open Policy Agent policies. It is maintained by nicoalbanese on GitHub, licensed under MIT, and designed for one-click deployment on Vercel.
What is the AI SDK Slackbot?
The AI SDK Slackbot turns a Slack app into a conversational AI agent. It takes Slack messages — either direct messages or app mentions — as input, processes them through an LLM via Vercel's AI SDK, and produces threaded replies that can include tool results such as weather data, web search summaries, or sandboxed bash command output. The bot runs on Node.js 18+ and is built for deployment on Vercel, though it can be hosted anywhere capable of running a Node.js serverless function.
Key Features
- AI SDK integration — Uses Vercel's AI SDK to call any supported LLM provider; the default model is OpenAI's gpt-4o, and you can switch to local Ollama models like llama3.1 or qwen2.5 by setting
MODEL_PROVIDERandOLLAMA_MODELenvironment variables. - Policy-gated tool calls — Every tool invocation is checked against Open Policy Agent (Rego) policies defined in
policies/decision.rego; policies compile to WASM (policy.wasm) so the deployed bot runs them without needing theopabinary. - Built-in tools — Includes real-time weather lookup, web search powered by Exa (with optional domain restriction, e.g. "search for sports news on bbc.com"), and a sandboxed bash tool built on
bash-tool+just-bash. - Thread and DM context — The bot maintains conversation context within both Slack threads and direct messages, so users can have multi-turn conversations without losing track.
- Extensible architecture — New tools are added by extending the tools object in
lib/generate-response.ts; existing tools can be removed the same way, and the AI SDK's tool system handles the rest. - Vercel one-click deploy — The repo includes a Deploy with Vercel button that clones the project and sets up the required environment variables (
SLACK_BOT_TOKEN,SLACK_SIGNING_SECRET,OPENAI_API_KEY,EXA_API_KEY).
Who is it for?
- Developer teams building internal AI assistants — They can deploy this bot to answer questions in Slack using company documentation searches or database queries by adding custom tools.
- Solopreneurs and small businesses — They can launch a support bot that replies to direct messages with web search and weather capabilities, with setup limited to creating a Slack app and adding environment variables.
- AI/ML engineers experimenting with LLM tool-calling — They can test how the AI SDK handles tool selection, switch between OpenAI and local Ollama models, and enforce safety policies on tool use via Rego.
What can you do with the AI SDK Slackbot?
- Customer support agents: Reply to users in Slack DMs with answers grounded in web search results, using the optional domain restriction to limit sources to a specific site.
- DevOps and platform teams: Run sandboxed shell commands through Slack by leveraging the built-in bash tool, with policy gating that can restrict which commands are permitted.
- AI product developers: Evaluate different LLM providers on the same Slackbot codebase by toggling environment variables, then test tool-calling reliability — the page notes that qwen2.5 follows tool instructions more reliably than llama3.1:8b.
How does the AI SDK Slackbot work?
The bot listens to Slack events (app_mention, assistant_thread_started, message:im) at the /api/events endpoint. When a message arrives, it constructs a conversation with the AI SDK, which decides whether to call a tool; before a tool runs, OPA policy checks the input, and the tool result plus the model's text reply are sent back to the Slack thread. Deployment requires creating a Slack app with specific bot token scopes (app_mentions:read, assistant:write, chat:write, channels:history, im:history, im:read, im:write) and enabling event subscriptions with the production URL.
FAQ
Does the policy gating restrict the model's free text?
No. The Open Policy Agent policies only gate tool calls — the action a tool is allowed to take. The model's free-text answer is not constrained, so the bot could answer from training knowledge even if a search was limited to a domain. The page suggests output-side validation for hard guarantees, and the reply footer shows which tool ran.
Can I run the bot with a local model?
Yes. Set MODEL_PROVIDER=ollama and install Ollama (e.g. brew install ollama), then pull a model like llama3.1 or qwen2.5 and set OLLAMA_MODEL. No OPENAI_API_KEY is needed on this path, but the model must be reachable — a deployed Vercel function cannot reach localhost:11434, so Ollama is best for local development.
Do I need an Admin account in Slack?
The prerequisites state that you need a Slack workspace with admin privileges to create the Slack app and configure scopes, plus a server or hosting platform such as Vercel for deployment.
What are the environment variables?
SLACK_BOT_TOKEN, SLACK_SIGNING_SECRET, OPENAI_API_KEY, and EXA_API_KEY are required; optional settings include MODEL_PROVIDER, OLLAMA_MODEL, OPENAI_MODEL, and POLICY_MODE.















