- For generating AWS Access keys follow this->https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html
- For generating Google API keys follow this->README
- For generating Airtable API keys follow this->README
-
Login to AWS platform(https://aws.amazon.com/console/)
-
Firstly we will created a Lambda function that our agent will use to generate the output. Search Lambda in the AWS search bar. Click on the create function
-
Create the name of the lambda function, then select Python 3.11 as the runtime. Click on create function
-
Next step Go to the Lambda->Configuration->Permission Click Add Permissions Specify a statement id.(It can be anything that you want it to be.) Specify the principle as bedrock.amazonaws.com Select lambda:InvokeFunction from the Action Dropdown. Click on Save
Go to Configuration->General Configuration. Click on Edit.
Change the Timeout value to 1 min and hit save.
-
Go to Configurations->Environment Variables
Click on Edit to add environment variables. Here you can store your API keys that you generated for Airtable and Google, for the lambda function to access.
Save the Airtable API as
AIRTABLE_API_KEY
AND Google API key asGOOGLE_API
-
Click on Deploy.
-
Now we need to upload the OpenAPI spec in the S3 bucket. Search for S3 in the search bar. Click on the Create bucket option.
-
Give the name for the bucket. Give the Object Owner as ACL enabled, with Bucket owner preferred. Click on the Create Bucket option.
-
Now go back to the Bucket list page and click on the bucket that you just created Click the upload option to upload the Open API spec. Upload the lead_generation.json file here.
-
Now we create the agent. Search AWS bedrock and select the agents option.
-
Click on the create agents option Specify the Agent name and the description (Note: you can find the descriptions in the agents_description.txt file in this directory.) You can create the IAM permission automatically for new user, or use an existing IAM permission if available. Click Next.
-
Select model from the drop down and give the descriptions Description for claude:
You are a solar panel financial advisor, your job is to extract address and monthly bills for calling functions to calculate solar potential. You also are a solar panel lead generation employee, your job is to extract personal details like name, phone number and address for returning as response for calling functions to generate leads. Strictly respond to the question for calling the function that is required to answer. While returning the summarized solar potential calculation, the assistant should add a statement in the end as "Please provide you name and phone number for contacting you". If the user provides the name, address and phone number, extract them for creating leads.
-
Create an action group. Give the action group name. Select the lambda function created earlier from the drop down menu. Select the file from the Browse option for S3. Click on the bucket then the Open API .json file inside it. Click on Choose then click on next.
-
Knowledge base is optional, it uses Open Search service of AWS and might charge for the uses, or you can just skip it.
Our Agent is now fully setup and can be used with functionalities such as creating data entries and generating solar potential through google apis.
Now you are ready to use the agents.
Once an agent is created in the AWS Bedrock console, it can be accessed through python using the agent ID and agent alias ID.
Here is an example of an agent already created and existing in AWS Bedrock.
In this case lead_gen is the agent that is already created and existing in AWS Bedrock. We need its agentId and aliasId. Now we can invoke this agent as such:
The response contains completion message as event byte chunks. (This is the message from the agents)
Now, creating a new agent using python. You must retrieve the agentResourceRoleArn
from the AWS platform:
-
Go to AWS console and search for 'IAM'-> Go to roles in the Side panel
-
Your IAM role will be present here, with a prefix 'AmazonBedrockExecutionRoleForAgents_', Click on the role and copy its ARN.
Now paste the ARN in the code while creating an agent.
aws_agent = bedrock_agent.create_agent(
agentName='Lead_gen_notebook',
description='Extract name, phone number and address for lead generation. Or extract address and monthly bill for calculating solar potential',
foundationModel='anthropic.claude-v2',
instruction="""You are a solar panel financial advisor, your job is to extract address and monthly bills for calling functions to calculate solar potential. You also are a solar panel lead generation employee, your job is to extract personal details like name, phone number and address for returning as response for calling functions to generate leads. Strictly respond to the question for calling the function that is required to answer.""",
agentResourceRoleArn='arn:aws:iam::674564987265:role/service-role/AmazonBedrockExecutionRoleForAgents_KT4F6CHPJV'
)
This will create a new agent in our AWS bedrock as Lead_gen_notebook
Then we give this agent an action group that stores our S3 bucket and Lambda Function informations
#Creating the action group for the agent
response = bedrock_agent.create_agent_action_group(
agentId=aws_agent['agent'].get('agentId'),
agentVersion="DRAFT",
actionGroupName='LeadGenAction',
actionGroupExecutor={
'lambda': 'arn:aws:lambda:us-east-1:674564987265:function:lead_gen_solar'
},
apiSchema={
's3': {
's3BucketName': 'legalgraphbucket',
's3ObjectKey': 'lead_generation.json'
}
},
actionGroupState='ENABLED'
)
After this we give an alias to the agent while passing the agent id
# Creating the alias
agent_alias = bedrock_agent.create_agent_alias(
agentId=aws_agent['agent'].get('agentId'),
agentAliasName='Dummy',
)
Now the process of Agent creation with minimal configuration is done and ready to be invoked as done earlier.
At the bottom right of the agent screen you will find a place to enter your message for the agent
Example Question:
- Calculate solar potential for 9813 Sherborne Ave, Bakersfield, CA 93311, USA with monthly bill as 300 USD
- Create a Lead for Jhon Doe, California, 336-2126-7543