Search Slack and Work with Files

Combine channel history, thread expansion, workspace search, and file download/upload in one focused SlackTools Agent.

slack_tools.py
"""
Search Slack and Work with Files
================================

Combine channel history, thread expansion, workspace search, and file
download/upload in one focused SlackTools Agent.

Prerequisites: SLACK_TOKEN, SLACK_SIGNING_SECRET, OPENAI_API_KEY
Run: .venvs/demo/bin/python cookbook/05_agent_os/17_slack/slack_tools.py
Try in Slack: Share a file, then ask for related discussions and an uploaded summary
Slack scopes: app_mentions:read, assistant:write, chat:write, im:history, channels:read, channels:history, groups:read, groups:history, files:read, files:write, search:read.public, search:read.files, search:read.users
"""

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses
from agno.os import AgentOS
from agno.os.interfaces.slack import Slack
from agno.tools.slack import SlackTools

# ---------------------------------------------------------------------------
# Create Slack Tools AgentOS
# ---------------------------------------------------------------------------

db = SqliteDb(
    id="slack-tools-db",
    db_file="tmp/slack_tools.db",
)

workspace_tools = SlackTools(
    output_directory="tmp/slack_downloads",
    enable_send_message=False,
    enable_send_message_thread=False,
    enable_list_channels=True,
    enable_get_channel_history=True,
    enable_upload_file=True,
    enable_download_file=True,
    enable_search_workspace=True,
    enable_get_thread=True,
    enable_list_users=False,
    enable_get_user_info=False,
    enable_get_channel_info=True,
)

workspace_analyst = Agent(
    id="slack-workspace-analyst",
    name="Slack Workspace Analyst",
    model=OpenAIResponses(id="gpt-5.5"),
    db=db,
    tools=[workspace_tools],
    instructions=[
        "Use Slack as the source of truth for workspace questions.",
        "Use search_workspace for topic searches; its action token comes from the Slack event.",
        "Use get_channel_history for a known channel and get_thread to expand important replies.",
        "Download shared files when analysis needs their contents.",
        "Upload a result file only when the user explicitly asks for one.",
        "Summarize decisions, owners, action items, and unresolved questions.",
    ],
    add_history_to_context=True,
    num_history_runs=5,
    markdown=True,
)

agent_os = AgentOS(
    id="slack-tools-os",
    description="AgentOS serving a Slack-native workspace and file analyst.",
    agents=[workspace_analyst],
    interfaces=[Slack(agent=workspace_analyst)],
)
app = agent_os.get_app()

# ---------------------------------------------------------------------------
# Run Slack Tools AgentOS
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    agent_os.serve(app=app)

Workspace search limitation

Before running this example, change enable_search_workspace=True to enable_search_workspace=False in its SlackTools constructor and remove the instruction to use workspace search.

The current adapter reads event.assistant_thread.action_token; it drops a top-level event.action_token, as used in Slack's current agent example. A request with only the top-level token therefore cannot use search_workspace through this adapter.

These examples also persist tool results, including retrieved workspace data, in SQLite. Slack's Real-time Search data policy prohibits retaining data retrieved by that API. Enabling workspace search requires both compatible event-token handling and a verified storage design for the retrieved data. A single storage flag is not presented here as a complete fix.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Prepare the Slack app

Follow Slack setup to create and install the app, obtain its bot token and signing secret, and configure its current agent experience. Add the bot scopes listed in this example's source docstring and reinstall after changing scopes. Subscribe to app_mention and message.im; configure interactivity for buttons and forms.

Install ngrok and run ngrok http 7777 in another terminal. Keep the tunnel running. After starting this example's server, use the callback paths listed on this page under your public HTTPS URL and complete Slack's verification challenge. Configure each app separately for a multi-app example.

Streaming requires the corresponding Slack app capability. The current Agno adapter initializes suggested prompts on the legacy assistant_thread_started event; the setup guide explains the new-app limitation. Keep only one standalone example on port 7777 at a time.

Install dependencies

uv pip install -U "agno[os,slack]" openai

Export environment variables

export OPENAI_API_KEY="your_openai_api_key_here"
export SLACK_SIGNING_SECRET="your_slack_signing_secret_here"
export SLACK_TOKEN="your_slack_token_here"

Run the example

Save the code above as slack_tools.py, then run:

python slack_tools.py

Connect Slack to the running server

Keep Python and ngrok running. In each app's Slack settings, prepend your public HTTPS origin to these paths:

AppEvent subscriptionsInteractivity
Slack app/slack/events/slack/interactions

Complete URL verification, then send a DM or invite the app to a channel and @mention it. Ordinary channel replies require an @mention with the default configuration.

Full source: cookbook/05_agent_os/17_slack/slack_tools.py