Amazon Bedrock AgentCoreとSlackの統合
AWSはAmazon Bedrock AgentCoreとSlackの統合方法を公開し、AIエージェントをワークスペースに直接組み込むための技術的実装と再利用可能なインフラ構築を解説した。
キーポイント
Slack統合によるAIエージェントの直接利用
Amazon Bedrock AgentCoreをSlackと統合することで、チームはアプリケーション間を移動せずにAIエージェントと対話でき、会話履歴の喪失や再認証の問題を解決する。
技術的課題の解決方法
統合ではSlackイベントリクエストのセキュリティ検証、スレッド間での会話コンテキスト維持、Slackのタイムアウト制限を超える応答の管理という3つの技術要件を処理する。
再利用可能なインフラ構築手法
AWS CDKを使用したSlack統合の構築方法を解説し、3つのLambda関数によるインフラデプロイ、適切なイベントサブスクリプション設定、多くのユースケースに対応する会話管理パターンを実装する。
サーバーレス統合アーキテクチャ
ソリューションはAmazon API Gateway、AWS Lambda、AWS Secrets Manager、Amazon SQSを使用したサーバーレス統合インフラと、AgentCore Runtimeで実行されるコンテナ化されたエージェントで構成される。
Slackイベントサブスクリプションの設定手順
デプロイで取得したWebhook URLをSlackアプリのEvent Subscriptionsに設定し、app_mentionとimのボットイベントを追加する必要があります。
デプロイ後のテスト方法
SlackのAppsセクションからagent-core-weather-agentをチャンネルに招待し、@agent-core-weather-agentで天気情報を取得するなどして統合をテストできます。
影響分析・編集コメントを表示
影響分析
この記事はAWSが提供するAIエージェントプラットフォームの実用的な応用例を示しており、企業が既存のコラボレーションツールにAI機能をシームレスに統合する方法を具体化している。技術的実装の詳細を公開することで、開発者の導入障壁を下げ、Bedrock AgentCoreの採用促進を図っている。
編集コメント
AWSの公式ブログ記事という性質上、営業PR色が強いが、具体的な技術実装の詳細まで踏み込んで解説している点は評価できる。既存ツールとの統合によるAIエージェントの実用化トレンドを反映した内容。
Amazon Bedrock AgentCore を Slack と統合することで、AI エージェントをワークスペースに直接導入できます。チームはアプリケーション間を行き来したり、会話履歴を失ったり、再認証を行ったりすることなく、エージェントと対話できるようになります。この統合では、セキュリティのために Slack イベントリクエストを検証し、スレッド間で会話の文脈を維持し、Slack のタイムアウト制限を超えるレスポンスを管理するという 3 つの技術要件に対応します。
開発者は通常、Slack 統合用のカスタム Webhook ハンドラー構築に時間を費やしています。AgentCore は、Slack 内で完結して、組み込みの会話メモリ、エージェントおよびそのツールへの安全なアクセス、エージェントの使用状況を追跡するアイデンティティ管理を提供することで、この作業を不要にします。
本稿では、AWS Cloud Development Kit (AWS CDK) を使用した Slack 統合の構築方法を実演します。3 つの専門的な AWS Lambda 関数でインフラストラクチャを展開し、Slack のセキュリティ要件に対応するためにイベントサブスクリプションを適切に設定する方法、そして多くのエージェントユースケースで機能する会話管理パターンを実装する方法を学びます。例として天気予報用エージェントを使用していますが、構築している統合層は完全に再利用可能です。Slack がエージェントと通信する方法を変更することなく、ランタイムやツールを特定のビジネスニーズに合わせてカスタマイズできます。
ソリューションの概要
本ソリューションは、主に 2 つのコンポーネントで構成されています。1 つ目は Slack とエージェント間の通信をルーティングおよび管理する Slack 統合インフラストラクチャであり、もう 1 つはクエリを処理して応答を行う Amazon AgentCore Runtime です。
本ソリューションにおける統合インフラストラクチャでは、サーバーレス型の統合を実現するために、Amazon API Gateway、AWS Lambda、AWS Secrets Manager、および Amazon Simple Queue Service (Amazon SQS) を使用しています。
エージェントはコンテナ化され、AgentCore Runtime 上で実行されるようにホストされています。このエージェントは、ツールのアクセスに Amazon Bedrock AgentCore Gateway と、会話履歴の管理に AgentCore Memory を統合した Strands Agents SDK を用いて構築されています。ランタイムは会話全体を通じてコンテキストを維持し、ツールの実行と通信のための標準化されたプロトコルである Model Context Protocol (MCP) を使用してツールを呼び出します。
これらのコンポーネントが整った状態で、以下のセクションではこれらがアーキテクチャ内でどのように連携して動作するかを検証します。
アーキテクチャ図
以下の図は、3 つの主要セクションを含むソリューションアーキテクチャを示しています:
セクション A – イメージビルドインフラストラクチャ – まず、WeatherAgentImageStack CDK がコンテナイメージビルドパイプライン(Amazon Simple Storage Service (Amazon S3) バケット、AWS CodeBuild プロジェクト、および Amazon Elastic Container Registry (Amazon ECR) リポジトリ)をデプロイします。これにより、CodeBuild を使用して AWS Graviton(ARM64 対応)のコンテナイメージが作成され、AgentCore Runtime で利用できるよう ECR リポジトリに格納されます。
セクション B – AgentCore コンポーネント – 次に、WeatherAgentCoreStack CDK が AgentCore Runtime、Gateway、Memory、および AWS Lambda 関数をデプロイします。Runtime は Strands Agents Framework(オープンソース AI エージェント SDK)を使用して、モデル呼び出し、ツール呼び出し、会話メモリのオーケストレーションを行います。
セクション C – Slack 統合インフラストラクチャ – 最後に、WeatherAgentSlackStack が統合インフラストラクチャ(API Gateway、Secrets Manager、Lambda 関数、SQS)をデプロイします。この層は、Webhook の検証、Amazon Simple Queue Service (Amazon SQS) によるキューイング、および 3 つの Lambda 関数を介したメッセージ処理を担当します。このレイヤーは AgentCore のユースケースに対して再利用可能です。
リクエストフローは以下の手順で構成されます:
- ユーザーが Slack でダイレクトメッセージまたはチャンネル内で @appname と宛先を指定してメッセージを送信します。
- Slack が API Gateway に対して Webhook の POST リクエストを送信します。
- このリクエストは検証用 Lambda 関数に転送されます。
- Lambda は Secrets Manager から Slack の署名シークレットとボットトークンを取得し、真正性を検証します。
- 検証完了後、Lambda は非同期で SQS 統合 Lambda を呼び出します。
- SQS 統合 Lambda は、Slack のスレッド内でユーザーに「リクエストを処理中…」というメッセージを送信します。
- SQS 統合 Lambda はそのメッセージを SQS FIFO キューへ送信します。
- このキューが Agent 統合 Lambda をトリガーします。
- Lambda は、ユーザーのクエリと Slack スレッドタイムスタンプから取得したセッション ID を用いて、AgentCore Runtime を呼び出します。
- AgentCoreMemorySessionManager は、セッション ID(スレッドタイムスタンプ)およびアクター ID(ユーザー ID)を使用して、AgentCore Memory から会話履歴を取得します。
- Strands Framework は MCP プロトコルを用いて AgentCore Gateway からツールを取得します。
- Strands Framework は、メッセージ、コンテキスト、およびツールを指定して Amazon Bedrock モデル(Nova Pro)を呼び出します。
- モデルはどのツールを呼び出すかを判断し、リクエストを生成します。
- Gateway はツールの呼び出しを Lambda 上の MCP サーバーへルーティングし、そこで気象関連のツールが実行されます。
- ツール結果が Strands Framework に返され、必要に応じて再度モデルを呼び出します。
- Strands Framework は会話のターンを AgentCore Memory に保存します。
- Agent 統合 Lambda は、「リクエストを処理中…」というメッセージをエージェントの応答に更新します。
事前準備
このソリューションには、以下の事前条件が必要です:
- Amazon Bedrock AgentCore, Lambda, API Gateway, SQS, ECR, CodeBuild, AWS Identity and Access Management (IAM), Secrets Manager, Amazon Bedrock に対する権限を持つ AWS アカウント
- 認証情報で設定された AWS Command Line Interface (AWS CLI) (v2.x)
- Node.js (v18 以降) と npm のインストール済み
- AWS CDK が AWS アカウント内でインストールされ、ブートストラップされていること
インストール: npm install -g aws-cdk
ブートストラップ: cdk bootstrap aws://ACCOUNT-NUMBER/REGION
- Slack アカウント (2 つのオプション):
企業の Slack アカウントの場合、管理者と連携して統合アプリケーションを作成・公開するか、サンドボックス組織を使用してください。
または、テストや実験のために独自の Slack アカウントとワークスペースを作成することもできます。
- アプリ名には、agent-core-weather-agent と入力してください。
- アプリを開発するワークスペースを選択するには、このアプリケーションを使用したいワークスペースを選んでください。
- [Create App] を選択します。
アプリケーションが作成されると、Basic Information ページに移動されます。
- ナビゲーションペインの Features 下で、[OAuth & Permissions] を選択してください。
- Scopes セクションに移動し、Bot Token Scopes の下で、[Add an OAuth Scope] を選択して以下を入力することで、以下のスコープを追加します:
app_mentions:read
- chat:write
- im:history
- im:read
- im:write
- [OAuth & Permissions] ページで、[OAuth Tokens] セクションに移動し、[Install to ExampleCorp] を選択してください。
- 次のページで、プロセスを完了するために [Allow] を選択します。
- [OAuth & Permissions] ページで、[OAuth Tokens] に移動し、作成された Bot User OAuth Token の値をコピーしてください。この値は、インフラストラクチャのデプロイ時に後で使用できるよう、メモ帳に保存しておいてください。
- ナビゲーションペインの Settings 下で、[Basic Information] を選択してください。
- Signing Secret に移動し、
- この値をコピーしてメモ帳に保存し、インフラストラクチャのデプロイ時に後で使用してください。
- Slack 内でアプリとのダイレクトメッセージングを有効にするには、ナビゲーションペインの App Home に移動します。
- [Show Tabs] セクションで、[Allow users to send Slash commands and messages from the messages tab] を有効にします。
注意: イベントサブスクリプションの設定は、インフラストラクチャのデプロイと Webhook URL の取得後、ステップ 3 で完了します。
ステップ 2: インフラストラクチャのデプロイ
GitHub リポジトリをクローンし、プロジェクトディレクトリに移動してください:
git clone https://github.com/aws-samples/sample-Integrating-Amazon-Bedrock-AgentCore-with-Slack
cd sample-Integrating-Amazon-Bedrock-AgentCore-with-Slack
デプロイには、Slack の認証情報を環境変数として設定し、デプロイスクリプトを実行する必要があります。
export SLACK_BOT_TOKEN="xoxb-your-token-here"
export SLACK_SIGNING_SECRET="your-signing-secret-here"
./deploy.sh
デプロイには約 10〜15 分かかり、3 つの CDK スタックが作成されます。コンテナビルド用のイメージスタック、ランタイム、ゲートウェイ、メモリを含むエージェントスタック、および API Gateway と Lambda 関数を含む Slack スタックです。デプロイ出力には、次のステップで使用する Webhook URL が含まれています。
ステップ 3: Slack イベントサブスクリプションの設定
インフラストラクチャのデプロイと Webhook URL の取得後、Slack アプリの設定を完了できます。
- 設定には、Slack API の Slack アプリに戻り、agent-core-weather-agent を選択する必要があります
- ナビゲーションペインの「機能」セクションで、「イベントサブスクリプション」を選択します。
- 「イベントを有効にする」をオンに切り替えます。
- 「リクエスト URL」フィールドに、デプロイ出力から取得した Webhook URL を貼り付けます。
- URL が検証されたことを示す緑色のチェックマークと「Verified」という表示が現れたら、「ボットイベントの購読へ移動」します。
- 「ボットユーザーイベントを追加」を選択し、以下のイベントを追加します:
app_mention
- im
- ページ下部にある「変更を保存」をクリックします。
- 「設定」セクションで、「アプリのインストール」へ移動し、「ExampleCorp への再インストール」を選択します。ポップアップ画面が表示されたら、「許可」を選択してください。
ステップ 4: AgentCore の Slack 統合テスト
テストには、Slack の「Apps」セクションで agent-core-weather-agent を見つける必要があります。このアプリを既存のチャンネルに招待するには、/invite @agent-core-weather-agent と入力します。このアプリケーションをチャンネルに追加した後、ユーザーは @agent-core-weather-agent を使用して天候情報を取得したり、AgentCore Agent と対話したりできます。また、直接チャットすることも可能です
原文を表示
Integrating Amazon Bedrock AgentCore with Slack brings AI agents directly into your workspace. Your teams can interact with agents without jumping between applications, losing conversation history, or re-authenticating. The integration handles three technical requirements: validating Slack event requests for security, maintaining conversation context across threads, and managing responses that exceed Slack’s timeout limits.
Developers typically spend time building custom webhook handlers for Slack integrations. AgentCore helps remove this work by providing built-in conversation memory, secure access to agents and their tools, and identity management that tracks agent usage, all from within Slack.
In this post, we demonstrate how to build a Slack integration using AWS Cloud Development Kit (AWS CDK). You will learn how to deploy the infrastructure with three specialized AWS Lambda functions, configure event subscriptions properly to handle Slack’s security requirements, and implement conversation management patterns that work for many agent use cases. We’re using a weather agent as our example, but the integration layer that you’re building is completely reusable. You can customize the runtime and tools for your specific business needs without changing how Slack communicates with your agent.
Solution overview
This solution consists of two main components: The Slack integration infrastructure and the Amazon AgentCore Runtime with tools. The integration infrastructure routes and manages communication between Slack and the agent, as the runtime processes and responds to queries.
The integration infrastructure in this solution uses Amazon API Gateway, AWS Lambda, AWS Secrets Manager, and Amazon Simple Queue Service (Amazon SQS) for serverless integration.
The agent has been containerized and hosted to run in AgentCore Runtime. It’s built with the Strands Agents SDK that integrates with Amazon Bedrock AgentCore Gateway for tool access and AgentCore Memory for conversation history. The runtime maintains context throughout conversations and uses the Model Context Protocol (MCP), a standardized protocol for tool execution and communication, to invoke tools.
With these components in place, the following section examines how they work together in the architecture.
Architecture diagram
The following diagram represents the solution architecture, which contains three key sections:
Section A – Image Build Infrastructure – First, WeatherAgentImageStack CDK deploys the container image build pipeline (Amazon Simple Storage Service (Amazon S3) bucket, AWS CodeBuild project, and Amazon Elastic Container Registry (Amazon ECR) repository). This uses CodeBuild to create AWS Graviton (ARM64) container images that are stored in the ECR repository for use by the AgentCore Runtime.
Section B – AgentCore Components – Next, WeatherAgentCoreStack CDK deploys the AgentCore Runtime, Gateway, Memory, and AWS Lambda function. The Runtime uses the Strands Agents Framework an Open Source AI Agents SDK to orchestrate model invocations, tool calls, and conversation memory.
Section C – Slack Integration Infrastructure – Lastly, WeatherAgentSlackStack deploys the integration infrastructure (API Gateway, Secrets Manager, Lambda functions, and SQS). This handles webhook verification, Amazon Simple Queue Service (Amazon SQS) queuing, and message processing through three Lambda functions. This layer is reusable for AgentCore use cases.
The request flow consists of the following steps:
- A user sends a message in Slack through direct message or @appname in a channel.
- Slack sends a webhook POST request to API Gateway.
- The request is forwarded to the verification Lambda function.
- The Lambda retrieves the Slack signing secret and bot token from Secrets Manager to verify authenticity.
- After verification, the Lambda 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 invokes AgentCore Runtime with the user’s query and a session ID from the Slack thread timestamp.
- AgentCoreMemorySessionManager retrieves conversation history from AgentCore Memory using the session ID (thread timestamp) 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 weather tools.
- Tool results return to the Strands Framework, which can 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
This solution requires the following prerequisites:
- AWS account with permissions for:
Amazon Bedrock AgentCore, Lambda, API Gateway, SQS, ECR, CodeBuild, AWS Identity and Access Management (IAM), Secrets Manager, 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
Install: npm install -g aws-cdk
- Bootstrap: cdk bootstrap aws://ACCOUNT-NUMBER/REGION
- Slack account (two options):
For company Slack accounts, work with your administrator to create and publish the integration application, or you can use a sandbox organization
- Alternatively, create your own Slack account and workspace for testing and experimentation
Step 1: Create a Slack App
Creating applications in Slack requires specific permissions that vary by organization. If the necessary access is unavailable, contact your Slack administrator. The screenshots in this walkthrough are from a personal Slack account and are intended to demonstrate the implementation process that can be followed for this solution.
- Go to Slack API and choose Create New App.
- In the Create an app pop-up, choose From scratch.
- For App Name, enter agent-core-weather-agent.
- For Pick a workspace to develop your app in, choose the workspace where you want to use this application.
- Choose Create App.
After the application is created, you will be taken to the Basic Information page.
- In the navigation pane under Features, choose OAuth & Permissions.
- Navigate to the Scopes section and under Bot Token Scopes, add the following scopes by choosing Add an OAuth Scope and entering:
app_mentions:read
- chat:write
- im:history
- im:read
- im:write
- On the OAuth & Permissions page, navigate to the OAuth Tokens section and choose Install to ExampleCorp.
- On the following page, choose Allow to complete the process.
- On the OAuth & Permissions page, navigate to OAuth Tokens and copy the value for the Bot User OAuth Token that has been created. Save this in a notepad to use later when you’re deploying the infrastructure.
- In the navigation pane under Settings, choose Basic Information.
- Navigate to Signing Secret and choose
- Copy and save this value to your notepad to use later when you’re deploying the infrastructure.
- To allow direct messaging with the app within Slack, navigate to App Home in the navigation pane under
- In the Show Tabs section, enable Allow users to send Slash commands and messages from the messages tab.
Note: You will complete the Event Subscriptions configuration in Step 3 after deploying the infrastructure and obtaining the Webhook URL.
Step 2: Deploy the infrastructure
Clone the GitHub repository and navigate to the project directory:
git clone https://github.com/aws-samples/sample-Integrating-Amazon-Bedrock-AgentCore-with-Slack
cd sample-Integrating-Amazon-Bedrock-AgentCore-with-SlackThe deployment requires setting Slack credentials as environment variables and running the deployment script.
export SLACK_BOT_TOKEN="xoxb-your-token-here"
export SLACK_SIGNING_SECRET="your-signing-secret-here"
./deploy.shThe deployment takes approximately 10–15 minutes and creates three CDK stacks: an Image Stack for the container build, an Agent Stack with Runtime, Gateway, and Memory, and a Slack Stack with API Gateway and Lambda functions. The deployment output provides the Webhook URL for the next step.
Step 3: Configure Slack event subscriptions
After deploying the infrastructure and obtaining the Webhook URL, the Slack app configuration can be completed.
- The configuration requires returning to the Slack app at Slack API and selecting the agent-core-weather-agent
- In the navigation pane under Features, choose Event Subscriptions.
- Toggle Enable Events to
- In the Request URL field, paste the Webhook URL from the deployment output.
- After the URL is verified (indicated by a green checkmark with ‘Verified’), navigate to the Subscribe to bot events
- Choose Add Bot User Event and add the following events:
app_mention
- im
- Choose Save Changes at the bottom of the page.
- Under Settings, navigate to Install App and select Reinstall to ExampleCorp. When the pop-up screen appears, select Allow.
Step 4: Test the integration of AgentCore in Slack
Testing requires locating agent-core-weather-agent in the Apps section of Slack. You can invite the APP to an existing channel by typing in /invite @agent-core-weather-agent. After adding this application to a channel, users can interact with the AgentCore Agent by using @agent-core-weather-agent to get weather information, or you can also chat directl
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み