Integrating Amazon Bedrock AgentCore with Slack for AI-Powered Workflows
Companies are increasingly adopting generative AI to enhance productivity and streamline operations. Integrating AI agents directly into communication platforms like Slack offers a seamless way to access AI assistance without disrupting existing workflows. Amazon Bedrock AgentCore simplifies this integration, allowing teams to interact with AI agents directly within Slack, eliminating the need to switch applications and re-authenticate.
The Benefits of Slack and AgentCore Integration
Integrating Amazon Bedrock AgentCore with Slack addresses three key technical challenges: ensuring the security of Slack event requests, maintaining conversation context across multiple messages, and managing responses that exceed Slack’s message length limitations. Traditionally, developers spend significant time building custom webhook handlers for Slack integrations. AgentCore streamlines this process by providing built-in conversation memory, secure access to agents and their tools, and identity management to track agent usage—all accessible directly within Slack.
Solution Overview
The solution comprises two main components: the Slack integration infrastructure and the Amazon AgentCore Runtime with tools. The integration infrastructure manages communication between Slack and the agent, although the runtime processes and responds to user queries. This architecture leverages serverless technologies, including Amazon API Gateway, AWS Lambda, AWS Secrets Manager, and Amazon Simple Queue Service (Amazon SQS).
The agent itself is containerized and hosted within the AgentCore Runtime, built using the Strands Agents SDK. This SDK integrates with Amazon Bedrock AgentCore Gateway for tool access and AgentCore Memory for preserving conversation history. The runtime utilizes the Model Context Protocol (MCP), a standardized protocol for tool execution and communication.
Architecture Breakdown
Image Build Infrastructure
The initial step involves deploying a container image build pipeline using Amazon Simple Storage Service (Amazon S3), AWS CodeBuild, and Amazon Elastic Container Registry (Amazon ECR). CodeBuild creates AWS Graviton (ARM64) container images, which are then stored in the ECR repository for use by the AgentCore Runtime.
AgentCore Components
The AgentCore Runtime, Gateway, Memory, and AWS Lambda function are deployed using the WeatherAgentCoreStack CDK. The Runtime employs the Strands Agents Framework, an open-source AI Agents SDK, to orchestrate model invocations, tool calls, and conversation memory.
Slack Integration Infrastructure
The Slack integration infrastructure, including API Gateway, Secrets Manager, Lambda functions, and SQS, is deployed using the WeatherAgentSlackStack. This layer handles webhook verification, message queuing with Amazon SQS, and message processing through three Lambda functions. This integration layer is reusable across various AgentCore use cases.
Request Flow
- A user sends a message in Slack, either through a direct message or by mentioning the app (@appname) in a channel.
- Slack sends a webhook POST request to API Gateway.
- The request is forwarded to the verification Lambda function.
- The Lambda function retrieves the Slack signing secret and bot token from Secrets Manager to verify authenticity.
- After verification, the Lambda function asynchronously invokes the SQS integration Lambda.
- The SQS integration Lambda sends a “Processing your request…” message to the user in a Slack thread.
- The SQS integration Lambda sends the message to the SQS FIFO queue.
- The queue triggers the Agent Integration Lambda.
- The Lambda function invokes AgentCore Runtime with the user’s query and a session ID derived from the Slack thread timestamp.
- AgentCoreMemorySessionManager retrieves conversation history from AgentCore Memory using the session ID and actor ID (user ID).
- The Strands Framework retrieves tools from AgentCore Gateway using the MCP protocol.
- The Strands Framework invokes the Amazon Bedrock model (Nova Pro) with the message, context, and tools.
- The model determines which tools to invoke and generates requests.
- The Gateway routes tool invocations to the MCP server on Lambda, which executes the necessary tools.
- Tool results are returned to the Strands Framework, which may invoke the model again if needed.
- The Strands Framework stores the conversation turn in AgentCore Memory.
- The Agent Integration Lambda updates the “Processing your request…” message with the agent’s response.
Prerequisites
- AWS account with permissions for Amazon Bedrock AgentCore, Lambda, API Gateway, SQS, ECR, CodeBuild, IAM, Secrets Manager, and Amazon Bedrock.
- AWS Command Line Interface (AWS CLI) (v2.x) configured with credentials.
- Node.js (v18 or later) and npm installed.
- AWS CDK installed and bootstrapped in your AWS account (
npm install -g aws-cdkandcdk bootstrap aws://ACCOUNT-NUMBER/REGION). - Slack account (either a company account with administrative access or a personal Slack account for testing).
Step-by-Step Implementation
Step 1: Create a Slack App
Navigate to the Slack API and choose “Create Fresh App.” Enter a name (e.g., agent-core-weather-agent) and select the workspace where you wish to use the application. Under “Features,” select “OAuth & Permissions.” Add the following bot token scopes: app_mentions:read, chat:write, im:history, im:read, and im:write. Install the app to your workspace and copy the Bot User OAuth Token. Likewise, copy the Signing Secret from the “Basic Information” settings.
Step 2: Deploy the Infrastructure
Clone the GitHub repository and navigate to the project directory. Set the Slack credentials as environment variables: export SLACK_BOT_TOKEN="xoxb-your-token-here" and export SLACK_SIGNING_SECRET="your-signing-secret-here". Run the deployment script: ./deploy.sh. This process takes approximately 10–15 minutes and creates three CDK stacks.
Step 3: Configure Slack Event Subscriptions
Return to the Slack app configuration and navigate to “Event Subscriptions.” Enable Events and paste the Webhook URL obtained from the deployment output into the “Request URL” field. Subscribe to the following bot events: app_mention and message. Reinstall the app to your workspace.
Step 4: Test the Integration
Locate the agent-core-weather-agent app in the Apps section of Slack and invite it to a channel or direct message it. Interact with the agent by using @agent-core-weather-agent to request information, such as “What’s the weather in Dallas today?”
Key Architectural Considerations
Session Management
Slack organizes conversations into threads identified by timestamps. AgentCore uses these timestamps as session IDs to maintain conversation context, eliminating the need for external state management.
Asynchronous Processing
The architecture utilizes Lambda functions and SQS to handle asynchronous processing, ensuring that Slack receives immediate acknowledgment while the agent processes requests in the background.
Conversation Memory
AgentCore Memory, integrated with the Strands framework, preserves conversation history for context continuity.
Cleanup
Run ./cleanup.sh to remove the deployed CDK stacks and associated resources.
Conclusion
This integration of Amazon Bedrock AgentCore with Slack provides a powerful solution for incorporating AI assistance into daily workflows. By leveraging serverless technologies and standardized protocols, this architecture offers a modular and reusable foundation for building a wide range of AI-powered applications. The ability to customize the runtime and tools allows organizations to adapt this solution to their specific business needs, driving productivity and innovation.