# Agents are available in the autogen.agents namespace
from autogen import ConversableAgent, LLMConfig
from autogen.agents.experimental import DiscordAgent
# For running the code in Jupyter, use nest_asyncio to allow nested event loops
#import nest_asyncio
#nest_asyncio.apply()
# LLM configuration for our agent to select the tools and craft the message
# Put your key in the OPENAI_API_KEY environment variable
llm_config = LLMConfig(api_type="openai", model="gpt-4o-mini")
# Tokens and Ids (CHANGE THESE)
my_discord_bot_token = "ABC..."
my_discord_guild_name = "My Discord Server Name"
my_discord_channel_name = "general"
with llm_config:
# Create DiscordAgent with defaults
discord_agent = DiscordAgent(
name="discord_agent",
bot_token=my_discord_bot_token,
guild_name=my_discord_guild_name,
channel_name=my_discord_channel_name,
)
# Tool execution is carried out by another agent
# Will output TERMINATE to end the conversation when complete
tool_executor = ConversableAgent(
name="tool_executor",
system_message=(
"You execute send and retrieve functions for Discord platforms.\n"
"Respond with 'TERMINATE' when finished."
),
human_input_mode="NEVER",
)
# Register the tools from the DiscordAgent with the tool_executor for execution
for tool in discord_agent.tools:
tool.register_for_execution(tool_executor)
# Let's get the latest message from Discord and send one back as a poem.
tool_executor.initiate_chat(
recipient=discord_agent,
message="Get the latest message from Discord and send back a message with a poem about it."
)