Slack工具包#
- class langchain_community.agent_toolkits.slack.toolkit.SlackToolkit[source]#
基础类:
BaseToolkit
用于与Slack交互的工具包。
- Parameters:
client – Slack客户端。
- Setup:
安装
slack_sdk
并设置环境变量SLACK_USER_TOKEN
。pip install -U slack_sdk export SLACK_USER_TOKEN="your-user-token"
- Key init args:
- client: slack_sdk.WebClient
Slack 客户端。
- Instantiate:
from langchain_community.agent_toolkits import SlackToolkit toolkit = SlackToolkit()
- Tools:
tools = toolkit.get_tools() tools
[SlackGetChannel(client=<slack_sdk.web.client.WebClient object at 0x113caa8c0>), SlackGetMessage(client=<slack_sdk.web.client.WebClient object at 0x113caa4d0>), SlackScheduleMessage(client=<slack_sdk.web.client.WebClient object at 0x113caa440>), SlackSendMessage(client=<slack_sdk.web.client.WebClient object at 0x113caa410>)]
- Use within an agent:
from langchain_openai import ChatOpenAI from langgraph.prebuilt import create_react_agent llm = ChatOpenAI(model="gpt-4o-mini") agent_executor = create_react_agent(llm, tools) example_query = "When was the #general channel created?" events = agent_executor.stream( {"messages": [("user", example_query)]}, stream_mode="values", ) for event in events: message = event["messages"][-1] if message.type != "tool": # mask sensitive information event["messages"][-1].pretty_print()
================================[1m Human Message [0m================================= When was the #general channel created? ==================================[1m Ai Message [0m================================== Tool Calls: get_channelid_name_dict (call_NXDkALjoOx97uF1v0CoZTqtJ) Call ID: call_NXDkALjoOx97uF1v0CoZTqtJ Args: ==================================[1m Ai Message [0m================================== The #general channel was created on timestamp 1671043305.
通过解析和验证来自关键字参数的输入数据来创建一个新模型。
如果输入数据无法验证以形成有效模型,则引发 [ValidationError][pydantic_core.ValidationError]。
self 被显式地设为仅位置参数,以允许 self 作为字段名称。
- param client: WebClient [Optional]#
使用 SlackToolkit 的示例