Skip to content

Conversation

@apexlnc
Copy link
Contributor

@apexlnc apexlnc commented Oct 13, 2025

Summary

Production-ready Slack bot integration for the Kagent multi-agent platform. Provides a unified Slack interface to interact with multiple AI agents through DMs and channel mentions.

Features

Core Functionality

  • Socket Mode Integration: WebSocket-based connection (no public endpoint required)
  • Dynamic Agent Discovery: Automatically discovers agents from /api/agents with 5-minute caching
  • Intelligent Routing: Keyword-based matching routes messages to appropriate agents
  • Thread Context Isolation: Each thread maintains independent conversation context
  • Session Management: Full conversation history maintained across multiple turns

User Experience

  • Streaming Responses: Real-time updates with progressive message rendering (2s intervals)
  • Human-in-the-Loop Approval: Smart detection of approval requests with ✅/❌ buttons
  • Rich Formatting: Slack Block Kit responses with agent metadata
  • Slash Commands: /agents to list, /agent-switch to manually select agents

Security & RBAC

  • Slack User Group Integration: Check group membership with 5-minute caching
  • Agent-Level Permissions: Configurable YAML-based access control
  • Email Allowlists: Support for individual user permissions
  • Configurable Deny Messages: Custom access denial messages per agent

Architecture

  • handlers/: Slack event handlers (mentions, commands, actions, middleware)
  • services/: Business logic (A2A client, agent discovery, routing)
  • auth/: RBAC with Slack group membership checking
  • slack/: Message formatting and validation utilities

Testing

Tested locally with kagent deployment using Socket Mode in DM-only configuration.

@apexlnc
Copy link
Contributor Author

apexlnc commented Oct 13, 2025

cc @peterj @EItanya @yuval-k @ilackarms can I get a review on this?

FWIW, i've fully tested this on a Slack enterprise-grid account and this is loosely based off existing patterns I'm currently using for other use cases.

The HITL portion is very "basic" atm with regex matching, but is a good starter for using Slack as an approval gate down the road -- using fancier conditions.

There are a few minor things that I'd like to wire up, but wanted to make sure this is line with the direction the project is heading towards.

@apexlnc apexlnc force-pushed the feat/slack-bot-integration branch 5 times, most recently from 8789d2e to fd2d66f Compare October 14, 2025 03:06
@apexlnc
Copy link
Contributor Author

apexlnc commented Oct 16, 2025

@EItanya can I get a review on this? Not sure which maintainer I should be tagging

@apexlnc apexlnc force-pushed the feat/slack-bot-integration branch from fd2d66f to aafe032 Compare October 17, 2025 02:56
@apexlnc apexlnc force-pushed the feat/slack-bot-integration branch 4 times, most recently from adab011 to f67f765 Compare October 18, 2025 21:24
@echo " make test - Run tests (if available)"
@echo " make lint - Run linting with ruff"
@echo " make type-check - Run type checking with mypy"
@echo " make build - Build Docker image"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make build doesn't work for me:

Screenshot 2025-10-20 at 1 57 36 PM

Should there be a default config folder with some default permissions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, defer to the wider audience on sensible defaults.

@peterj
Copy link
Collaborator

peterj commented Oct 20, 2025

This is a great feature - I got it to work; however, I think this Slack bot should probably be in a separate repo, instead of having it in the main repository. @EItanya what do you think?

Also, it would be great starting point (in terms of UX and functionality) for creating a Discord and/or MS Teams bots as well.

@peterj
Copy link
Collaborator

peterj commented Oct 20, 2025

@apexlnc how do I continue the conversation with the agent? I see that it creates a thread when using @kagent-bot, but if I need to continue the same conversation, I have to do another @kagent-bot within the thread it seems? I wonder if it would make sense to automatically chat with the agent when in thread (e.g. without prefixing each message with kagent-bot) - what do you think?
Screenshot 2025-10-20 at 2 11 32 PM

Copy link
Collaborator

@peterj peterj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a couple of comments

@apexlnc
Copy link
Contributor Author

apexlnc commented Oct 20, 2025

@apexlnc how do I continue the conversation with the agent? I see that it creates a thread when using @kagent-bot, but if I need to continue the same conversation, I have to do another @kagent-bot within the thread it seems? I wonder if it would make sense to automatically chat with the agent when in thread (e.g. without prefixing each message with kagent-bot) - what do you think? Screenshot 2025-10-20 at 2 11 32 PM

