Configuration

To connect slack, you can:

  1. Head to the HumanLayer dashboard
  2. Navigate to “Integrations”
  3. Click “Add to Slack”
  4. Follow the Slack Approval Workflow
  5. Congrats - your HumanLayer agents will now contact you in Slack for approvals

Customizing Channels

By default,

The Slack contact channel allows agents to send messages and collect responses through Slack channels or direct messages. Configure a Slack channel using the SlackContactChannel model:

from humanlayer import ContactChannel, SlackContactChannel

dm_with_ceo = ContactChannel(
    slack=SlackContactChannel(
        channel_or_user_id="U123456",  # Must be an ID like C123456 or U123456, not #channel or @user
        context_about_channel_or_user="a DM with the CEO",  # Optional context for the LLM
        experimental_slack_blocks=True,  # Optional - enables rich message formatting
    )
)

hl = HumanLayer(contact_channel=dm_with_ceo)

You can also override the contact channel at the per-request level:

hl = HumanLayer()

@hl.require_approva(contact_channel=dm_with_ceo)
def send_email():
    ...

Or in one or more human-as tool instances

tools = [
  hl.human_as_tool(contact_channel=channel_with_sre_team),
  hl.human_as_tool(contact_channel=dm_with_ceo),
]

Channel/User ID

The channel_or_user_id must be a Slack ID:

  • Channel IDs start with C (e.g. C123456)
  • User IDs start with U (e.g. U123456)
  • Do not use channel names (#general) or usernames (@user)

You can get a channel ID in slack by right-clicking the channel, going to “Channel Details”, and copying the ID at the bottom of the modal.

Context

The optional context_about_channel_or_user field helps the LLM understand who it’s talking to:

# Good context examples
"a DM with the CEO"
"the channel with the SRE team"
"a private channel for approvals"

Usage

Use the Slack channel with either core feature:

# With require_approval
@hl.require_approval(contact_channel=dm_with_ceo)
def send_email(to: str, subject: str, body: str) -> str:
    """Send an email to a customer"""
    return f"Email sent to {to}"

# With human_as_tool
tools = [
    langchain_tools.StructuredTool.from_function(
        hl.human_as_tool(
            contact_channel=dm_with_ceo,
        )
    ),
]

Next Steps