
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.
- 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
- 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.
- Bedrock Agent is invoked, it could be a single agent or multi agent in a collaboration scheme.
- 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)
- Amazon Connect identifies the action and moves the contact to a human agent, to continue the interaction with the customer.
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)
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}")
- Multi-Agent Collaboration System with escalation using CDK. Recommended, this are the agents in the diagram and in the demo.
- Create and configure agent manually (manually)
- Amazon Bedrock Agent Samples For mor examples and dive deep.
- Install CDK and dependencies
- Configure your environment
- Bootstrap your AWS account and region
1
git clone https://github.com/aws-samples/generative-ai-ml-latam-samples
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
1
cdk cdk deploy --parameters instanceId=<YOUR INSTANCE ID>
<YOUR INSTANCE ID>
with your Amazon Connect Instance IdAGENT_ALIAS_ID
and AGENT_ID
environment variables :AGENT_ID
can be seen in bedrock agent console, and TSTALIASID is the default alias ID for the first agent (Draft version).Custom Bot Flow via CDK
will be created in that instance with CDK.StartBot
Lambda function and using BasicQueue
in Set Working Queue
block.Custom Bot Flow via CDK
- Amazon Connect Chat: 0,004 USD per message
- AWS Lambda: Likely covered by free tier for this demo (1 million free requests and 400,000 GB-seconds of compute time per month)
- Amazon SNS (no charges for lambda delivery)
- Using CDK CLI: Run
cdk destroy
- Using AWS Console: Navigate to CloudFormation and select "Delete"
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.