You should be able to continue the conversation in the thread. Are you not able to?

This is a great feature - I got it to work; however, I think this Slack bot should probably be in a separate repo, instead of having it in the main repository. @EItanya what do you think?

Also, it would be great starting point (in terms of UX and functionality) for creating a Discord and/or MS Teams bots as well.

Sure, let me know if you want it in another repo, and if so, which repo.

@peterj -- btw, a lot of the "magic" happens once this is merged : #1025

i'm also realizing that i didn't push some of my local changes (mostly housekeeping stuff) -- will do that later after some responses to the comments above

@apexlnc apexlnc force-pushed the feat/slack-bot-integration branch 2 times, most recently from 649f677 to cab2a12 Compare October 21, 2025 03:00
Adds a production-ready Slack bot that provides a unified interface to interact
with Kagent agents through Slack, including full Human-in-the-Loop (HITL) support
for tool approvals.

Key features:
- Socket Mode bot for @mentions and direct messages
- Dynamic agent discovery and intelligent routing with keyword-based routing
- Real-time streaming responses with HITL approval workflow
- RBAC with Slack user group integration
- Prometheus metrics with kagent_slackbot namespace prefix
- Complete Kubernetes manifests (Deployment, HPA, PDB, RBAC)
- Dockerfile for containerized deployment

Architecture:
- Uses A2A SDK types throughout for type safety and validation
- Pydantic models for agent metadata and HITL protocol
- Handles both TaskStatusUpdateEvent and TaskArtifactUpdateEvent
- Structured DataPart decisions for tool approval workflow
- Interactive approval buttons with streaming completion responses

The bot integrates with Kagent's A2A protocol via JSON-RPC 2.0 and supports
all agent types (Declarative, BYO, etc.). Follows bolt-python async patterns.

Addresses maintainer feedback:
- Use Pydantic models for agent data validation
- Full A2A SDK type integration (not raw dicts)
- Metrics namespace prefix for Prometheus
- Code formatted with ruff
- Default permissions.yaml config provided

Signed-off-by: apexlnc <[email protected]>
@apexlnc apexlnc force-pushed the feat/slack-bot-integration branch from cab2a12 to 73ceb6c Compare October 21, 2025 03:02
@marcinkubica
Copy link
Contributor

marcinkubica commented Oct 21, 2025

@apexlnc how do I continue the conversation with the agent? I see that it creates a thread when using @kagent-bot, but if I need to continue the same conversation, I have to do another @kagent-bot within the thread it seems? I wonder if it would make sense to automatically chat with the agent when in thread (e.g. without prefixing each message with kagent-bot) - what do you think? Screenshot 2025-10-20 at 2 11 32 PM

You should be able to continue the conversation in the thread. Are you not able to?


@peterj This is probably for the better: bot should only respond to a configurable calls (ie: @kagent kagent) and not by default to any message in the thread created.

@apexlnc I'm noticing also the emoji response 👀 are not removed after bot responded - they should be present when bot is processing and removed after bot responded.

Also, something nice to steal from Onyx (in the later time) - "continue in kagent" and "I need help from a human"

image image

…plication

Address reviewer feedback from PR review:
- Run ruff formatter on all Python files (all checks pass)
- Remove 👀 emoji reaction after bot response completion
- Fix Docker build by including config/ directory in image
- Reorganize SLACK_SETUP.md to clearly separate Option A (manifest)
  from Option B (manual setup)

Additional code quality improvements:
- Extract duplicate button parsing logic to _parse_button_value() helper
- Extract duplicate SSE streaming logic to _parse_sse_stream() helper
- Replace magic numbers with named constants:
  * SLACK_TEXT_SUMMARY_LENGTH = 200
  * PREVIEW_MAX_LENGTH = 1000
  * UPDATE_THROTTLE_SECONDS = 2
- Use existing AGENT_CACHE_TTL constant in main.py
- Add emoji removal to all exit paths including errors and HITL flows
- Add _remove_reaction() helpers to eliminate further duplication

This eliminates ~60 lines of duplicate code and improves maintainability
without changing any functionality.

Fixes: peterj's review comments on make build, docs, formatting
Signed-off-by: apexlnc <[email protected]>
@apexlnc
Copy link
Contributor Author

apexlnc commented Oct 26, 2025

Thanks for the feedback @peterj @marcinkubica

I believe all the comments have been addressed, but let me know if I missed anything!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants