# Agents are available in the autogen.agents namespace
from autogen import ConversableAgent, register_function, LLMConfig
from autogen.agents.experimental import SlackAgent
# 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 Slack credentials
_bot_token = "xoxo..." # OAuth token
_channel_id = "C1234567" # ID of the Slack channel
# Our tool executor agent, which will run the tools once recommended by the slack_agent, no LLM required
executor_agent = ConversableAgent(
name="executor_agent",
human_input_mode="NEVER",
)
with llm_config:
slack_agent = SlackAgent(
name="slack_agent",
bot_token=_bot_token,
channel_id=_channel_id,
)
# We get the registered tools and register them for execution with the tool executor
for tool in slack_agent.tools:
tool.register_for_execution(executor_agent)
# Weather function
def get_weather():
return "The weather today is 25 degrees Celsius and sunny, with a late storm."
# Register for LLM recommendation with our slack_agent and for execution with our executor_agent
register_function(
get_weather,
caller=slack_agent,
executor=executor_agent,
description="Get the current weather forecast",
)
# Ask the SlackAgent to get the weather (using the get_weather tool) and then send a message out (using its SlackSendTool tool)
executor_agent.initiate_chat(
recipient=slack_agent,
message="Get the latest weather forecast and send it to our Slack channel. Use some emojis to make it fun!",
max_turns=3,
)