Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

AWS Logo
Menu
Amazon Connect Custom Bot with Bedrock Multi Agent Collaboration and Human Escalation

Amazon Connect Custom Bot with Bedrock Multi Agent Collaboration and Human Escalation

Integrate your Bedrock Agents as Contact Center Agents providing long-running invocations and free form interactions.

Enrique Rodriguez
Amazon Employee
Published Feb 26, 2025

Introduction

While Amazon Lex could be suitable for basic chatbot integration in Amazon Connect that offers native Amazon Q integration, which is ideal for companies without extensive generative AI expertise seeking quick deployment of AI-powered customer service capabilities (see Amazon Q in Connect documentation), some organizations require more flexibility and control over their AI capabilities, custom reasoning workflows, or sophisticated multi-agent architectures.
This project implements a custom chatbot solution for Amazon Connect that leverages Amazon Bedrock Agents, providing advanced capabilities for companies that need to:
  • Execute long-running reasoning or multi-agent workflows
  • Integrate with custom knowledge bases and Bedrock Agents
  • Implement asynchronous bot interactions
  • Build complex, customized conversation flows
The system is designed to provide AI responses and interactions, while maintaining the ability to escalate to human agents when necessary, ensuring optimal customer service delivery.

Architecture

The solution architecture consists of several key components:
Amazon Connect Instance (existing) for customer interaction management
AWS Lambda functions, DynamoDB tables and SNS Topic for chat processing and bot initialization.
Amazon Bedrock Agent (this repo) for AI-powered responses
Image not found
diagram

The system flow is:

  1. Customer initiates chat in Connect
    • a Inside the contact flow start Bot Lambda initializes the session and store contact id
    • b For every customer message Chat Bot Lambda process that message and responds.
  2. Bedrock Agent is invoked, it could be a single agent or multi agent in a collaboration scheme.
  3. Escalation is handled by specific Agent or Action Group. With RETURN CONTROL the agent signal the application the specific action (escalation) and parameters needed for escalation (order_id, issue, ticket, or other defined)
  4. Amazon Connect identifies the action and moves the contact to a human agent, to continue the interaction with the customer.

Chatbot Sequence Diagram

Image not found
Sequence
For every turn the ChatBot Lambda function parses the message content and invokes the Bedrock Agent. Then it sends the response back to the chat session.
1
2
3
4
5
6
7
8

# Answer with Agent
...
response = bedrock_agent.invoke_agent(content)
print (f"Response: {response}")

if type(response) == str:
chat_service.send_message(response)
If the response is a dictionary, meaning RETURN_CONTROL type of response, that will be signaled to Amazon Connect using Contact Attributes:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
elif type(response) == dict:
print("Updating Contact Attributes")
chat_service.update_contact_attributes(attributes =response)
chat_service.send_message( f"Action: {response.get('functionName')}")

# Dummy response from fictional system invocation_result = OK
return_control_response = bedrock_agent.return_control_invocation_results(
invocation_id=response.get("invocationId"),
action_group=response.get("actionGroup"),
function_name=response.get("functionName"),
invocation_result="OK",
agent_id = response.get("agentId")
)
chat_service.disconnect()
print(f"return_control_response: {return_control_response}")

Deployment

Prerequisites

1) An Amazon Connect instance

You need a Amazon Connect Instance. If you don't have one already you can follow this guide.

2) A Bedrock Agent

A Bedrock agent is needed and it's not deployed in this stack.If you dont have at least 1 working agent you can easily create one. Here are some options:

3) CDK Setup

New to CDK? Start here to learn how to:
  • Install CDK and dependencies
  • Configure your environment
  • Bootstrap your AWS account and region

Deploy the Custom Bot Stack

Clone the repo:
1
git clone https://github.com/aws-samples/generative-ai-ml-latam-samples
Set up environment:
1
2
3
4
cd samples/connect-custom-bot
python3 -m venv .venv
source .venv/bin/activate # On Windows use: .venv\Scripts\activate.bat
pip install -r requirements.txt
Deploy the stack:
1
cdk cdk deploy --parameters instanceId=<YOUR INSTANCE ID>
Replace <YOUR INSTANCE ID> with your Amazon Connect Instance Id

Post deployment setup

AWS Lambda Environment Variables

After deployed, go to the ChatBot Lambda function and update the AGENT_ALIAS_ID and AGENT_ID environment variables :
Image not found
environment
The AGENT_ID can be seen in bedrock agent console, and TSTALIASID is the default alias ID for the first agent (Draft version).

Amazon Connect Flow

If you passed a instance_id to the stack deployment, a contact flow called Custom Bot Flow via CDK will be created in that instance with CDK.
If you want to do it manually, download the Flow Definition and import that in your Amazon Connect Instance. After importing, make sure you are invoking your StartBot Lambda function and using BasicQueue in Set Working Queue block.
Invoke AWS Lambda function Block
Image not found
connect flow1
Set working Queue Block
Image not found
connect flow2
Then save and publish the flow.

Testing

In order to test the chatbot, go to your Amazon Connect Instance and Test Chat using the newly created Custom Bot Flow via CDK
Image not found

Demo

Just interact with your chatbot, in this example we have a multi agent order support and escalation agent.
Image not found
demo

Security

For information about securing your implementation, please refer to the Amazon Bedrock Security documentation. This will help you configure Amazon Bedrock according to your security and compliance requirements.

Cost Considerations

The main cost components for this project include:

Decommissioning

To remove all resources:
  • Using CDK CLI: Run cdk destroy
  • Using AWS Console: Navigate to CloudFormation and select "Delete"
Enjoy building!
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

Comments

Log in to comment