Slack Function Tool
π Key Concepts
The Slack Function Tool allows function-calling agents to send custom messages to Slack channels dynamically during a workflow. It is designed for actionable automation, enabling your agents to respond to insights, conditions, or triggers by immediately communicating updates or alerts through Slack.
This tool is ideal when workflows need to output results, alert team members, or report summaries to relevant stakeholders in real time.
π Key Definitions
| Term | Description |
|---|---|
| Slack Token | An API token with chat:write scope used to send messages to Slack. |
| FunctionCallingAgent | A LlamaIndex agent that chooses from available callable Python functions and invokes them automatically based on query intent. |
| FunctionTool | A wrapper that allows you to expose Python functions as callable tools for an agent. |
| Slack Function | The callable Python function that posts a message to the selected Slack channel using slack_sdk. |
βοΈ Setup Guide: Using the Slack Function Tool
1. Slack Bot Token
- Go to https://api.slack.com/apps
- Create a new app or select an existing one
- Ensure the app has
chat:writescope under OAuth & Permissions - Install the app to your workspace and copy the Bot Token (e.g.,
xoxb-...)
β This token must be saved in your
data.jsonfile under the key:"slack_token"
2. Add Function Configuration
| Field | Purpose | Example |
|---|---|---|
name |
Internal label for the tool (used in UI) | "Slack Notifier" |
slack_token |
Bot token with write permissions | "xoxb-1234567890-abcdef" |
No additional fields are needed; the channel and message will be passed as arguments to the function.
π How It Works
The following function is registered as a tool:
- Your agent receives a prompt or query.
- It selects this tool if it determines the response requires a Slack notification.
- The tool dynamically sends the message to the selected
channel_nameusingslack_sdk.WebClient.
π§ͺ Example Use Cases
-
π’ Training Completed Alerts βNotify #ml-pipeline when model training is done.β
-
π¨ Threshold Exceeded Warnings βSend a warning to #ops if memory usage exceeds 85%.β
-
π¬ Pipeline Step Logging βPost to #data-team that the preprocessing step started.β
β Best Practices
- Secure your token by storing it in the centralized
data.jsonfile. - Use clear channel names to prevent misrouting messages.
- Combine with logic nodes to conditionally trigger Slack notifications.
- Use
allow_parallel_tool_calls=Falseif you need sequential Slack updates.