# Tools are available in the autogen.tools namespace
from autogen import ConversableAgent, LLMConfig
from autogen.tools.experimental import DiscordRetrieveTool, DiscordSendTool
# For running the code in Jupyter, use nest_asyncio to allow nested event loops
#import nest_asyncio
#nest_asyncio.apply()
llm_config = LLMConfig(model="gpt-4o-mini", api_type="openai")
# Our tool executor agent, which will run the tools once recommended by the discord_agent, no LLM required
executor_agent = ConversableAgent(
name="executor_agent",
human_input_mode="NEVER",
)
# Our discord agent, who will construct messages and recommend the tool calls
with llm_config:
discord_agent = ConversableAgent(name="discord_agent")
_bot_token = "MTMyOTI..." # Discord bot token
_guild_name = "My Test Server" # Name of the server
_channel_name = "general" # Name of the channel, this is equivalent to "# general"
# Create our send tool
discord_send_tool = DiscordSendTool(bot_token=_bot_token, guild_name=_guild_name, channel_name=_channel_name)
# Register it for recommendation by our Discord agent
discord_send_tool.register_for_llm(discord_agent)
# Register it for execution by our executor agent
discord_send_tool.register_for_execution(executor_agent)
# And the same for our our retrieve tool
discord_retrieve_tool = DiscordRetrieveTool(bot_token=_bot_token, guild_name=_guild_name, channel_name=_channel_name)
discord_retrieve_tool.register_for_llm(discord_agent)
discord_retrieve_tool.register_for_execution(executor_agent)
# Let’s send a message to Discord, all about the wonders of Australia.
# We’ll limit it to 2 turns, allowing the Discord agent to receive the request,
# construct and recommend the send tool, and then the executor agent to execute the tool,
# sending the message to Discord.
executor_agent.initiate_chat(
recipient=discord_agent,
message="Let's send a message to Discord giving them a paragraph on the highlights of Australia.",
max_turns=2,
)