SlackAgent
can help you.
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
SlackAgent
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.
- 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.
- 40,000 character limit
- Markdown
- bold/italic/code
- emojis
- notification formats
has_writing_instructions
to False
when creating the agent.
In-built Tools
TheSlackAgent
has two in-built tools that it will call upon as it needs:
Find out more about these tools and how you can add them to your own AG2 agents in the Slack Tools documentation.
Platform configuration
Each agent is configured for a specific channel. This configuration is applied when you create the agent. TheSlackAgent
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 theSlackAgent
that gets the current weather and sends a message to a Slack channel to give them a weather forecast.
