Skip to content

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:write scope 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.json file 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:

def send_message_to_slack_channel(channel_name: str, message: str):
  • 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_name using slack_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.json file.
  • Use clear channel names to prevent misrouting messages.
  • Combine with logic nodes to conditionally trigger Slack notifications.
  • Use allow_parallel_tool_calls=False if you need sequential Slack updates.