How it works
At a high level, the Amazon Connect integration with GenerativeAgent works by handing off the conversation between your Amazon Connect flow and GenerativeAgent:- Hand off the conversation to GenerativeAgent through Call Transfer over PSTN.
- GenerativeAgent handles the conversation using Lambda functions to communicate with ASAPP’s APIs, and respond to the caller using a Text to Speech (TTS) service.
- Return control back to your Amazon Connect Flow when:
- The conversation is successfully completed
- The caller requests a human agent
- An error occurs
- Use Output Context of the call to determine the next course of action.
Detailed Flow
Detailed Flow
Here’s how a GenerativeAgent call will work in detail within your Amazon Connect:
- Incoming call: A customer calls your existing phone number.
- Call Processing: Amazon Connect processes the call and determines when to transfer to GenerativeAgent.
- Request a number: Amazon Connect invokes a Lambda function to request a phone number from ASAPP to transfer the call to.
- Transfer the call: Amazon Connect transfers the call to the GenerativeAgent using Call Transfer over PSTN.
- GenerativeAgent interaction: GenerativeAgent takes over the call and engages with the customer using ASAPP’s APIs. It processes the customer’s requests, generates responses, communicates back to the customer.
- Call Transfer back: The call with GenerativeAgent disconnects, and control returns to Amazon Connect.
- Request Call Context: Amazon Connect requests the call context from GenerativeAgent using a Lambda function and passes the input context/ variable to determine the outcome of the conversation.
- Call Context: GenerativeAgent returns the call context to Amazon Connect, which includes:
- The conversation outcome
- Any error messages
- Instructions for next steps (e.g., transfer to agent)
- Next Steps: Based on the call context, Amazon Connect decides the next steps, such as:
- Ending the call if the conversation was successful.
- Transferring to a human agent if requested by the customer.
- Handling errors appropriately.

