Create a file slack_agent.py with the following code:

slack_agent.py
from phi.agent import Agent
from phi.tools.slack import SlackTools
from phi.model.openai import OpenAIChat

agent = Agent(model=OpenAIChat(id="gpt-4o"), tools=[SlackTools()], show_tool_calls=True)

agent.print_response("Send a warm message to the #general channel", markdown=True)

Usage

1

Create a virtual environment

Open the Terminal and create a python virtual environment.

2

Install libraries

pip install openai slack-sdk phidata
3

Set environment variables

export SLACK_TOKEN=****
4

Run the agent

python slack-agent.py