Get Communicating with Discord, Slack, and Telegram


Welcome DiscordAgent, SlackAgent, and TelegramAgent
We want to help you focus on building workflows and enhancing agents, so we’re building reference agents to get you going quicker.
Say hello to three new AG2 communication agents - DiscordAgent
, SlackAgent
, and TelegramAgent
, here so that you can use an agentic application to send and retrieve messages from messaging platforms.
New agents need new tools
Underpinning these new agents are AG2 tools for sending and retrieving messages.
Why is it important that these are tools? Simple, you can add the tools to your existing agents or build a mega communications agent with all the tools.
Additionally, as the agents are tool-based, you can add your tools to these agents to make them even more capable.
Here are our three new agents and the pair of new tools that they use (and you can use with your own agents):
Agent | Send Tool | Retrieve Tool |
---|---|---|
DiscordAgent | DiscordSendTool | DiscordRetrieveTool |
SlackAgent | SlackSendTool | SlackRetrieveTool |
TelegramAgent | TelegramSendTool | TelegramRetrieveTool |
Capabilities
The send tools all have the same functionality, they take a message and post it to the configured channel/group/bot. If a message is longer than the platforms permitted message length, the tool will split the message into multiple messages.
All the retrieve tools can:
- Retrieve the latest X messages from a channel/group/bot.
- Retrieve messages since a given date.
- Retrieve messages since a given message ID.
- Retrieve a message given its ID.
The Telegram retrieve tool also has the ability to retrieve messages using a search string (and this can be done in combination with the retrieval options above).
Configuration
In this first iteration of the tools, each tool is configured for a specific channel/group/bot. This configuration is applied when you create the tool.
Discord, Slack, and Telegram all have their own authentication and channel/group/bot identifiers. See this Notebook for more guidance on establishing those authentication details and identifiers.
Here are examples of how to create the tools, passing in the configuration:
Or, the agents:
If you need to send to or retrieve messages from multiple channels, create additional tool instances for each channel and load up your agents or have an agent for each channel.
Agent vs Tools
You could create a ConversableAgent and add the send and retrieve tools and you would almost have the same functionality as the new agents.
Apart from the simplicity of creating an agent with the tools already registered, an important component of the new agents is that the platform’s messaging requirements will be appended to their system message.
They cover aspects like maximum message length, preferred format (e.g. Markdown), and provide tips like using emojis.
Agent | System Message guidance |
---|---|
DiscordAgent | 2,000 character limit, Markdown, bold/italic/code, use emojis |
SlackAgent | 40,000 character limit, Markdown, bold/italic/code, emojis, notification formats |
TelegramAgent | 4,096 character limit, HTML, mentions and emojis |
These are enabled by default, but you can turn these off by setting has_writing_instructions
to False
when creating the agent.
Another important consideration is the execution of these tools. In AG2 the tool execution is typically handled by a separate agent that will follow the agent in the conversation (unless its an agent in a swarm whereby tools are executed automatically). So, you will need to register the tools with another agent for execution. See the demo below for how to do this.
Installation
Each messaging platform requires installation of a package specifically for that platform.
To use the Discord agent or tools install AG2 with the commsagent-discord
extra:
Slack:
Telegram:
You’re all set! Now you can start sending to and retrieving messages from these platforms.
Demo
Here’s a quick example of how to use the new agents and tools. If you’re after more examples, see this Notebook.
In this demo we have a Slack channel where AG2 bugs are noted. Those bugs need to go to a Discord channel for them to be raised as a ticket and also to Telegram to inform the community about it. Finally, we should send a message back to Slack to say that we’ve actioned the steps.
We’ll start with creating an equivalent DiscordAgent
using the tools so you now how to construct your own communication agent. For Slack and Telegram, we’ll use SlackAgent
and TelegramAgent
.
All your tokens and identifiers, next.
Creating an equivalent DiscordAgent
using tools.
Our Slack and Telegram agents.
To execute the tools, we create a tool executor and associate the tools to allow it to execute them.
Here’s our GroupChat and GroupChatManager to manage the agents.
Let’s go!
Here’s the message we had in Slack that it retrieved:
AG2 workflow:
Discord message posted (based on Markdown as per instructions):
Telegram message posted (based on HTML):
Finally, our return message to Slack (based on Markdown):
Feedback
These tools are currently in our experimental
namespace, indicating that we have tested the functionality but their interface may change.
We’d love for you to try them but please use them with that in mind. Let us know how you go with them!
What’s next?
We’re continuing to build new agents, creating more tools, and enhancing agent capabilities.
There are many messaging platforms and we’re starting with Discord, Slack, and Telegram. If you want your AG2 agents to communicate with more messaging platforms we’d love to help you build new agents, see our Contributor Guide and chat with the team and collaborators on Discord.