前提条件

以下示例需要 slack-sdk 库。

pip install openai slack-sdk

在此处获取 Slack 令牌:https://api.slack.com/tutorials/tracks/getting-a-token

export SLACK_TOKEN=***

示例

以下代理将使用 Slack 向频道发送消息、列出所有频道以及获取特定频道的消息历史记录。

cookbook/tools/slack_tools.py
import os

from agno.agent import Agent
from agno.tools.slack import SlackTools

slack_tools = SlackTools()

agent = Agent(tools=[slack_tools], show_tool_calls=True)

# 示例 1:向 Slack 频道发送消息
agent.print_response("Send a message 'Hello from Agno!' to the channel #general", markdown=True)

# 示例 2:列出 Slack 工作区中的所有频道
agent.print_response("List all channels in our Slack workspace", markdown=True)

# 示例 3:通过频道 ID 获取特定频道的消息历史记录
agent.print_response("Get the last 10 messages from the channel 1231241", markdown=True)

Toolkit 参数

参数类型默认描述
tokenstr-用于身份验证的 Slack API 令牌
send_messageboolTrue启用向 Slack 频道发送消息的功能
list_channelsboolTrue启用列出可用 Slack 频道的功能
get_channel_historyboolTrue启用从频道检索消息历史记录的功能

Toolkit 函数

函数描述
send_message向指定的 Slack 频道发送消息
list_channels列出 Slack 工作区中所有可用频道
get_channel_history从指定频道检索消息历史记录

开发者资源