Back to Agno

Slack Cookbook

cookbook/05_agent_os/interfaces/slack/README.md

2.6.67.6 KB
Original Source

Slack Cookbook

Examples for connecting Agno agents, teams, and workflows to Slack using the Slack interface in AgentOS. Supports both standard request/response and real-time streaming via Slack's chat_stream API.

Requirements: slack_sdk >= 3.40.0 (streaming with plan-mode task cards). Install or upgrade with pip install "slack_sdk>=3.40.0".

Slack App Setup

Follow these steps to create and configure a Slack app for use with Agno.

1. Create the App

  1. Go to https://api.slack.com/apps and click Create New App.
  2. Choose From scratch, give it a name, and select your workspace.
  3. On the Basic Information page, copy the Signing Secret — you'll need it later.

2. Enable Agents & AI Apps (required for streaming)

  1. In the sidebar, click Agents & AI Apps.
  2. Toggle Agent or Assistant to On.
  3. Under Suggested Prompts, select Dynamic (lets the server set prompts via API).
  4. Click Save.

Enabling this automatically adds the assistant:write scope.

3. Add OAuth Scopes

  1. In the sidebar, click OAuth & Permissions.
  2. Scroll to Scopes > Bot Token Scopes and add:
ScopePurpose
app_mentions:readReceive @mention events
assistant:writeStreaming (startStream/appendStream/stopStream)
chat:writeSend messages and stream responses
im:historyRead DM history for thread context
channels:historyRead public channel history
groups:historyRead private channel history
files:readDownload files users send to the bot
files:writeUpload response files (images, docs)
users:readLook up user info (for channel_summarizer, etc.)
search:readSearch workspace messages (research_assistant, support_team, etc.)

Not all scopes are needed for every example — app_mentions:read, assistant:write, chat:write, and im:history are the minimum for streaming. Each cookbook's docstring lists the exact scopes it requires.

  1. Scroll up and click Install to Workspace (or Reinstall if updating scopes).
  2. Copy the Bot User OAuth Token (xoxb-...).

4. Subscribe to Events

  1. In the sidebar, click Event Subscriptions.
  2. Toggle Enable Events to On.
  3. Set Request URL to your tunnel URL + /slack/events:
    https://<your-tunnel>/slack/events
    
    Slack will send a challenge request — the server must be running to verify.
  4. Under Subscribe to bot events, add:
EventPurpose
app_mentionRespond to @mentions in channels
message.imRespond to direct messages
message.channelsRespond to messages in public channels
message.groupsRespond to messages in private channels
assistant_thread_startedSet suggested prompts when a thread opens
assistant_thread_context_changedUpdate context when thread is moved
  1. Click Save Changes.
  2. Go to Install App and click Reinstall to Workspace to apply the new events.

5. Enable Interactivity (required for HITL)

If you're using Human-in-the-Loop (HITL) features like hitl_confirmation.py, hitl_user_input.py, or hitl_incident_commander.py, you must enable Interactivity:

  1. In the sidebar, click Interactivity & Shortcuts.
  2. Toggle Interactivity to On.
  3. Set Request URL to your tunnel URL + /slack/interactions:
    https://<your-tunnel>/slack/interactions
    
  4. Click Save Changes.

Without this, button clicks (Approve/Deny) and form submissions won't work. The server must be running for Slack to verify the URL.

6. Set Environment Variables

bash
export SLACK_TOKEN="xoxb-..."               # Bot User OAuth Token from step 3
export SLACK_SIGNING_SECRET="..."           # Signing Secret from step 1
export OPENAI_API_KEY="sk-..."              # Or whichever model provider you use

7. Start a Tunnel

Slack needs a public URL to deliver events. Use ngrok or cloudflared:

bash
ngrok http 7777
# or: cloudflared tunnel --url http://localhost:7777

Copy the public HTTPS URL and paste it into:

  • Event Subscriptions Request URL (step 4.3)
  • Interactivity Request URL (step 5.3) — if using HITL features

The free ngrok tier gives you a random subdomain that changes on restart — update both Request URLs each time.

8. Run an Example

bash
.venvs/demo/bin/python cookbook/05_agent_os/interfaces/slack/basic.py

DM the bot or @mention it in a channel to test.

Examples

Getting Started

  • basic.py — Minimal agent that responds to @mentions with session history.
  • basic_workflow.py — Two-step research-then-write workflow.

Streaming

Streaming is enabled by default. Tokens arrive in real-time and tool calls render as progress cards in Slack's plan display.

  • streaming_deep_research.py — Deep research agent with 7 toolkits.
  • reasoning_agent.py — Agent with step-by-step reasoning display.

Human-in-the-Loop (HITL)

These examples pause execution for human approval or input. Requires Interactivity to be enabled (step 5).

  • hitl_simple.py — Basic confirmation flow (Approve/Deny).
  • hitl_confirmation.py — Confirmation with detailed tool arguments display.
  • hitl_user_input.py — User provides priority and component via Slack form.
  • hitl_user_feedback.py — Multi-choice feedback questions.
  • hitl_external_execution.py — Human runs a command and pastes output.
  • hitl_incident_commander.py — Full incident response flow with all HITL types.

Teams and Workflows

  • support_team.py — Support team routing to Technical Support or Documentation Specialist.
  • multimodal_team.py — Team with GPT-4o vision input and DALL-E image output.
  • multimodal_workflow.py — Parallel visual analysis + web research, then creative synthesis.

Tools and Features

  • agent_with_user_memory.py — Agent with MemoryManager that learns about users.
  • channel_summarizer.py — Agent that reads channel history and summarizes threads.
  • file_analyst.py — Agent that downloads, analyzes, and uploads files.
  • research_assistant.py — Agent combining Slack search with web search.
  • multi_bot.py — Multiple bots with different models in one server.
  • multiple_instances.py — Two bots on one server with separate credentials.

Troubleshooting

SymptomCauseFix
Bot doesn't respondEvent URL not set or server not runningCheck Event Subscriptions shows "Verified"
internal_error on chat.appendStream"Agents & AI Apps" not enabled, or missing assistant:write scope, or app not reinstalled after config changes1. Enable "Agents & AI Apps" (step 2). 2. Add assistant:write scope (step 3). 3. Reinstall the app to the workspace.
Blank streaming bubbleWrong recipient_user_idEnsure you're using the human user's ID, not the bot's
No plan-mode task cardsslack_sdk older than 3.40.0Run pip install "slack_sdk>=3.40.0"
No suggested promptsassistant_thread_started event missingAdd it in Event Subscriptions (step 4)
Bot only responds to DMs, not channelsMissing message.channels eventAdd channel events in Event Subscriptions
HITL buttons don't workInteractivity not enabledEnable Interactivity and set Request URL (step 5)
SLACK_SIGNING_SECRET is not setMissing env varExport SLACK_SIGNING_SECRET before running
403 on event webhookInvalid signing secretCheck the secret matches Basic Information page
URL verification failsServer not running or wrong signing secretStart the server (step 7) before setting the Request URL