SlackSendTool
and SlackRetrieveTool
are easy to add.
If you haven’t had a chance to read about how AG2’s Communication Platform agents and tools work, read the overview first.
Installation
Install AG2 with the LLM model provider and Slack platform extra.Capabilities
SlackSendTool
can:
- Construct and send a message to the configured channel. If a message is longer than the platforms permitted message length, they will split the message into multiple messages.
SlackRetrieveTool
can:
- Retrieve the latest X messages from a channel.
- Retrieve messages since a given date.
- Retrieve messages since a given message ID.
- Retrieve a message given its ID.
Consider
SlackAgent
if you don’t want to build your agent with these tools, it is a ready-to-go AG2 agent that already incorporates the tools and messaging instructions.Platform configuration
Each tool is configured for a specific channel. This configuration is applied when you create the tool. The tools require authentication (OAuth token) and channel details in order to send/retrieve messages. Here are the steps to get a token:- Create an app, from scratch, at https://api.slack.com/apps
- In your app settings, go to Features > OAuth & Permissions:
- Under “Bot Token Scopes”, add these permissions:
- chat:write (to send messages)
- channels:history
- channels:read (to access channel info)
- groups:read (for private channels)
- im:read (for direct messages)
- users:read (to get user info)
- files:read (to access file attachments)
- groups:history
- im:history
- mpim:history
- Under “Bot Token Scopes”, add these permissions:
- With your app setup, now install it in your workspace, using the “Install App” menu, to create an OAuth Token.
- Open Slack in a browser
- Navigate to your channel
- Get the channel ID from the URL (e.g., …/C12345678)
- In Slack, go to your channel
- Type
/invite @YourBotName
, e.g./invite @ag2commsagent
Code example
Here’s a simple example using the Slack tools with aConversableAgent
-based agent to send a weather forecast to a Slack channel.
