A comprehensive toolkit for building and running AI-powered Slack bots using LangGraph and Slack Bolt API. This implementation integrates advanced AI capabilities through LangGraph and LangChain, supporting both OpenAI and Anthropic models.
- Natural language interaction through mentions
- Context-aware responses using conversation history
- Thread-based communication management
- Interactive message components
- Support for both OpenAI and Anthropic models
help
- Display detailed usage instructionsai [question]
- Direct interaction with AI agenthello
- Interactive greeting with button interface
- Advanced natural language processing with LangGraph and LangChain
- Conversation history consideration
- Interactive UI elements (buttons, etc.)
- Comprehensive error handling and feedback
- Customizable workflows
- Tool execution and complex interactions
- Python 3.11 or higher
- Poetry for dependency management
- Slack App credentials
- OpenAI API key (or Anthropic API key if using Claude)
- LangGraph setup
Create a .env
file with the following:
# Slack Configuration
SLACK_BOT_TOKEN=your-bot-token
SLACK_APP_TOKEN=your-app-token
SLACK_SIGNING_SECRET=your-signing-secret
PORT=3000 # Optional, defaults to 3000
# AI Configuration
OPENAI_API_KEY=your-openai-api-key
# Or for Anthropic:
# ANTHROPIC_API_KEY=your-anthropic-api-key
# LangGraph Configuration
LANGGRAPH_URL=your-langgraph-url
LANGGRAPH_TOKEN=your-langgraph-token
- Clone the repository
git clone https://github.com/kyaukyuai/slack-ai-agent-starter.git
cd slack-ai-agent-starter
- Install dependencies
poetry install
- Start the development servers
# Start both LangGraph and Web servers
make dev
# Or start them separately
make dev-langgraph # For LangGraph server
make dev-web # For Web server
- Mention the bot:
@AI Assistant hello
- Use direct commands:
ai what's the weather?
- Get help:
help
- Use threads for related conversations
- Be specific with questions
- Provide context when needed
- Use appropriate commands for different tasks
slack_ai_agent/
├── agents/ # AI agent implementation
│ ├── simple_agent.py # LangGraph AI agent implementation
│ ├── security/ # Security-related functionality
│ └── utils/
│ ├── nodes.py # Agent workflow nodes
│ ├── tools.py # Tool implementations
│ └── types.py # Type definitions
├── slack/
│ ├── handler/ # Event, message, and action handlers
│ ├── app.py # Main Slack app configuration
│ └── utils.py # Utility functions
└── README.md
slack-bolt
: For Slack bot functionalitylanggraph
: For AI agent workflow managementlangchain_core
: Core LangChain functionalitylangchain_openai
: OpenAI model integrationlangchain_anthropic
: Anthropic model integrationpython-dotenv
: For environment variable management
ruff
: For code lintingmypy
: For type checkingpre-commit
: For git hookslanggraph-cli
: For development tools
- Type hints and docstrings for all functions and classes
- Modular design with separate packages for Slack bot and AI agent
- Clear separation of concerns between bot handling and AI processing
- Comprehensive error handling and logging
The implementation includes:
- Graceful handling of API errors
- Detailed logging for debugging
- User-friendly error messages in Slack
- Tool execution result reporting
To add new capabilities:
- Define new tool functions in
agents/utils/nodes.py
- Update the agent workflow in
agents/simple_agent.py
- Add any new environment variables to
.env
- Update type definitions in
agents/utils/types.py
if needed
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.