Before you Begin
Before using the GenerativeAgent integration with Amazon Connect, you need to:-
Get your API Key Id and Secret
- Ensure your API key has been configured to access GenerativeAgent APIs. Reach out to your ASAPP team if you need access enabled.
-
Have an existing Amazon Connect instance:
- Have claimed phone numbers.
- Access to an Amazon Connect admin account.
-
Be familiar with AWS including Amazon Connect, IAM roles, and more:
AWS Components
You will set up and configure the following AWS services:- Amazon Connect - Handles call flow and audio streaming
- Lambda functions - These functions will handle communication between Amazon Connect and GenerativeAgent
- Enable Call Transfer over PSTN by contacting your ASAPP account team.
Configuring Amazon Connect with GenerativeAgent
Step 1: Create Lambda Functions
Lambda functions are used to interact with ASAPP’s GenerativeAgent APIs to create call transfers and retrieve call context. They can be created using the AWS Console or AWS API. To create a Lambda function in AWS Console:- Log in to the AWS Management Console.
- Open Lambda.
-
Select Author from scratch and fill in the required fields:
After filling in the required fields, click Create function.
- Basic Information
- Execution Role
- Function name:
call-transferor ‘get-call-context ’ - Runtime: Select
Node.js 22.x - Architecture: Select
x86_64
- In the Function Overview section, look for ARN and save it.
-
Go to the Code tab, click upload from and select
.zipfile to upload your Lambda function code. Click Deploy. -
Go to the Configuration tab, select Environment variables, and add the following environment variables:
Variable Description ASAPP_API_IDAPI Credential provided by ASAPP. ASAPP_API_SECRETAPI Credential provided by ASAPP. ASAPP_API_HOSTAPI hostname provided by ASAPP, usually api.asapp.com - Click Save.
Sample Lambda function code to create Call Transfer
Sample Lambda function code to create Call Transfer
| Parameter | Description |
|---|---|
taskName | (Optional) The name of the GenerativeAgent task to be initiated in the initial Connections. |
customerId | The unique identifier for the customer. If not provided, the calling number of the caller will be used as the customerId. Ensure the value is unique and consistent for each customer to avoid integration issues. |
| Field | Type | Description |
|---|---|---|
result | string | ”ok” if the call transfer was created successfully, “error” otherwise. |
error | string | Error message if the call transfer failed. |
transferNumber | string | A E.164 formatted PSTN number assigned to transfer the call by ASAPP. |
Sample Lambda function code to retrieve Call Context
Sample Lambda function code to retrieve Call Context
| Parameter | Description |
|---|---|
contactId | The unique identifier for the contact. This is typically the ContactId from the Amazon Connect event. |
| Field | Type | Description |
|---|---|---|
result | string | ”ok” if the call context was retrieved successfully, “error” otherwise. On “Ok” response, it includes the Call Transfer Data. |
outputContext | object | The output context of the call, which includes the conversation |
| Field | Type | Description |
|---|---|---|
ID | string | The unique identifier for the call transfer. This is typically the Transfer ID. |
externalConversationId | string | The external conversation ID associated with the call transfer. |
status | string | The status of the call transfer, e.g., “COMPLETED”. |
createdAt | string | The timestamp when the call transfer was created. |
callReceivedAt | string | The timestamp when the call was received. |
completedAt | string | The timestamp when the call transfer was completed. |
inputContext | object | The input context for the call transfer, which includes variables such as taskName and inputVariables. |
inputContext.taskName | string | The name of the task being handled by GenerativeAgent. |
inputContext.inputVariables | object | Key-value pairs of input variables used in the conversation. |
inputContext.inputVariables.name | string | The unique identifier for the customer. |
type | string | The type of transfer, which is “PHONE_NUMBER” for this integration. |
phoneNumber | object | The phone number details for the transfer. |
phoneNumber.country | string | The country code for the phone number, e.g., “US”. |
phoneNumber.transferNumber | string | The E.164 formatted PSTN number assigned to transfer the call by ASAPP. |
| Status | Description |
|---|---|
ACTIVE | The call transfer is currently active and the temporary number is waiting to be connected. |
ONGOING | The call transfer is in progress and the GenerativeAgent is still handling the call. |
COMPLETED | The call transfer has been completed successfully. |
EXPIRED | The call transfer has expired and the temporary number is no longer valid. |
| Field | Type | Description |
|---|---|---|
transferType | string | The type of transfer. This can either be SYSTEM or AGENT. |
currentTaskName | string | The name of the current task being handled by GenerativeAgent. |
referenceVariables | object | Key-value pairs of reference variables used in the conversation. |
transferVariables | object | Key-value pairs of transfer variables used in the conversation. |
You can have the metrics, logging, redundancy, warm starts, and other settings configured as per your specific requirements, environment, and uses cases.
Step 2: Add your Lambda Functions to your Amazon Connect instance
The Lambda function must be added to your Amazon Connect instance to be used in the contact flow. To do this:- Open the Amazon Connect console.
- Select your Amazon Connect instance.
- In the left navigation pane, choose Contact flows.
- Choose AWS Lambda functions from the dropdown menu.
- Click Add Lambda function.
- Select the Lambda function
call-transferyou created earlier. - Click Add.
- Repeat the process for the
get-call-contextLambda function.
Step 3: Set Up Flow in Amazon Connect
1
Create Call Transfer Record
To createa a Call Transfer record in your Amazon Connect contact flow, you need to reference the
call-transfer Lambda function:- In the Amazon Connect console, open your contact flow.
- Add an Invoke AWS Lambda function block at the point where you want to initiate the transfer.
- Select the
call-transferLambda function. - Map any required parameters (such as
taskNameorcustomerId) in the block’s configuration. - Use the output variable
transferNumberfrom the Lambda function as the destination number in a Transfer to phone number block. - Check for failure scenarios and handle errors appropriately.
- Connect the blocks to complete the flow.
2
Transfer Call to GenerativeAgent
- Go to “Transfer to phone number” block and navigate to the Properties panel.
- Set the Transfer Via to “Phone number”.
- Under Phone number, select Set Dynamically.
- The Namespace must be set to
External. - The Key must be set to
transferNumber. - Set Resume Flow after Disconnect to Yes.
- Connect the output of this block to the next step in your flow.
3
Retrieve Call Context After Transfer Back
- Add another Invoke AWS Lambda function block after the transfer block.
- Select the
get-call-contextLambda function. - Map the
ContactIdfrom the Amazon Connect flow to the Lambda function input. - Use the output variable
outputContextfrom the Lambda function to determine the next steps. - Connect the output of this block to the next step in your flow.
4
Handle Call Context
- Use the output context from the
get-call-contextLambda function to determine the next steps in your flow. - Based on the following fields in the output context, you can decide how to proceed:
- Transfer Type: If it is
AGENT, you can transfer the call to a human agent. If it isSYSTEM, you can trnasfer the call back to the IVR. - Current Task Name: If it matches a specific task, you can route the call accordingly.
- Reference Variables: Use these variables to provide additional context or information to the customer.
- Transfer Variables: Use these variables to handle any specific transfer logic.
- Transfer Type: If it is
Next Steps
Now that you have integrated GenerativeAgent with Amazon Connect, here are some important next steps to consider:Configuration Overview
Learn how to configure GenerativeAgent’s behaviors, tasks, and communication style
Connect your APIs
Configure your APIs to allow GenerativeAgent to access necessary data and perform actions
Review Knowledge Base
Connect and optimize your knowledge base to improve GenerativeAgent’s responses
Go Live
Follow the deployment checklist to launch GenerativeAgent in your production environment