A minimal starter template for building AI-powered Slack agents with Bolt for Python and Pydantic AI using models from Anthropic or OpenAI. Works with the Slack MCP Server to search messages, read channels, send messages, and manage canvases — all from within your agent.
The starter agent interacts with users through four entry points:
- App Home — Displays a welcome message with instructions on how to interact.
- Direct Messages — Users message the agent directly. It responds in-thread, maintaining context across follow-ups.
- Channel @mentions — Mention the agent in any channel to get a response without leaving the conversation.
- Assistant Panel — Users click Add Agent in Slack, select the agent, and pick from suggested prompts or type a message.
The template also includes one example tool (emoji reactions). Add your own tools to customize it for your use case.
When connected to the Slack MCP Server, the agent can search messages and files, read channel history and threads, send and schedule messages, and create and update canvases. When deployed with OAuth (HTTP mode), the agent automatically connects to the Slack MCP Server using the user's token.
Before getting started, make sure you have a development workspace where you have permissions to install apps.
Join the Slack Developer Program for exclusive access to sandbox environments for building and testing your apps, tooling, and resources created to help you build and grow.
Using Slack CLI
Install the latest version of the Slack CLI for your operating system:
You'll also need to log in if this is your first time using the Slack CLI.
slack loginslack create my-starter-agent --template slack-samples/bolt-python-starter-agent --subdir pydantic-ai
cd my-starter-agentUsing App Settings
- Open https://api.slack.com/apps/new and choose "From an app manifest"
- Choose the workspace you want to install the application to
- Copy the contents of manifest.json into the text box that says
*Paste your manifest code here*(within the JSON tab) and click Next - Review the configuration and click Create
- Click Install to Workspace and Allow on the screen that follows. You'll then be redirected to the App Configuration dashboard.
Before you can run the app, you'll need to store some environment variables.
- Rename
.env.sampleto.env. - Open your apps setting page from this list, click OAuth & Permissions in the left hand menu, then copy the Bot User OAuth Token into your
.envfile underSLACK_BOT_TOKEN.
SLACK_BOT_TOKEN=YOUR_SLACK_BOT_TOKEN- Click Basic Information from the left hand menu and follow the steps in the App-Level Tokens section to create an app-level token with the
connections:writescope. Copy that token into your.envasSLACK_APP_TOKEN.
SLACK_APP_TOKEN=YOUR_SLACK_APP_TOKENgit clone https://github.com/slack-samples/bolt-python-starter-agent.git my-starter-agent
cd my-starter-agentpython3 -m venv .venv
source .venv/bin/activate # for Windows OS, .\.venv\Scripts\Activate instead should workpip install -r requirements.txtThis app supports both Anthropic and OpenAI as AI providers. Set at least one API key — if both are set, Anthropic is used by default.
Uses Anthropic's claude-sonnet-4-6 model through Pydantic AI.
- Create an API key from your Anthropic dashboard.
- Rename
.env.sampleto.env. - Save the Anthropic API key to
.env:
ANTHROPIC_API_KEY=YOUR_ANTHROPIC_API_KEYUses OpenAI's gpt-4.1-mini model through Pydantic AI.
- Create an API key from your OpenAI dashboard.
- Rename
.env.sampleto.env. - Save the OpenAI API key to
.env:
OPENAI_API_KEY=YOUR_OPENAI_API_KEYUsing OAuth HTTP Server (with ngrok)
This mode uses an HTTP server instead of Socket Mode, which is required for OAuth-based distribution.
- Install ngrok and start a tunnel:
ngrok http 3000- Copy the
https://*.ngrok-free.appURL from the ngrok output.
Using Slack CLI
-
Update
manifest.jsonfor HTTP mode:- Set
socket_mode_enabledtofalse - Replace
ngrok-free.appwith your ngrok domain (e.g.YOUR_NGROK_SUBDOMAIN.ngrok-free.app)
- Set
-
Create a new local dev app:
slack install -E local-
Enable MCP for your app:
- Run
slack app settingsto open your app's settings - Navigate to Agents & AI Apps in the left-side navigation
- Toggle Model Context Protocol on
- Run
-
Update your
.envOAuth environment variables:- Run
slack app settingsto open App Settings - Copy Client ID, Client Secret, and Signing Secret
- Update
SLACK_REDIRECT_URIin.envwith your ngrok domain
- Run
SLACK_CLIENT_ID=YOUR_CLIENT_ID
SLACK_CLIENT_SECRET=YOUR_CLIENT_SECRET
SLACK_SIGNING_SECRET=YOUR_SIGNING_SECRET
SLACK_REDIRECT_URI=https://YOUR_NGROK_SUBDOMAIN.ngrok-free.app/slack/oauth_redirect- Start the app:
slack run app_oauth.py- Click the install URL printed in the terminal to install the app to your workspace via OAuth.
Using the Terminal
-
Create your Slack app at api.slack.com/apps/new using
manifest.json. Before pasting the manifest, setsocket_mode_enabledtofalseand replacengrok-free.appwith your ngrok domain. -
Install the app to your workspace and copy the following values into your
.env:- Signing Secret — from Basic Information
- Bot User OAuth Token — from OAuth & Permissions
- Client ID and Client Secret — from Basic Information
SLACK_BOT_TOKEN=xoxb-YOUR_BOT_TOKEN
SLACK_CLIENT_ID=YOUR_CLIENT_ID
SLACK_CLIENT_SECRET=YOUR_CLIENT_SECRET
SLACK_SIGNING_SECRET=YOUR_SIGNING_SECRET
SLACK_REDIRECT_URI=https://YOUR_NGROK_SUBDOMAIN.ngrok-free.app/slack/oauth_redirectReplace your-subdomain in SLACK_REDIRECT_URI with your ngrok subdomain.
-
Enable MCP for your app:
- Open your app at api.slack.com/apps
- Navigate to Agents & AI Apps in the left-side navigation
- Toggle Model Context Protocol on
-
Start the app:
python3 app_oauth.py- Click the install URL printed in the terminal to install the app to your workspace via OAuth.
Note: Each time ngrok restarts, it generates a new URL. You'll need to update the ngrok domain in
manifest.json,SLACK_REDIRECT_URIin your.env, and re-install the app.
Once the agent is running, there are several ways to interact:
App Home — Open the agent in Slack and click the Home tab. You'll see a welcome message with instructions on how to interact.
Direct Messages — Open a DM with the agent. You'll see suggested prompts like Write a Message, Summarize, and Brainstorm — pick one or type your own message. The agent replies in a thread. Send follow-up messages in the same thread and the agent will maintain the full conversation context.
Channel @mentions — Invite the agent to a channel by typing /invite @agent-name in the message box, then @mention it followed by your message. The agent responds in a thread so the channel stays clean.
Assistant Panel — Click Add Agent in the top-right corner of Slack, select the agent from the list, then pick a suggested prompt or type a message.
# Run ruff check from root directory for linting
ruff check
# Run ruff format from root directory for code formatting
ruff formatmanifest.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.
app.py is the entry point for the application and is the file you'll run to start the server. This project aims to keep this file as thin as possible, primarily using it as a way to route inbound requests.
app_oauth.py is an alternative entry point that runs the app in HTTP mode instead of Socket Mode. This is intended for deployments that use OAuth for app distribution. See the HTTP Mode section under Development for setup instructions.
Every incoming request is routed to a "listener". This directory groups each listener based on the Slack Platform feature used.
/listeners/events — Handles incoming events:
app_home_opened.py— Publishes the App Home view with a welcome message and MCP status.app_mentioned.py— Responds to @mentions in channels.message.py— Responds to direct messages from users.
/listeners/actions — Handles interactive components:
feedback_buttons.py— Handles thumbs up/down feedback on agent responses.
/listeners/views — Builds Block Kit views:
app_home_builder.py— Constructs the App Home Block Kit view.feedback_builder.py— Creates the feedback button block attached to responses.
The agent.py file defines the Pydantic AI Agent with a system prompt, personality, and tool configuration.
The deps.py file defines the AgentDeps dataclass passed to the agent at runtime, providing access to the Slack client and conversation context.
The tools directory contains one example tool (emoji reaction) that the agent can call during a conversation.
The store.py file implements a thread-safe in-memory conversation history store, keyed by channel and thread. This enables multi-turn conversations where the agent remembers previous context within a thread.
If you see an error like:
Failed to connect to MCP server 'streamable_http: https://mcp.slack.com/mcp': HTTP error 400 (Bad Request)
This means the Slack MCP feature has not been enabled for your app. There is no manifest property for this yet, so it must be toggled on manually:
- Run
slack app settingsto open your app's settings page (or visit api.slack.com/apps and select your app) - Navigate to Agents & AI Apps in the left-side navigation
- Toggle Slack Model Context Protocol on