Skip to main content
Agno and AgentOS make it easy to deploy your agents on Slack with just 2 extra lines of code. This example creates a simple agent for answering questions:
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.os import AgentOS
from agno.os.interfaces.slack import Slack

basic_agent = Agent(
    name="Basic Agent",
    model=OpenAIChat(id="gpt-5.2"), # Ensure OPENAI_API_KEY is set
    add_history_to_context=True,
    num_history_runs=3,
    add_datetime_to_context=True,
)

agent_os = AgentOS(
    agents=[basic_agent],
    interfaces=[Slack(agent=basic_agent)],
)
app = agent_os.get_app()

if __name__ == "__main__":
    agent_os.serve(app="slack_bot:app", port=7777, reload=True)
Install the Slack SDK: pip install slack-sdk
Thread timestamps are automatically used as session IDs, so each Slack thread maintains its own conversation context.

Setup and Configuration

1

Prerequisites

Ensure you have the following:
  • A Slack workspace with admin privileges
  • ngrok (for development)
  • Python 3.7+
2

Create a Slack App

  1. Go to Slack App Directory
  2. Click “Create New App”
  3. Select “From scratch”
  4. Provide:
    • App name
    • Workspace to install to
  5. Click “Create App”
3

Configure OAuth & Permissions

  1. Navigate to “OAuth & Permissions” in your Slack App settings
  2. Under “Scopes”, click “Add an OAuth Scope”
  3. Add the following Bot Token Scopes:
    • app_mention
    • chat:write
    • chat:write.customize
    • chat:write.public
    • im:history
    • im:read
    • im:write
  4. Scroll to the top and click “Install to Workspace”
  5. Click “Allow” to authorize the app
4

Setup Environment Variables

Create a .env file in your project root with the following content, replacing placeholder values with your actual credentials:
SLACK_TOKEN="xoxb-your-bot-user-token"  # Bot User OAuth Token
SLACK_SIGNING_SECRET="your-signing-secret"  # App Signing Secret
Find these values in your Slack App settings:
  • Bot User OAuth Token: Under “OAuth & Permissions”
  • Signing Secret: Under “Basic Information” > “App Credentials”
5

Setup Webhook with ngrok

  1. Run ngrok to expose your local server, ensuring the port matches your app (7777):
    ngrok http 7777
    # Or, if you have a paid ngrok plan with a static domain:
    # ngrok http --domain=your-custom-domain.ngrok-free.app 7777
    
  2. Copy the https:// URL provided by ngrok
  3. In your Slack App settings, go to “Event Subscriptions”
  4. Enable events by toggling the switch
  5. Add your Request URL:
    • Format: https://your-ngrok-url.ngrok.io/slack/events
  6. Wait for Slack to verify the endpoint (your app must be running)
6

Configure Event Subscriptions

  1. Under “Subscribe to bot events” in Event Subscriptions:
  2. Click “Add Bot User Event” and add:
    • app_mention
    • message.im
    • message.channels
    • message.groups
  3. Click “Save Changes”
  4. Reinstall your app to apply the new permissions
7

Enable App Home

  1. Go to “App Home” in your Slack App settings
  2. Under “Show Tabs”:
    • Enable “Messages Tab”
    • Check “Allow users to send Slash commands and messages from the messages tab”
  3. Save changes
8

Final Installation

  1. Go back to “Install App” in your Slack App settings
  2. Click “Reinstall to Workspace”
  3. Authorize the app with the new permissions
  4. Your app is now ready to use!
ngrok is used only for local development and testing. For production deployments, see the deployment tutorials.

Developer Resources