Slack
SlackTools enable an Agent to interact with the Slack API. 12 methods cover messaging, channels, file management, search, threads, and user lookup.
Prerequisites
1uv pip install -U "kern-ai[slack]"1export SLACK_TOKEN=***Example
The following agent sends a message to a Slack channel, lists channels, and retrieves message history.
1import os23from kern.agent import Agent4from kern.tools.slack import SlackTools56slack_tools = SlackTools()78agent = Agent(tools=[slack_tools])910# Example 1: Send a message to a Slack channel11agent.print_response("Send a message 'Hello from Kern!' to the channel #general", markdown=True)1213# Example 2: List all channels in the Slack workspace14agent.print_response("List all channels in our Slack workspace", markdown=True)1516# Example 3: Get the message history of a specific channel by channel ID17agent.print_response("Get the last 10 messages from the channel 1231241", markdown=True)Toolkit Params
| Parameter | Type | Default | Description |
|---|---|---|---|
token | Optional[str] | None | Slack API token. Falls back to SLACK_TOKEN env var. |
markdown | bool | True | Enable Slack mrkdwn formatting in messages. |
output_directory | Optional[str] | None | Directory to save downloaded/uploaded files locally. |
enable_send_message | bool | True | Enable send_message tool. |
enable_send_message_thread | bool | True | Enable send_message_thread tool. |
enable_list_channels | bool | True | Enable list_channels tool. |
enable_get_channel_history | bool | True | Enable get_channel_history tool. |
enable_upload_file | bool | True | Enable upload_file tool. |
enable_download_file | bool | True | Enable download_file tool. |
enable_search_messages | bool | False | Enable search_messages tool. Requires a user token and the search:read OAuth scope. |
enable_search_workspace | bool | False | Enable search_workspace tool. Uses Slack's assistant.search.context API. Requires search:read.public, search:read.files, and search:read.users bot scopes. Only works through the Slack interface (needs action_token). |
enable_get_thread | bool | False | Enable get_thread tool. |
enable_list_users | bool | False | Enable list_users tool. |
enable_get_user_info | bool | False | Enable get_user_info tool. |
enable_get_channel_info | bool | False | Enable get_channel_info tool. |
all | bool | False | Enable all tools. Overrides individual flags. |
ssl | Optional[SSLContext] | None | SSL context for the Slack WebClient. |
max_file_size | int | 1073741824 | Maximum file size in bytes for uploads and downloads (default 1 GB). |
thread_message_limit | int | 20 | Maximum number of messages to fetch in get_thread. |
Toolkit Functions
| Function | Description |
|---|---|
send_message(channel, text) | Send a message to a Slack channel. |
send_message_thread(channel, text, thread_ts) | Reply to a message thread in a channel. |
list_channels() | List all channels in the workspace. |
get_channel_history(channel, limit=100) | Get message history from a channel. |
upload_file(channel, content, filename, title?, initial_comment?, thread_ts?) | Upload a file to a channel with optional caption. |
download_file(file_id, dest_path?) | Download a file by file ID. Returns path or base64 content. |
search_messages(query, limit=20) | Search messages across the workspace. Requires a user token (bot tokens return not_allowed_token_type). |
search_workspace(query, content_types?, channel_types?, limit=10, include_context_messages=True) | Search messages, files, channels, and users across the workspace using Slack's Real-Time Search API. Only works through the Slack interface. |
get_thread(channel, thread_ts, limit=20) | Get all messages in a thread by parent timestamp. Capped by thread_message_limit. |
list_users(limit=100) | List all users in the workspace. |
get_user_info(user_id) | Get detailed info about a user by user ID. |
get_channel_info(channel) | Get channel metadata: name, topic, purpose, member count, and visibility. |
Tip
search_messages supports Slack search modifiers: from:@user, in:#channel, has:link, before:2024-01-01, after:2024-01-01. Combine them to narrow results.