1. Building generative AI applications with Amazon
Bedrock using agents
1.1 Introduction
This workshop details the setup process of an application that will use an agent on
Amazon Bedrock. This will include setting up Amazon S3 buckets, a knowledge
base, action group, AWS Lambda function, and an Amazon EC2 instance within an
AWS environment. We will use the Streamlit framework for the user
interface(Optional). The agent is designed to create an ROI company portfolio
automatically. We will also create Q&A capability by setting up an internal knowledge
base that references several open committee meeting reports. This workshop will
also provide partial functionality for a send email capability, but will not be fully
enabled. This is to simply show the art of the possible.
1.2 Intended Audience
This workshop is intended for the following audiences:
o
Solution Architects
o
Software Development Engineers
o
Generative AI enthusiasts
1.3 Prerequisites
You will need an active AWS Account.
Familiarity with AWS services like Amazon Bedrock, Amazon S3, AWS
Lambda, and Amazon EC2.
This workshop will take about 2 hours to complete
For the purpose of this workshop and included code, the preferred region
is us-west-2. If you need to run this workshop in another region, you will need
to modify the region accordingly at a later step.
1.4 Workshop Structure
There are 6 modules in this workshop:
o
[Type here]
Setup Amazon S3 buckets
[Type here]
Mitra, Sumit | RSI
o
Setup AWS Lambda function
o
Setup agent and Action group
o
Setup Knowledge base with Amazon Bedrock agent
o
Testing the Setup
o
Setup User interface (Optional)
Introduction
This workshop details the setup process of an application that will use an agent on
Amazon Bedrock. In an AWS environment, you will be setting up S3 buckets, a
knowledge base, action group, Lambda function, and an EC2 instance(optional). We
will use the Streamlit framework for the user interface. The agent is designed to
dynamically create a top profit company portfolio based on specific parameters, and
providing a Q&A capability for Federal Open Market Committee reports. This
workshop will also include a send email method, but will not be enabled. Below is a
diagram of what we will be building out.
1.5 Architecture
[Type here]
[Type here]
Mitra, Sumit | RSI
The AWS Services that are used in this workshop are:
Amazon Bedrock is a comprehensive, serverless service that simplifies the
development of generative AI applications by providing access to top-tier
[Type here]
[Type here]
Mitra, Sumit | RSI
foundation models from leading AI companies through a single API, along with
customization options and seamless integration with familiar AWS services.
Amazon S3 (Simple Storage Service) offers scalable object storage for data
backup, archival, and analytics, with 99.999999999% (11 9's) of durability and
stores data for millions of applications.
AWS Lambda lets you run code without provisioning or managing servers.
You pay only for the compute time you consume, making it a cost-effective
solution to run code in response to HTTP requests via Amazon API Gateway,
event triggers, or direct calls.
Amazon OpenSearch Serverless is a scalable and fully managed service for
deploying, operating, and scaling OpenSearch clusters in the AWS Cloud.
Amazon EC2 Instance is a resizable virtual server in the cloud that provides
secure and scalable compute capacity. You can run various workloads on
EC2 instances, ranging from small-scale applications to large-scale
distributed systems. EC2 gives you full control over your compute resources
and allows you to scale up or down as your needs change. It supports
multiple operating systems and is tightly integrated with other AWS services,
making it a versatile option for deploying applications in the cloud.
AWS CloudFormation template is a JSON or YAML formatted text file that
defines the infrastructure and resources you want to provision in AWS. With
CloudFormation, you can model and set up your AWS resources so that you
can spend less time managing those resources and more time focusing on
your applications. It allows you to automate the creation and management of
your AWS environment, ensuring consistent and repeatable deployment of
infrastructure across multiple regions and accounts.
Cloud native projects and other tools we will be using are:
Streamlit Framework is an open-source Python library that makes it easy to
create and share custom UIs.
1.6 Core Concepts
In this section, we will explore two key concepts that underpin many modern
generative AI applications: Large Language Model (LLM) Agents and Retrieval
Augmented Generation (RAG). These concepts enable LLMs to leverage external
knowledge and capabilities, enhancing their performance and expanding the range
of tasks they can tackle.
[Type here]
[Type here]
Mitra, Sumit | RSI
1.7 Large Language Model (LLM) Agents
At the core of many modern generative AI applications are Large Language Models
(LLMs), which are powerful natural language processing models trained on vast
amounts of text data. These LLMs can understand and generate human-like text,
making them suitable for a wide range of applications such as chatbots, content
generation, and question-answering systems.
However, LLMs alone are not always sufficient for more complex tasks that require
external information or capabilities beyond text generation. This is where LLM agents
come into play. An LLM agent is an architecture that combines an LLM with other
components, allowing the LLM to interact with and leverage these external
resources.
The key idea behind LLM agents is to enable the LLM to call or invoke other
components, such as APIs, databases, or specialized models, as needed during the
task execution. This allows the LLM to augment its capabilities and access
information beyond what is contained in its training data.
Benefits and Use Cases of LLM Agents
Expanded Knowledge and Capabilities: By integrating with external
resources, LLM agents can access up-to-date information, specialized
knowledge bases, or perform complex calculations, extending the capabilities
of the LLM beyond its initial training data.
Context-aware Responses: LLM agents can leverage contextual information
from external sources to provide more relevant and tailored responses,
improving the overall user experience.
Task Automation: LLM agents can be used to automate various tasks by
combining the LLM's natural language understanding with external
components for data retrieval, analysis, or execution of actions.
Multi-modal Interaction: LLM agents can be integrated with other modalities
like vision, speech, or robotics, enabling multi-modal applications such as
virtual assistants or embodied AI systems.
Example: LLM Agent for Travel Planning
Consider a travel planning application built using an LLM agent. The LLM component
would handle natural language interaction with the user, understanding their travel
preferences and requirements. However, to provide accurate and up-to-date
information, the LLM agent would integrate with various external components:
Flight API: To retrieve flight information and pricing from airline databases.
[Type here]
[Type here]
Mitra, Sumit | RSI
Hotel API: To search for and book hotel accommodations based on the user's
preferences.
Weather API: To provide weather forecasts for the travel destinations.
Translation Model: To translate text between languages if needed for
international travel.
By leveraging these external components, the LLM agent can provide a
comprehensive travel planning experience, answering queries, making
recommendations, and even booking travel arrangements based on the user's
natural language input and preferences.
1.8 Retrieval Augmented Generation (RAG)
Retrieval Augmented Generation (RAG) is a technique used in LLM-based
applications to enhance the generation capabilities of the LLM by incorporating
external knowledge from a retrieval system.
The core idea behind RAG is to combine the generative power of an LLM with the
ability to retrieve relevant information from a knowledge base or corpus. This
approach aims to address the limitations of LLMs, which can sometimes generate
hallucinated or factually incorrect responses due to their limited training data.
How RAG Works
Retrieval: Given an input query or context, a retrieval system (e.g., a search
engine or a dense retrieval model) is used to retrieve relevant documents or
passages from a knowledge base or corpus.
Augmentation: The retrieved information is then combined with the original
input and fed into the LLM as additional context.
Generation: The LLM generates an output based on the augmented input,
leveraging both its language understanding capabilities and the retrieved
knowledge.
Benefits and Use Cases of RAG
Improved Factual Accuracy: By incorporating external knowledge from trusted
sources, RAG can improve the factual accuracy of the LLM's generated
responses, reducing the risk of hallucinations or incorrect information.
Knowledge-grounded Generation: RAG allows the LLM to generate outputs
that are grounded in external k nowledge, making it suitable for applications
[Type here]
[Type here]
Mitra, Sumit | RSI
that require factual or evidence-based responses, such as questionanswering systems or research assistants.
Dynamic Knowledge Integration: RAG can dynamically integrate knowledge
from various sources, enabling the LLM to adapt to new domains or topics
without the need for extensive retraining.
Open-ended Generation: While traditional retrieval systems simply return
relevant documents, RAG leverages the LLM's generative capabilities to
produce novel and coherent responses based on the retrieved information.
Example: RAG-based Question-Answering System
Consider a question-answering system built using the RAG approach. When a user
submits a query, the retrieval component searches through a knowledge base (e.g.,
Wikipedia) and retrieves relevant articles or passages related to the query.
These retrieved documents are then combined with the original query and fed into
the LLM. The LLM generates a response by synthesizing the relevant information
from the retrieved documents, providing a coherent and informative answer to the
user's question.
By incorporating external knowledge from trusted sources, the RAG-based questionanswering system can provide more accurate and factual responses, while still
leveraging the LLM's natural language generation capabilities to produce human-like
and context-aware outputs.
1.9 Storyline
1.9.1
The Unseen Opportunity: A Journey of Innovation and Insight
[Type here]
[Type here]
Mitra, Sumit | RSI
Setting the Scene: In the bustling city of New York, amidst towering skyscrapers and
the constant hum of commerce, there lies a small yet innovative investment
startup, AnyCompany Portfolios Inc. The team is diverse, passionate, and driven
by the belief that technology can unlock untapped potential in the world of finance
and business intelligence.
The Problem: Despite the advancements in technology, the startup notices a
significant gap in the market. Financial analysts and investors spend countless hours
manually researching companies, often relying on outdated or superficial data. This
tedious process not only limits the potential of creating high value investment
portfolios, but also leaves smaller, yet promising companies overshadowed by
industry giants.
The Inspiration: The team realizes that there is a wealth of proprietary data – a
treasure trove of insights and opportunities – that remains largely untapped. They
[Type here]
[Type here]
Mitra, Sumit | RSI
envision a GenerativeAI application that can shift through this data, identifying key
patterns and profitable trends invisible to the human eye.
The Challenge: However, the journey isn't straightforward. Developing a Generative
AI application capable of handling text summarazation, chatbot with proprietary data,
and dynamically create investment company portfolios requires innovative thinking,
and a deep understanding of both technology and finance.
The Solution: The team starts building an application that can not only analyze vast
amounts of company data, but also able to search through dozens of ingested
Federal Open Market Committee reports to identify top company profit earners. This
allows for a nuanced understanding of the market dynamics and more informed
decision-making.
The Impact: The application revolutionizes the way investors and analysts approach
company research and analysis. No longer confined to traditional methods, they can
now access deeper insights, discover hidden gems in the market, and make more
strategic investment decisions faster than ever before.
The Invitation: And now, we invite you to be a part of this groundbreaking journey.
Through our workshop, you'll learn how to harness the power of agents in Amazon
Bedrock in transforming data into opportunities, shaping the future of financial
analysis and investment!
Login to AWS console
This workshop creates an AWS account. You will need the AWS Account Login
URL provided by the workshop facilitators.
STEPS
1. Connect to the workshop by browsing to https://catalog.us-east1.prod.workshops.aws/join?access-code= <ReplacewithAccessCode> The
following screen shows up where you will need to specify the event access
code.
[Type here]
[Type here]
Mitra, Sumit | RSI
2. Click Next.
3. Click on Email One-Time Password (OTP).
4. Enter Email (company email address) and click Send passcode.
5. It may take a few minutes to receive your passcode through your email. Enter
the passcode and click Sign in.
6. This should redirect you to the Terms and Conditions. Click on the box to
agree and Click Join event.
[Type here]
[Type here]
Mitra, Sumit | RSI
7. This will take you to the workshop instructions page. On the bottom right
corner of this screen click on Open AWS Console. This will open AWS
Console in a new browser tab.
8. At the end of this workshop, if you are using your own AWS account, clean
up your resources so you don't get charged.
[Type here]
[Type here]
Mitra, Sumit | RSI
2. Module 1 - Setup Amazon S3 Buckets and
Knowledge base
2.1 Configuration and Setup
You will now be setting up the S3 buckets and Knowledge base.
Creating S3 Buckets
2.2 Setup S3 and load files
Domain Data Bucket: Navigate to the Amazon S3 console and create an S3
bucket. Use the default settings. This S3 bucket will be used to store the
domain data that the Agent will later use to answer domain specific questions.
Call the S3 bucket knowledgebase-bedrock-agent-{alias}. We will use the
default settings.
Make sure to update {alias} with the appropriate value throughout this workshop.
Next, we will download the SEC reports of several months, then store them in
an S3 bucket for our knowledge base. Select each button below to view, then
download the documents:
Download data (02-23)
Download data (03-23)
[Type here]
[Type here]
Mitra, Sumit | RSI
Download data (06-23)
Download data (07-23)
Download data (09-23)
Download data (11-23)
Upload these files to S3 bucket knowledgebase-bedrock-agent-{alias}. These
files are the Federal Open Market Committee documents describing monetary
policy decisions made at the Federal Reserved board meetings. The
documents include discussions of economic conditions, policy directives to
the Federal Reserve Bank of New York for open market operations, and votes
on the federal funds rate. More information can be found here . Once
uploaded, please select one of the documents to open and review the
content.
Now, the team at AnyCompany Portfolios are looking optimistic! But still wondering if
this is to good to be true. "I wonder if we will still have to analyze all of these
documents to gather enough information to create an investment company portfolio
for our clients" they ask themselves..
2.3 Grant model access & Setup Knowledge base
[Type here]
[Type here]
Mitra, Sumit | RSI
Grant model access and create KB
Before we setup the knowledge base, we will need to grant access to the
models that will be needed for our agent in Bedrock. Navigate to the Amazon
Bedrock console. On the left of the screen, scroll down to Bedrock
configurations and select Model access. On the right, select the Enable
specific models button.
Select the checkbox for the base model columns Amazon: Titan
Embeddings G1 - Text (If not already granted) and Anthropic: Claude 3
Haiku. This will provide you access to the required models. After, scroll down
to the bottom right and select Request model access.
Gaining access to both models can take a few minutes.
After, verify that the access status of the models is green with Access
granted.
[Type here]
[Type here]
Mitra, Sumit | RSI
Now, we will create a knowledge base by selecting Knowledge base on the
left under Builder tools. Then, the orange button Create knowledge base.
You can use the default name, or enter in your own. Then, select Next at the
bottom right of the screen.
[Type here]
[Type here]
Mitra, Sumit | RSI
Sync S3 bucket knowledgebase-bedrock-agent-{alias} to this knowledge
base.
For the embedding model, choose Titan Text Embeddings V2. Leave the
other options as default, and scroll down to select Next.
[Type here]
[Type here]
Mitra, Sumit | RSI
On the next screen, review your work, then select Create knowledge base
Scroll to the top, and you should see a blue banner saying the vector
database is being prepared. When complete, you will see a green message
saying the setup was successful, similar to below:
Do not move on to the next step or leave this screen until the knowledge base is
complete.
[Type here]
[Type here]
Mitra, Sumit | RSI
Next, scroll down to the Data source section, select your knowledge base,
then *Sync the data. You will see another blue banner at the top saying that
your data is being
synced.
Do not move on to the next step until you see a green banner at the top saying that
the sync is complete
[Type here]
[Type here]
Mitra, Sumit | RSI
"Wow! that was easy enough. I wonder what the catch is" the team asks themselves.
With AnyCompany Portfolios being new to Generative AI, they are wondering if they
have enough skills to build this workload out.
[Type here]
[Type here]
Mitra, Sumit | RSI
3. Module 2 - Setup AWS Lambda function
3.1 Configuration and setup
Now, it is time to create the Lambda function that will be able to query relevant data.
Lambda Function Configuration
3.2 Create an AWS Lambda function for the Action group
Create a Lambda function (Python 3.12) for the Bedrock agent's action group.
We will call this Lambda function PortfolioCreator-actions. We are creating
this function for an action group in order to carry out various tasks.
The Lambda function serves as a backend API for the AI agent that will be
created to access and retrieve company-related data. It provides the following
functionality:
Company Research: Allows the AI agent to search for a specific company by
name and retrieve its details.
Portfolio Creation: Enables the AI agent to create a portfolio of top-performing
companies within a specified industry sector. The agent can specify the number
of companies to include in the portfolio, and the function will return the top
companies sorted by profit in descending order.
[Type here]
[Type here]
Mitra, Sumit | RSI
Email Sending: Allows the AI agent to simulate sending an email containing a
portfolio summary to a specified email address.
The Lambda function uses predefined mock data for demonstration purposes.
It parses the incoming API requests, routes them to the appropriate handler
functions, and returns the response in a structured format.
Copy the python code provided below, or from the file here into your Lambda
function.
import json
def lambda_handler(event, context):
print(event)
# Mock data for demonstration purposes
company_data = [
#Technology Industry
{"companyId": 1, "companyName": "TechStashNova Inc.",
"industrySector": "Technology", "revenue": 10000, "expenses": 3000,
"profit": 7000, "employees": 10},
{"companyId": 2, "companyName": "QuantumPirateLeap
Technologies", "industrySector": "Technology", "revenue": 20000,
"expenses": 4000, "profit": 16000, "employees": 10},
{"companyId": 3, "companyName": "CyberCipherSecure IT",
"industrySector": "Technology", "revenue": 30000, "expenses": 5000,
"profit": 25000, "employees": 10},
{"companyId": 4, "companyName": "DigitalMyricalDreams Gaming",
"industrySector": "Technology", "revenue": 40000, "expenses": 6000,
"profit": 34000, "employees": 10},
{"companyId": 5, "companyName": "NanoMedNoLand
Pharmaceuticals", "industrySector": "Technology", "revenue": 50000,
"expenses": 7000, "profit": 43000, "employees": 10},
{"companyId": 6, "companyName": "RoboSuperBombTech Industries",
"industrySector": "Technology", "revenue": 60000, "expenses": 8000,
"profit": 52000, "employees": 12},
[Type here]
[Type here]
Mitra, Sumit | RSI
{"companyId": 7, "companyName": "FuturePastNet Solutions",
"industrySector": "Technology", "revenue": 60000, "expenses": 9000,
"profit": 51000, "employees": 10},
{"companyId": 8, "companyName": "InnovativeCreativeAI Corp",
"industrySector": "Technology", "revenue": 65000, "expenses": 10000,
"profit": 55000, "employees": 15},
{"companyId": 9, "companyName": "EcoLeekoTech Energy",
"industrySector": "Technology", "revenue": 70000, "expenses": 11000,
"profit": 59000, "employees": 10},
{"companyId": 10, "companyName": "TechyWealthHealth Systems",
"industrySector": "Technology", "revenue": 80000, "expenses": 12000,
"profit": 68000, "employees": 10},
#Real Estate Industry
{"companyId": 11, "companyName": "LuxuryToNiceLiving Real
Estate", "industrySector": "Real Estate", "revenue": 90000, "expenses":
13000, "profit": 77000, "employees": 10},
{"companyId": 12, "companyName": "UrbanTurbanDevelopers Inc.",
"industrySector": "Real Estate", "revenue": 100000, "expenses": 14000,
"profit": 86000, "employees": 10},
{"companyId": 13, "companyName": "SkyLowHigh Towers",
"industrySector": "Real Estate", "revenue": 110000, "expenses": 15000,
"profit": 95000, "employees": 18},
{"companyId": 14, "companyName": "GreenBrownSpace Properties",
"industrySector": "Real Estate", "revenue": 120000, "expenses": 16000,
"profit": 104000, "employees": 10},
{"companyId": 15, "companyName": "ModernFutureHomes Ltd.",
"industrySector": "Real Estate", "revenue": 130000, "expenses": 17000,
"profit": 113000, "employees": 10},
{"companyId": 16, "companyName": "CityCountycape Estates",
"industrySector": "Real Estate", "revenue": 140000, "expenses": 18000,
"profit": 122000, "employees": 10},
{"companyId": 17, "companyName": "CoastalFocalRealty Group",
"industrySector": "Real Estate", "revenue": 150000, "expenses": 19000,
"profit": 131000, "employees": 10},
[Type here]
[Type here]
Mitra, Sumit | RSI
{"companyId": 18, "companyName": "InnovativeModernLiving
Spaces", "industrySector": "Real Estate", "revenue": 160000, "expenses":
20000, "profit": 140000, "employees": 10},
{"companyId": 19, "companyName": "GlobalRegional Properties
Alliance", "industrySector": "Real Estate", "revenue": 170000, "expenses":
21000, "profit": 149000, "employees": 11},
{"companyId": 20, "companyName": "NextGenPast Residences",
"industrySector": "Real Estate", "revenue": 180000, "expenses": 22000,
"profit": 158000, "employees": 260}
]
def get_named_parameter(event, name):
'''Function searches through the parameters list in the event dictionary
and returns the value of the parameter whose name matches the provided
name string'''
return next(item for item in event['parameters'] if item['name'] ==
name)['value']
def companyResearch(event):
'''Searches for a company based on the 'name' parameter in the
lambda event and returns its information if found.'''
companyName = get_named_parameter(event, 'name').lower()
print("NAME PRINTED: ", companyName)
for company_info in company_data:
if company_info["companyName"].lower() == companyName:
return company_info
return None
def createPortfolio(event, company_data):
[Type here]
[Type here]
Mitra, Sumit | RSI
'''Creates a portfolio of top companies based on the 'numCompanies'
and 'industry' parameters in the lambda event.'''
numCompanies = int(get_named_parameter(event, 'numCompanies'))
industry = get_named_parameter(event, 'industry').lower()
industry_filtered_companies = [company for company in
company_data
if company['industrySector'].lower() == industry]
sorted_companies = sorted(industry_filtered_companies, key=lambda
x: x['profit'], reverse=True)
top_companies = sorted_companies[:numCompanies]
return top_companies
def sendEmail(event, company_data):
'''Prepares and sends an email with a summary report and portfolio
details based on parameters in the lambda event.'''
emailAddress = get_named_parameter(event, 'emailAddress')
fomcSummary = get_named_parameter(event, 'fomcSummary')
# Retrieve the portfolio data as a string
portfolioDataString = get_named_parameter(event, 'portfolio')
# Prepare the email content
[Type here]
[Type here]
Mitra, Sumit | RSI
email_subject = "Company Portfolio and Search Results Summary
Report"
#email_body = f"Search Summary
Report:\n{fomcSummary}\n\nPortfolio Details:\n{json.dumps(portfolioData,
indent=4)}"
# Email sending code here (commented out for now)
return "Email sent successfully to {}".format(emailAddress)
result = ''
response_code = 200
action_group = event['actionGroup']
api_path = event['apiPath']
print("api_path: ", api_path )
if api_path == '/companyResearch':
result = companyResearch(event)
elif api_path == '/createPortfolio':
result = createPortfolio(event, company_data)
elif api_path == '/sendEmail':
result = sendEmail(event, company_data)
else:
response_code = 404
result = f"Unrecognized api path: {action_group}::{api_path}"
response_body = {
'application/json': {
[Type here]
[Type here]
Mitra, Sumit | RSI
'body': result
}
}
action_response = {
'actionGroup': event['actionGroup'],
'apiPath': event['apiPath'],
'httpMethod': event['httpMethod'],
'httpStatusCode': response_code,
'responseBody': response_body
}
api_response = {'messageVersion': '1.0', 'response': action_response}
return api_response
Then, select Deploy in the tab section of the Lambda console. Review the
code provided before moving to the next step. You will see that we are using
mock data to represent various companies in the technology and real estate
industry, along with functions that we will call later in this workshop.
Next, apply a resource policy to the Lambda to grant Bedrock agent access.
To do this, we will switch the top tab from code to configuration and the side
tab to Permissions. Then, scroll to the Resource-based policy
statements section and click the Add permissions button.
[Type here]
[Type here]
Mitra, Sumit | RSI
Select AWS service, then use the following settings to configure the resource
based policy:
o
Service - Other
o
Statement ID - allow-bedrock-agent
o
Principal - bedrock.amazonaws.com
o
Source ARN - arn:aws:bedrock:us-west-2:{account-id}:agent/* (Please note, AWS recommends least privilage so only an allowed
agent can invoke this Lambda function. A * at the end of the ARN
grants any agent in the account access to invoke this Lambda. Ideally,
we would not use this in a production environment.)
o
Action - lambda:InvokeFunction
[Type here]
[Type here]
Mitra, Sumit | RSI
Now, the team at AnyCompany Portfolios is feeling really good that they are building
out the product that they envisioned!
4. Module 3 - Setup agent and Action group
4.1 Configuration and setup
We will now be configuring an agent with an Action group.
Setup Amazon Bedrock agent
[Type here]
[Type here]
Mitra, Sumit | RSI
4.2 Create an agent in Amazon Bedrock
Navigate to the Bedrock console. Go to the toggle on the left, and
under Builder tools select Agents. Provide an agent name,
like PortfolioCreator then create the
agent.
For agent details, the agent description is optional. We will use the default
new service role. For the model, select Anthropic: Claude 3 Haiku. Next,
provide the following instruction for the agent:
You are an investment analyst. Your job is to assist in investment analysis, create
research summaries, generate profitable company portfolios, and facilitate
communication through emails. Here is how I want you to think step by step:
1. Portfolio Creation:
Analyze the user's request to extract key information such as the desired number
of companies and industry.
Based on the criteria from the request, create a portfolio of companies. Use the
template provided to format the portfolio.
2. Company Research and Document Summarization:
For each company in the portfolio, conduct detailed research to gather relevant
financial and operational data.
When a document, like the FOMC report, is mentioned, retrieve the document and
provide a concise summary.
[Type here]
[Type here]
Mitra, Sumit | RSI
3. Email Communication:
Using the email template provided, format an email that includes the newly
created company portfolio and any summaries of important documents.
Utilize the provided tools to send an email upon request, That includes a summary
of provided responses and portfolios created.
After, scroll to the top and Save.
The instructions for the Generative AI Investment Analyst Tool outlines a
comprehensive framework designed to assist in investment analysis. This tool is
tasked with creating tailored portfolios of companies based on specific industry criteria,
conducting thorough research on these companies, and summarizing relevant
financial documents. Additionally, the tool formats and sends professional emails
containing the portfolios and document summaries. The process involves continuous
adaptation to user feedback and maintaining a contextual understanding of ongoing
requests to ensure accurate and efficient responses.
[Type here]
[Type here]
Mitra, Sumit | RSI
Next, we will add an action group. Scroll down to Action groups then
select Add.
Call the action group PortfolioCreator-actions. We will set the Action group
type to Define with API schemas.
Action group invocations should be set to select an existing Lambda
function. For the Lambda function, select PortfolioCreator-actions.
For the Action group Schema, we will choose Define via in-line schema
editor and switch to JSON. Replace the default schema in the In-line
OpenAPI schema editor with the schema provided below. You can also
retrieve the schema from the repo here . After, select Create. (This API
schema is needed so that the bedrock agent knows the format structure and
parameters needed for the action group to interact with the Lambda function.)
{
"openapi": "3.0.1",
"info": {
"title": "PortfolioCreatorAssistant API",
"description": "API for creating a company portfolio, search company data,
and send summarized emails",
"version": "1.0.0"
},
"paths": {
"/companyResearch": {
"post": {
"description": "Get financial data for a company by name",
"parameters": [
{
"name": "name",
"in": "query",
"description": "Name of the company to research",
"required": true,
"schema": {
"type": "string"
}
}
[Type here]
[Type here]
Mitra, Sumit | RSI
],
"responses": {
"200": {
"description": "Successful response with company data",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CompanyData"
}
}
}
}
}
}
},
"/createPortfolio": {
"post": {
"description": "Create a company portfolio of top profit earners by
specifying number of companies and industry",
"parameters": [
{
"name": "numCompanies",
"in": "query",
"description": "Number of companies to include in the portfolio",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
},
{
"name": "industry",
"in": "query",
"description": "Industry sector for the portfolio companies",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Successful response with generated portfolio",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Portfolio"
}
}
}
[Type here]
[Type here]
Mitra, Sumit | RSI
}
}
}
},
"/sendEmail": {
"post": {
"description": "Send an email with FOMC search summary and created
portfolio",
"parameters": [
{
"name": "emailAddress",
"in": "query",
"description": "Recipient's email address",
"required": true,
"schema": {
"type": "string",
"format": "email"
}
},
{
"name": "fomcSummary",
"in": "query",
"description": "Summary of FOMC search results",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "portfolio",
"in": "query",
"description": "Details of the created stock portfolio",
"required": true,
"schema": {
"$ref": "#/components/schemas/Portfolio"
}
}
],
"responses": {
"200": {
"description": "Email sent successfully",
"content": {
"text/plain": {
"schema": {
"type": "string",
"description": "Confirmation message"
}
}
}
}
[Type here]
[Type here]
Mitra, Sumit | RSI
}
}
}
},
"components": {
"schemas": {
"CompanyData": {
"type": "object",
"description": "Financial data for a single company",
"properties": {
"name": {
"type": "string",
"description": "Company name"
},
"expenses": {
"type": "string",
"description": "Annual expenses"
},
"revenue": {
"type": "number",
"description": "Annual revenue"
},
"profit": {
"type": "number",
"description": "Annual profit"
}
}
},
"Portfolio": {
"type": "object",
"description": "Stock portfolio with specified number of companies",
"properties": {
"companies": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CompanyData"
},
"description": "List of companies in the portfolio"
}
}
}
}
}
}
The results should look similar to the following:
[Type here]
[Type here]
Mitra, Sumit | RSI
This API schema defines three primary
endpoints, /companyResearch, /createPortfolio, and /sendEmail detailing how
to interact with the API, the required parameters, and the expected responses.
Now, we need to provide the Bedrock agent a prompt that are examples of a
formatted response for an investment company portfolio, and email. In the
creation of an agent, it's initially configured with four foundational prompt
templates for pre-processing, orchestration, knowledge base response
generation, and post-processing. These prompts guide how the agent
interacts with the foundation model across various steps of the process.
These templates are crucial for processing user inputs, orchestrating the flow
between the foundation model, action groups, and knowledge bases, as well
as formatting the responses sent to users. By customizing these templates
and incorporating advanced prompts or few-shot examples, you can
significantly improve the agent's precision and performance in handling
specific tasks. More information on advanced prompting for an agent can be
found here . Additionally, there is an option to use a custom parser Lambda
function for more granular formatting.
Scroll down to Advanced prompts and select Edit.
[Type here]
[Type here]
Mitra, Sumit | RSI
Select the Orchestration tab. Toggle on the radio button Override
orchestration template defaults. Make sure Activate orchestration
template is enabled as well.
In the Prompt template editor, scroll down to line 22-23, then copy/paste in
the following portfolio example and email format:
Here is an example of a company portfolio.
<portfolio_example>
Here is a portfolio of the top 3 real estate companies:
1. NextGenPast Residences with revenue of $180,000, expenses of $22,000
and profit of $158,000 employing 260 people.
2. GlobalRegional Properties Alliance with revenue of $170,000, expenses of
$21,000 and profit of $149,000 employing 11 people.
3. InnovativeModernLiving Spaces with revenue of $160,000, expenses of
$20,000 and profit of $140,000 employing 10 people.
</portfolio_example>
Here is an example of an email formatted.
<email_format>
Company Portfolio:
1. NextGenPast Residences with revenue of $180,000, expenses of $22,000
and profit of $158,000 employing 260 people.
2. GlobalRegional Properties Alliance with revenue of $170,000, expenses of
$21,000 and profit of $149,000 employing 11 people.
3. InnovativeModernLiving Spaces with revenue of $160,000, expenses of
$20,000 and profit of $140,000 employing 10 people.
FOMC Report:
Participants noted that recent indicators pointed to modest growth in spending
and production. Nonetheless, job gains had been robust in recent months, and
the unemployment rate remained low. Inflation had eased somewhat but
remained elevated.
Participants recognized that Russia’s war against Ukraine was causing
tremendous human and economic hardship and was contributing to elevated
[Type here]
[Type here]
Mitra, Sumit | RSI
global uncertainty. Against this background, participants continued to be highly
attentive to inflation risks.
</email_format>
The results should look similar to the following:
Scroll to the bottom and select the Save and exit button.
Now, check to confirm that the Orchestration in the Advance prompt section
is Overridden.
PLEASE NOTE: The default advanced prompts apply to Claude 3 Haiku, and it’s
likely to be different with other models (Claude v2.1, Claude Instant, etc.)
[Type here]
[Type here]
Mitra, Sumit | RSI
5. Module 4 - Sync Knowledge base with an agent on
Amazon Bedrock
5.1 Configuration and Setup
Lets now sync the Knowledge base with domain specific documents with the agent.
Sync knowledge base with Amazon Bedrock agent
Add instruction to the knowledge base
PLEASE NOTE: If you are not currently on the Bedrock agent console, navigate
back by selecting Agents under Builder Tools on the left side of the screen ->
select the agent created -> then select the orange button in the top right Edit in
Agent Builder.
[Type here]
[Type here]
Mitra, Sumit | RSI
While in edit mode on the Bedrock agent console, scroll down to Knowledge
base and select
Add.
When integrating the KB with the agent, you will need to provide basic
instructions on how to handle the knowledge base so the agent knows when
to leverage it. For example, use the following:
This knowledge base contains information for understanding data sets related to
economic trends, company financials, and policy decisions made during Federal
Open Market Committee meetings.
Review your input, then select Add.
Scroll to the top and select Save, then Prepare. Then select Save and exit.
"Hey look! we have another co-worker now. We'll call it Mr. Agent". The team joked
around, while suggesting just the right instructions to provide to the agent.
5.2 Create an alias
[Type here]
[Type here]
Mitra, Sumit | RSI
To create an alias, scroll down to the Alias section, then select Create.
Choose a name of your liking. After it's done, make sure to copy your Alias
ID after creation, along with the Agent ID at the top. You will need this in step
8 when setting up the user interface.
6. Module 5 - Testing the Setup
6.1 Configuration and Setup
[Type here]
[Type here]
Mitra, Sumit | RSI
6.1.1
Testing the Knowledge Base
While in the Amazon Bedrock console, select Knowledge base under
the Builder tools tab, then select the knowledge base you
created.
You will see a user interface on the right where you will need to select a
model. Choose the Anthropic Claude 3 Haiku model, then select Apply.
You can now enter prompts in the user interface provided.
[Type here]
[Type here]
Mitra, Sumit | RSI
[Type here]
[Type here]
Mitra, Sumit | RSI
Test Prompts:
o
Give me a summary of financial market developments and open
market operations in January 2023.
o
Can you provide information about inflation or rising prices?
o
What can you tell me about the Staff Review of the Economic &
Financial Situation.
6.2 Testing the agent
While in the Amazon Bedrock console, select Agents under
the Orchestration drop-down, then select the agent you created. Also, make
sure the agent has been Prepared. You should be able to enter prompts in
the user interface provided to test your knowledge base and action groups
from the agent.
[Type here]
[Type here]
Mitra, Sumit | RSI
Example Knowledge Base prompts:
o
Give me a summary of financial market developments and open
market operations in January 2023
o
Tell me the participants view on economic conditions
o
Provide any important information I should know about inflation, or
rising prices
[Type here]
[Type here]
Mitra, Sumit | RSI
o
Tell me about the Staff Review of the Economic & financial Situation
Example Action Groups prompts:
o
Create a portfolio with 3 companies in the real estate industry
o
Create portfolio of 3 companies that are in the technology industry
o
Create a new investment portfolio of companies
o
Do company research on TechStashNova Inc.
Example KB, AG, and history prompt:
o
Send an email to test@example.com that includes the company
portfolio and FOMC summary (The logic for this method is not
implemented to send emails)
"I can't believe it. We can search for specific data in the FOMC report and/or private
company data seamlessly!" They said. AnyCompany Portfolios began to rejoice as
they realized the searching and analyzing of economic and financial data has
evolved, and will save them several hours a day in labor.
[Type here]
[Type here]
Mitra, Sumit | RSI
7. Module 6 - Setup and Run Streamlit App on EC2
(Optional)
7.1 Configuration and Setup
Now, lets setup our Streamlit UI that will run on an ec2 instance.
Setup and Run Streamlit App on EC2 (Optional)
Obtain AWS CloudFormation template to launch the streamlit app: Download
the Cloudformation template from below:
Download CF Template
This template will be used to deploy an EC2 instance that will run the code for
the Streamlit UI.
Deploy template via AWS CloudFormation:
From the AWS mangement console, search for, then navigate to the AWS
CloudFormation service.
Create a stack with new resources (standard)
Prepare template: Choose existing template -> Specify template: Upload a
template file -> upload the template downloaded from the previous step.
[Type here]
[Type here]
Mitra, Sumit | RSI
Next, Provide a stack name like ec2-streamlit. Keep the instance type on the
default of t3.small, then go to Next.
On the Configure stack options screen, leave settings as default, then go
to Next.
Scroll down to the capabilities section, and acknowledge the warning
message before submitting.
Once the stack is complete, go to the next step.
[Type here]
[Type here]
Mitra, Sumit | RSI
Edit the app to update agent IDs:
Navigate to the EC2 instance management console. Under instances, you
should see EC2-Streamlit-App. Select the checkbox next to it, then connect to
it via EC2 Instance Connect.
Next, use the following command to edit the InvokeAgent.py file:
sudo vi app/streamlit_app/InvokeAgent.py
Press i to go into edit mode. Then, update the AGENT ID and Agent ALIAS
ID values.
[Type here]
[Type here]
Mitra, Sumit | RSI
After, hit Esc, then save the file changes with the following command:
1
:wq!
Now, start the streamlit app:
1
streamlit run app/streamlit_app/app.py
You should see an external URL. Copy & paste the URL into a web browser to
start the streamlit application.
Once the app is running, please test some of the sample prompts provided.
(On 1st try, if you receive an error, try again.)
[Type here]
[Type here]
Mitra, Sumit | RSI
Optionally, you can review the trace events in the left toggle of the screen.
This data will include the Preprocessing, Orchestration,
and PostProcessing traces.
[Type here]
[Type here]
Mitra, Sumit | RSI
"This is exactly what we were looking for!" The CEO of AnyCompany Portfolios said
as he continued asking the Generative AI application questions on months of FOMC
reports and top company profit earners before creating various company portfolios to
send out in email.
[Type here]
[Type here]
Mitra, Sumit | RSI
Summary
Overview: In this workshop, we embarked on an exciting journey to develop a
GenerativeAI application capable of conducting company research and creating
investment portfolios. Utilizing Amazon Bedrock and Streamlit, we achieved a
seamless integration of various AWS services, demonstrating the power of cloud
computing in the realm of financial analysis and decision-making.
Key Achievements:
Setting Up Amazon Bedrock Agent on AWS: We successfully established S3 buckets
for storing domain data and artifacts. A knowledge base was configured for our
Bedrock agent, integrating economic and financial data from FOMC documents. We
created and configured a Lambda function, "PortfolioCreator-actions," tailored for the
application's unique needs.
Building the Knowledge Base: Participants gained hands-on experience in setting up
and syncing a knowledge base with the Bedrock agent. We focused on leveraging
the Anthropic: Claude V1.2 model for intelligent data interpretation.
Configuring AWS Lambda Function: We delved into the intricacies of Python 3.12 to
craft a functional Lambda setup. The workshop provided insights into resource policy
application and Lambda function deployment.
Agent and Action Group Setup: The creation of the "PortfolioCreator" agent enabled
us to define operational rules and integrate the Lambda function. We highlighted the
process of creating an agent alias and implementing action groups for portfolio
creation, company research, and sending emails.
Practical Applications: Throughout the workshop, we emphasized practical
applications by: Testing the knowledge base and agent with real-world prompts.
Exploring scenarios like creating investment portfolios based on profit data and
conducting company-specific research.
Impact and Takeaways: The workshop not only equipped participants with the
technical know-how but also provided a broader understanding of how agents on
Amazon Bedrock can revolutionize financial analysis and investment strategies,
along with many other domains. This hands-on experience has laid a foundation for
innovative approaches in data-driven decision-making within the financial sector.
[Type here]
[Type here]
Mitra, Sumit | RSI
Cleanup
After completing the setup and testing of the Bedrock Agent and Streamlit app, follow
these steps to clean up your AWS environment and avoid unnecessary charges:
1. Delete S3 Buckets:
Navigate to the S3 console.
Select the buckets "knowledgebase-bedrock-agent-alias" and "artifactsbedrock-agent-creator-alias". Make sure that both of these buckets are empty
by deleting the files.
Choose 'Delete' and confirm by entering the bucket name.
2. Remove Lambda Function:
Go to the Lambda console.
elect the "PortfolioCreator-actions" function.
Click 'Delete' and confirm the action.
3. Delete Bedrock Agent:
In the Bedrock console, navigate to 'Agents'.
Select the created agent, then choose 'Delete'.
4. Deregister Knowledge Base in Bedrock:
Access the Bedrock console, then navigate to “Knowledge base” under the
Orchestration tab.
Select, then delete the created knowledge base.
5. Terminate EC2 Instance (if applicable):
Navigate to the EC2 management console.
Select the EC2 instance created, then Instance state -> Terminate instance.
[Type here]
[Type here]
Mitra, Sumit | RSI
8. Event: NAMER Tech Summit (Dallas)
Configuration and Setup
We will enable access to models, deploy resources, and create a knowledge base
Introduction
Introduction
Welcome! Thank you for attending this hands-on workshop. We will be discussing
how Large Language Models (LLMs) are powerful for text generation but often need
external data or capabilities for complex tasks. Amazon Bedrock agents combine
LLMs with components like APIs, databases, RAG, or specialized models to
enhance functionality. This workshop guides setting up an application with an agent
on Amazon Bedrock, using sample code in Streamlit for the interface. The scenario
involves a Fintech company scaling operations through automation to meet growing
economic demand.
Prerequisites
An active AWS Account.
Familiarity with AWS services like Amazon Bedrock, S3, Lambda, and
Serverless Application Model.
All models that you plan to test will need to be granted access via Amazon
Bedrock.
[Type here]
[Type here]
Mitra, Sumit | RSI
Key concepts
Amazon Bedrock
Amazon Bedrock is a fully managed service that offers a choice of industry
leading foundation models (FMs) along with a broad set of capabilities that
you need to build generative AI applications, simplifying development with
security, privacy, and responsible AI. With the comprehensive capabilities of
Amazon Bedrock, you can experiment with a variety of top FMs, customize
them privately with your data using techniques such as fine-tuning and
retrieval-augmented generation (RAG), and create managed agents that
execute complex business tasks—from booking travel and processing
insurance claims to creating ad campaigns and managing inventory—all
without writing any code. Since Amazon Bedrock is serverless, you don't have
to manage any infrastructure, and you can securely integrate and deploy
generative AI capabilities into your applications using the AWS services you
are already familiar with
Amazon Bedrock Agents
Agents for Amazon Bedrock is a fully managed service that enables
generative AI applications to execute multi-step tasks across an organization's
systems and data sources. You can create an agent in Amazon Bedrock in
just a few quick steps, accelerating the time it takes to build generative AI
capabilities into applications. Agents orchestrate and analyze the task and
break it down into the correct logical sequence using the FM’s reasoning
abilities. Agents can automatically call the necessary functions or knowledge
bases to transact with the organization's systems and processes to fulfill the
request, determining along the way if they can proceed or if they need to
gather more information. Alternatively, the developer can choose to return the
control of the functions execution to the application and handle the function
invocations within the application.
Diagram
[Type here]
[Type here]
Mitra, Sumit | RSI
Overview
[Type here]
[Type here]
Mitra, Sumit | RSI
Overview:
In the fast-paced world of finance, AnyCompany Portfolios Inc., a small yet
innovative investment startup based in New York, is on a mission to
revolutionize the investment landscape. Despite its size, the team is driven by
a bold vision – using technology to unlock hidden potential in financial data
and create high-value investment portfolios. However, traditional methods of
researching companies remain labor-intensive, inefficient, and often rely on
outdated information. To solve this problem, the team is setting their sights on
a cutting-edge Generative AI application designed to transform how financial
analysts and investors approach market research, enabling more informed
and strategic decision-making.
Use Case:
Imagine a financial analyst tasked with identifying top-performing companies
in the tech sector. Using AnyCompany’s Generative AI application, the analyst
can access a chatbot interface to interact with proprietary company data and
FOMC reports. Within moments, the AI system analyzes the data, highlights
the top profit earners, and creates an optimized investment portfolio. The AI’s
ability to uncover hidden patterns and trends empowers analysts to act quickly
and make more strategic, data-backed decisions. This approach not only
reduces research time but also opens up new opportunities to invest in
smaller companies that would have otherwise gone unnoticed.
Through this solution, AnyCompany Portfolios Inc. is transforming how
investment portfolios are created, enabling their clients to remain ahead of the
market curve with the power of AI-driven financial insights.
Problem:
Manual research processes consume countless hours of analysts' time.
Investors often rely on outdated or superficial data to make decisions.
Traditional methods limit the ability to create high-value, data-driven
investment portfolios.
A vast amount of proprietary data remains untapped, preventing deeper
market insights.
Proposed Solution:
The team proposes the development of a Generative AI application capable of
ingesting and analyzing proprietary data, alongside external market reports
such as Federal Open Market Committee (FOMC) publications. The solution
will combine the power of AI for text summarization and a chatbot to
dynamically create investment portfolios tailored to user queries. With this AIdriven approach, the application will identify key patterns and trends in real-
[Type here]
[Type here]
Mitra, Sumit | RSI
time, providing analysts and investors with deeper, previously inaccessible
insights into companies, enabling them to discover hidden market
opportunities.
Key components of the solution include:
Text summarization for analyzing vast amounts of company data.
A chatbot that interacts with proprietary financial data and external reports.
Dynamic portfolio generation based on real-time analysis of market dynamics
and company performance.
Send emails of summarized searched reports, and company portfolio created.
Architecture
This workshop details the setup process of an application that will use an agent on
Amazon Bedrock. In an AWS environment, you will be setting up S3 buckets, a
knowledge base, action group, Lambda function, and an EC2 instance(optional). We
[Type here]
[Type here]
Mitra, Sumit | RSI
will use the Streamlit framework for the user interface. The agent is designed to
dynamically create a top profit company portfolio based on specific parameters, and
providing a Q&A capability for Federal Open Market Committee reports. This
workshop will also include a send email method, but will not be enabled. Below is a
diagram of what we will be building out.
Architecture
[Type here]
[Type here]
Mitra, Sumit | RSI
In this workshop, we will guide you through setting up:
An S3 bucket and data download for storing our reports.
Deploying the lambda function for our agent.
[Type here]
[Type here]
Mitra, Sumit | RSI
Defining Bedrock Agent and Action group.
Create a Knowledge base for semantic search capabilities.
Deploying and testing the solution with various prompts.
(Optional) Setting up a Streamlit app for an interactive front-end.
Cloud native projects and other tools we will be using are:
Streamlit Framework is an open-source Python library that makes it easy to
create and share custom UIs.
[Type here]
[Type here]
Mitra, Sumit | RSI
9. Hands-on Exercise
9.1 Time for building!
Login to AWS console
This workshop creates an AWS account. You will need the AWS Account Login
URL provided by the workshop facilitators.
9.2 STEPS
1. Connect to the workshop by browsing to https://catalog.us-east1.prod.workshops.aws/join?access-code= <ReplacewithAccessCode> The
following screen shows up where you will need to specify the event access
code.
2. Click Next.
3. Click on Email One-Time Password (OTP).
4. Enter Email (company email address) and click Send passcode.
[Type here]
[Type here]
Mitra, Sumit | RSI
5. It may take a few minutes to receive your passcode through your email. Enter
the passcode and click Sign in.
6. This should redirect you to the Terms and Conditions. Click on the box to
agree and Click Join event.
7. This will take you to the workshop instructions page. On the bottom right
corner of this screen click on Open AWS Console. This will open AWS
Console in a new browser tab.
[Type here]
[Type here]
Mitra, Sumit | RSI
8. At the end of this workshop, if you are using your own AWS account, clean
up your resources so you don't get charged.
Grant LLM access
9.3 Grant access to various large language models
Before we setup the knowledge base, we will need to grant access to the
models that will be needed for our agent in Bedrock. Navigate to the Amazon
Bedrock console. On the left of the screen, scroll down and select Model
access. On the right, select the Enable specific models button.
[Type here]
[Type here]
Mitra, Sumit | RSI
Select the checkbox for the base model columns Amazon: Titan Text
Embedding V2 and Anthropic: Claude 3 Haiku. This will provide you access
to the required models. After, scroll down to the bottom right and
select Request model access.
Gaining access to both models can take a few minutes.
After, verify that the access status of the models is green with Access
granted.
Review your configuration, then submit.
[Type here]
[Type here]
Mitra, Sumit | RSI
Deploy Resources via Cloudformation
Now, here are the instructions to deploy the resources within your environment:
Download the Cloudformation templates from below, then deploy in order:
Click here to � 1 - S3_Dataload Stack - This template will create an S3 bucket, then
upload Federal Open market committee reports.
Click here to � 2 - Agent_Lambda Stack - This next template will create an Amazon
bedrock agent, action group, with an associated Lambda function.
Deploy templates via AWS CloudFormation:
From the AWS mangement console, search for, then navigate to the AWS
CloudFormation service.
Create a stack with new resources (standard)
Prepare template: Choose existing template -> Specify template: Upload a
template file -> upload the first template from the previous step.
[Type here]
[Type here]
Mitra, Sumit | RSI
Next, Provide a stack name like s3-dataload. Keep the instance type on the
default of t3.small, then go to Next.
On the Configure stack options screen, leave settings as default, then go
to Next.
Scroll down to the capabilities section, and acknowledge the warning
message before submitting.
Once the stack is complete, deploy the second template in the same fashion,
but provide a different template name.
[Type here]
[Type here]
Mitra, Sumit | RSI
9.4 Create Knowledge base, then add to agent
Navigated to the AWS management console. in the search bar at the top, type
in Bedrock. Once the service appears in the dropdown, select it which should
bring you to the Bedrock mangement
console.
Now, we will create a knowledge base by selecting Knowledge bases on the
left under Builder tools. Then, the orange button Create knowledge base.
[Type here]
[Type here]
Mitra, Sumit | RSI
You can use the default name, or enter in your own. Then, select Next at the
bottom right of the screen.
Sync S3 bucket knowledgebase-bedrock-agent-{alias} to this knowledge
base.
[Type here]
[Type here]
Mitra, Sumit | RSI
For the embedding model, choose Titan Text Embeddings V2. Leave the
other options as default, and scroll down to select Next.
On the next screen, review your work, then select Create knowledge base
[Type here]
[Type here]
Mitra, Sumit | RSI
Scroll to the top, and you should see a blue banner saying the vector
database is being prepared. When complete, you will see a green message
saying the setup was successfull, similar to below:
Do not move on to the next step or leave this screen until the knowledge base is
complete.
Next, scroll down to the Data source section, select your knowledge base,
then Sync the data. You will see another blue banner at the top saying that
your data is being synced.
[Type here]
[Type here]
Mitra, Sumit | RSI
Do not move on to the next step until you see a green banner at the top saying that
the sync is complete.
Next, we will sync the knowledge base with the Amazon Bedrock agent. On
the left under Builder tools, select Agents, then the agent that was created
on deployment.
At the top, select the orange button Edit in Agent Builder. While in edit
mode, scroll down to Knowledge base and select Add.
[Type here]
[Type here]
Mitra, Sumit | RSI
When integrating the KB with the agent, you will need to provide basic
instructions on how to handle the knowledge base so the agent knows when
to leverage it. For example, use the following:
1
This knowledge base contains information for understanding data sets related to
economic trends, company financials, and policy decisions made during Federal
Open Market Committee meetings.
Review your input, then select Add.
Scroll to the top and select Save, then Prepare. Then select Save and exit.
-You can now use the prompts below to test your app from the Amazon Bedrock
management console!
Example prompts for Knowledge base:
1
Give me a summary of financial market developments and open market operations
in January 2023
[Type here]
[Type here]
Mitra, Sumit | RSI
1
Tell me the participants view on economic conditions and economic outlook
1
Provide any important information I should know about inflation, or rising prices
1
Tell me about the Staff Review of the Economic & financial Situation
Example prompts for Action groups:
1
Create a portfolio with 3 companies in the real estate industry
1
Create portfolio of 3 companies that are in the technology industry
1
Create a new investment portfolio of companies
1
Do company research on TechStashNova Inc.
**Example prompt for KB & AG- **
1
Send an email to test@example.com that includes the company portfolio and FOMC
summary
(The logic for this method is not implemented to send emails)
-Continue to the next step if you would like to integrate a Streamlit app user interface
with the Bedrock agent.
Setup and Run Streamlit App on EC2 (Optional)
Obtain AWS CloudFormation template to launch the streamlit app: Download
the Cloudformation template from below:
Click here to � 3 - EC2_UI Stack
This template will be used to deploy an EC2 instance that will run the code for
the Streamlit UI.
Deploy template via AWS CloudFormation:
[Type here]
[Type here]
Mitra, Sumit | RSI
From the AWS mangement console, search for, then navigate to the AWS
CloudFormation service.
Create a stack with new resources (standard)
Prepare template: Choose existing template -> Specify template: Upload a
template file -> upload the template from the previous step.
Next, Provide a stack name like ec2-streamlit. Keep the instance type on the
default of t3.small, then go to Next.
[Type here]
[Type here]
Mitra, Sumit | RSI
On the Configure stack options screen, leave settings as default, then go
to Next.
Scroll down to the capabilities section, and acknowledge the warning
message before submitting.
Once the stack is complete, go to the next step.
Edit the app to update agent IDs:
Navigate to the EC2 instance management console. Under instances, you
should see EC2-Streamlit-App. Select the checkbox next to it, then connect to
it via EC2 Instance Connect.
[Type here]
[Type here]
Mitra, Sumit | RSI
Next, use the following command to edit the InvokeAgent.py file:
1
sudo vi app/streamlit_app/InvokeAgent.py
Press i to go into edit mode. Then, update the AGENT ID and Agent ALIAS
ID values.
[Type here]
[Type here]
Mitra, Sumit | RSI
After, hit Esc, then save the file changes with the following command:
1
:wq!
Now, start the streamlit app:
1
streamlit run app/streamlit_app/app.py
You should see an external URL. Copy & paste the URL into a web browser to
start the streamlit application.
Once the app is running, please test some of the sample prompts provided.
(On 1st try, if you receive an error, try again.)
Optionally, you can review the trace events in the left toggle of the screen.
This data will include the Preprocessing, Orchestration,
and PostProcessing traces.
[Type here]
[Type here]
Mitra, Sumit | RSI
[Type here]
[Type here]
Mitra, Sumit | RSI
Event: NAMER Tech Summit (Austin)
10.
10.1 Introduction
Welcome! This hands-on workshop is intended to be a baseline for builders to
extend their use cases across various LLMs via Amazon Bedrock agents. The intent
is to show the art of the possible leveraging all available models on Bedrock for
chained responses to fit different use cases. You will be guided through the process
of setting this up, giving you the flexibility to further explore the power of agents with
the latest models on Amazon bedrock.
10.2 Prerequisites
An active AWS Account.
Familiarity with AWS services like Amazon Bedrock, Amazon S3, and AWS
Lambda.
All models that you plan to test will need to be granted access via Amazon
Bedrock.
10.3 Key Concepts
Amazon Bedrock
Amazon Bedrock is a fully managed service that offers a choice of industry leading
foundation models (FMs) along with a broad set of capabilities that you need to build
generative AI applications, simplifying development with security, privacy, and
responsible AI. With the comprehensive capabilities of Amazon Bedrock, you can
experiment with a variety of top FMs, customize them privately with your data using
techniques such as fine-tuning and retrieval-augmented generation (RAG), and
create managed agents that execute complex business tasks—from booking travel
and processing insurance claims to creating ad campaigns and managing
inventory—all without writing any code. Since Amazon Bedrock is serverless, you
[Type here]
[Type here]
Mitra, Sumit | RSI
don't have to manage any infrastructure, and you can securely integrate and deploy
generative AI capabilities into your applications using the AWS services you are
already familiar with
10.4 Amazon Bedrock Agents
Agents for Amazon Bedrock is a fully managed service that enables generative AI
applications to execute multi-step tasks across an organization's systems and data
sources. You can create an agent in Amazon Bedrock in just a few quick steps,
accelerating the time it takes to build generative AI capabilities into applications.
Agents orchestrate and analyze the task and break it down into the correct logical
sequence using the FM’s reasoning abilities. Agents can automatically call the
necessary functions or knowledge bases to transact with the organization's systems
and processes to fulfill the request, determining along the way if they can proceed or
if they need to gather more information. Alternatively, the developer can choose to
return the control of the functions execution to the application and handle the
function invocations within the application.
10.5 Diagram
[Type here]
[Type here]
Mitra, Sumit | RSI
10.6 Use Case
[Type here]
[Type here]
Mitra, Sumit | RSI
The Content Revolution: Unleashing Creativity with AI
Setting the Scene: In the heart of Silicon Valley, where innovation thrives and ideas
flow like electricity, sits the headquarters of AnyCompany. This cutting-edge content
creation agency, led by a visionary CTO, stands at the crossroads of creativity and
technology. The team, a vibrant mix of wordsmiths, visual artists, and tech gurus, is
united by a shared belief: that AI can revolutionize the world of content creation.
The Problem: Despite their talent and dedication, AnyCompany faces a growing
challenge. Their diverse clientele, ranging from nimble startups to Fortune 500
giants, demand an ever-increasing volume and variety of content. From snappy
social media posts to in-depth product descriptions, from eye-catching ad copy to
accessibility-focused image descriptions - the requests are as varied as they are
numerous. The team finds themselves stretched thin, struggling to maintain quality
and consistency across such a broad spectrum of content types.
The Inspiration: During a late-night brainstorming session, fueled by too much
coffee, the team starts to ask questions to roadmap a solution - would it be possible
they could harness the power of multiple AI models, each specialized for different
types of content creation? The idea of a central AI orchestrator, capable of
delegating tasks to the most suitable AI model, begins to take shape.
The Challenge: However, bringing this vision to life is no small feat. It requires not
just technical prowess, but a deep understanding of content creation nuances. How
can they ensure that the AI-generated content maintains the human touch their
clients love? How do they seamlessly integrate multiple AI models into a cohesive
system? And perhaps most crucially, how can they make this system flexible enough
to adapt to the ever-changing landscape of content creation?
[Type here]
[Type here]
Mitra, Sumit | RSI
The Solution: The team embarks on an ambitious project to build a centralized AI
agent using Amazon Bedrock. This agent becomes the mastermind, capable of
understanding client requests and routing them to the most appropriate AI model:
1. For creating catchy ad copy, it leverages a model specialized in persuasive
writing.
2. Product descriptions are handled by a model trained on e-commerce data.
3. Image analysis and description tasks are routed to a visual recognition model.
4. Text-to-image requests are sent to an advanced image generation model.
5. For summarization tasks, it employs a model expert in distilling long-form
content.
The Impact: The new system transforms AnyCompany Solutions. Suddenly, they can
handle an unprecedented volume of diverse content requests without sacrificing
quality. Clients are amazed by the consistency, creativity, and quick turnaround
times. The human team, freed from repetitive tasks, can focus on high-level strategy
and adding that crucial human touch to the AI-generated content.
The Invitation: Now, it's your turn to join this content revolution. In this workshop,
you'll step into the shoes of AnyCompany's innovative team. You'll learn how to
harness the power of Amazon Bedrock Agents to orchestrate a multi-model solution
capable of tackling diverse content creation tasks. Get ready to push the boundaries
of what's possible in AI-powered content creation!
Solution Overview
The high-level overview of the solution is as follows:
Agent and Environment Setup: The solution begins by configuring an Amazon
Bedrock agent, an AWS Lambda function, and an Amazon S3 bucket. This step
establishes the foundation for model interaction and data handling, preparing the
system to receive and process prompts from a front-end application. Prompt
Processing and Model Inference: When a prompt is received from the front-end
application, the Bedrock agent evaluates and dispatches the prompt, along with the
[Type here]
[Type here]
Mitra, Sumit | RSI
specified model ID, to the Lambda function using the action group mechanism. This
step leverages the action group's API schema for precise parameter handling,
facilitating effective model inference based on the input prompt. Data Handling and
Response Generation: For tasks involving image-to-text or text-to-image conversion,
the Lambda function interacts with the S3 bucket to perform necessary read or write
operations on images. This step ensures the dynamic handling of multimedia
content, culminating in the generation of responses or transformations dictated by
the initial prompt.
Diagram
In the following sections, we will guide you through:
[Type here]
[Type here]
Mitra, Sumit | RSI
Setting up S3 bucket
Deploying the lambda function using CloudFormation
Defining Bedrock Agent and Action group
Deploying and testing the solution with various models and prompts
(Optional) Setting up a Streamlit app for an interactive front-end
Login to AWS console
This workshop creates an AWS account. You will need the AWS Account Login
URL provided by the workshop facilitators.
STEPS
1. Connect to the workshop by browsing to https://catalog.us-east1.prod.workshops.aws/join?access-code= <ReplacewithAccessCode> The
following screen shows up where you will need to specify the event access
code.
2. Click Next.
3. Click on Email One-Time Password (OTP).
4. Enter Email (company email address) and click Send passcode.
[Type here]
[Type here]
Mitra, Sumit | RSI
5. It may take a few minutes to receive your passcode through your email. Enter
the passcode and click Sign in.
6. This should redirect you to the Terms and Conditions. Click on the box to
agree and Click Join event.
7. This will take you to the workshop instructions page. On the bottom right
corner of this screen click on Open AWS Console. This will open AWS
Console in a new browser tab.
[Type here]
[Type here]
Mitra, Sumit | RSI
8. At the end of this workshop, if you are using your own AWS account, clean
up your resources so you don't get charged.
Deploy Resources via Cloudformation
Before we deploy resources, we will first grant access to the models in
Amazon Bedrock. Navigate to the Amazon Bedrock console, scroll to the
bottom of the page and select Bedrock Access under Bedrock
Configurations on the left.
Select 'Enable all models', click Next and Submit.
[Type here]
[Type here]
Mitra, Sumit | RSI
Now, here are the instructions to deploy the resources within your environment:
Download the Cloudformation templates from below, then deploy in order:
Click here to � 1 ECR-Image Stack - This template will create an Docker image
containing the code, then stored in and ECR repository.
Click here to � 2 Lambda-Agent Stack - This next template will create a Lambda
function from the image.
Click here to � 3 EC2-Streamlit Stack - This template will create an EC2 instance
with the Streamlit app running on it..
Deploy templates via AWS CloudFormation:
From the AWS mangement console, search for, then navigate to the AWS
CloudFormation service.
Create a stack with new resources (standard)
Prepare template: Choose existing template -> Specify template: Upload a
template file -> upload the template donaloaded from the previous step.
[Type here]
[Type here]
Mitra, Sumit | RSI
Next, Provide a stack name like ecr-image, then go to Next.
On the Configure stack options screen, leave settings as default, then go
to Next.
For the third template, Keep the default parameter configurations of a t3.small
instance and the default RegionIpsAllowed
Scroll down to the capabilities section, and acknowledge the warning
message before submitting.
Once the stack is complete, deploy the second and third templates in the
same fashion, but provide a different template name.
[Type here]
[Type here]
Mitra, Sumit | RSI
Upon completion, all the templates should be deployed as shown below.
Inspecting the Deployed Resources and Prompting
Configuration and Setup
[Type here]
[Type here]
Mitra, Sumit | RSI
Now, we will walk through each of the components in the workflow to inspect the
deployed resources
Step 1: Inspect the Amazon S3 bucket
We have deployed an S3 bucket called `bedrock-agent-images-{account-id}{region}'. Navigate to the 'lambda-agent' stack and select the Resources tab.
You should see the created bucket.
This step is required to perform image-to-text and text-to-image inference for
certain models. It provides storage for input and output images in our content
creation workflow
[Type here]
[Type here]
Mitra, Sumit | RSI
Next, download the sample image from here , and upload this file into your S3
bucket.
Step 2: Inspect the Lambda Function configuration
We have used a serverless approach to deploy our Lambda function. This
function will be used with the action group of the agent in order to infer your
model of choice.
AWS SAM (Serverless Application Model) is an open-source framework that
helps you build serverless applications on AWS. It simplifies the deployment,
management, and monitoring of serverless resources such as AWS Lambda,
[Type here]
[Type here]
Mitra, Sumit | RSI
Amazon API Gateway, Amazon DynamoDB, and more. Here's a
comprehensive guide on how to set up and use AWS SAM .
The Framework simplifies the process of creating, deploying, and managing
serverless applications by abstracting away the complexities of cloud
infrastructure. It provides a unified way to define and manage your serverless
resources using a configuration file and a set of commands.
Navigate to the the AWS Lambda and inspect the Lambda function
configuration. The Lambda function acts as the intermediary between our
Bedrock agent and the various LLMs. Notice also that we have configured an
IAM Role for Lambda with the following permissions: AmazonS3FullAccess,
AmazonBedrockFullAccess, AWSLambdaBasicExecutionRole These grant
necessary permissions for the Lambda function to interact with S3, Bedrock,
and CloudWatch logs. We also have a Lambda Resource Policy which allows
the Bedrock service to invoke our Lambda function.
Step 3: Inspect the Amazon Bedrock agent and action group
Agents for Amazon Bedrock is a fully managed service that enables generative AI
applications to execute multi-step tasks across an organization's systems and data
sources. You can create an agent in Amazon Bedrock in just a few quick steps,
accelerating the time it takes to build generative AI capabilities into applications. You
first select your desired model and write a few instructions in natural language for
example, “you are a friendly customer service agent” and “check product availability
in the inventory system”.
Agents orchestrate and analyze the task and break it down into the correct logical
sequence using the FM’s reasoning abilities. Agents can automatically call the
[Type here]
[Type here]
Mitra, Sumit | RSI
necessary functions or knowledge bases to transact with the organization's systems
and processes to fulfill the request, determining along the way if they can proceed or
if they need to gather more information. Alternatively, the developer can choose to
return the control of the functions execution to the application and handle the
function invocations within the application. The figure below shows the traditional
Agent orchestration flow where the function execution is handled by the Lambda
function.
Navigate to the Bedrock console. Go to the toggle on the left, and
under Builder Tools select Agents. You would see the agent name,
like InferModels-agent that was deployed through the CloudFormation
template.
Next, inspect the action group. Scroll down to Action groups and notice
the infer-model action group points to the Lambda function.
For the API Schema, notice we're defining the Action group schema via an inline editor. This API schema is needed so that the bedrock agent knows the
[Type here]
[Type here]
Mitra, Sumit | RSI
format structure and parameters required for the action group to interact with
the Lambda function.
Now we will need to modify the Advanced prompts. Select the orange Edit
in Agent Builder button at the top. Scroll down to advanced prompts, then
select Edit.
In the Orchestration tab, enable the Override orchestration template
defaults option.
[Type here]
[Type here]
Mitra, Sumit | RSI
In the Prompt template editor, go to line 22-23 and copy & paste the
following prompt:
1
2
3
4
5
6
Here is an example of what a url response to access an image should look like:
<url_example>
URL Generated to access the image:
https://bedrock-agentimages.s3.amazonaws.com/generated_pic.png?AWSAccessKeyId=123xyz&Signatu
re=rlF0gN%2BuaTHzuEDfELz8GOwJacA%3D&x-amz-securitytoken=IQoJb3JpZ2msqKr6cs7sTNRG145hKcxCUngJtRcQ%2FzsvDvt0QUSyl7xgp8
yldZJu5Jg%3D%3D&Expires=1712628409
</url_example>
[Type here]
[Type here]
Mitra, Sumit | RSI
Scroll to the bottom, then save & exit.
This prompt helps provide the agent an example when formatting the
response of a presigned url after an image is generated in the S3 bucket.
Additionally, there is an option to use a custom parser Lambda function for
more granular formatting.
Step 4: Test various models
To start testing, prepare the agent by finding the prepare button on the Agent
builder page
On the right, you should see an option to test the agent with a user input field.
Below are a few prompts that we would be testing for our scenario.
Test Scenarios
Let's run through some content creation tasks that align with CreativeAI Solutions'
needs:
1. Ad Copy Generation Prompt:
Use model meta.llama3-1-70b-instruct-v1:0 and create a catchy ad copy for
AnyCompany's Solutions' new AI-powered content creation service. Target audience:
marketing professionals at mid-size companies.
2. Product Description Prompt:
[Type here]
[Type here]
Mitra, Sumit | RSI
Use Use model ai21.j2-ultra-v1 and write a compelling product description for
AnyCompany's Solutions' multi-model content generation platform. Highlight its key
features and benefits for potential clients in the e-commerce industry.
3. Image Generation Prompt:
Use model amazon.titan-image-generator-v2:0 and create an image representing the
concept of AI-powered content creation. The image should showcase creativity and
technology working together.
4. Image Analysis Prompt:
Use model anthropic.claude-3-sonnet-20240229-v1:0 and analyze the image that is
uploaded to our S3 bucket. Describe the key elements of AnyCompany's Solutions'
logo for accessibility purposes.
5. Content Summarization Prompt:
Use model anthropic.claude-3-haiku-20240307-v1:0 and summarize the following
article about the impact of AI on content marketing into a short, engaging social
media post for Anycompany's Solutions: [Insert a relevant article here]
(If you would like to have a UI setup with this project, continue to step 6)
Step 6: Setting up and running the Streamlit app
You will need to copy the agent alias ID, along with the agent ID for this step.
Go to the Bedrock management console, then select your multi-model agent.
Copy the Agent ID from the top-right of the Agent overview section.
Edit the app to update agent IDs:
[Type here]
[Type here]
Mitra, Sumit | RSI
Navigate to the EC2 instance management console. Under instances, you
should see EC2-Streamlit-App. Select the checkbox next to it, then connect to
it via EC2 Instance Connect.
Next, use the following command to edit the InvokeAgent.py file:
1
sudo vi app/streamlit_app/InvokeAgent.py
Press i to go into edit mode. Then, update the AGENT ID and Agent ALIAS
ID values.
[Type here]
[Type here]
Mitra, Sumit | RSI
After, hit Esc, then save the file changes with the following command:
1
:wq!
Now, start the streamlit app:
1
streamlit run app/streamlit_app/app.py
You should see an external URL. Copy & paste the URL into a web browser to
start the streamlit application.
Once the app is running, please test some of the sample prompts provided.
(On 1st try, if you receive an error, try again.)
[Type here]
[Type here]
Mitra, Sumit | RSI
Optionally, you can review the trace events in the left toggle of the screen.
This data will include the Preprocessing, Orchestration,
and PostProcessing traces.
Model IDs this project currently supports:
Anthropic: Claude
anthropic.claude-3-haiku-20240307-v1:0
anthropic.claude-3-sonnet-20240229-v1:0
anthropic.claude-v2:1
anthropic.claude-v2
anthropic.claude-instant-v1
Mistral: models
mistral.mistral-large-2402-v1:0
mistral.mistral-7b-instruct-v0:2
mistral.mixtral-8x7b-instruct-v0:1
Amazon: Titan Models
[Type here]
[Type here]
Mitra, Sumit | RSI
amazon.titan-text-lite-v1
amazon.titan-text-express-v1
amazon.titan-image-generator-v1 (in preview)
Meta: Llama models
meta.llama3-8b-instruct-v1:0
meta.llama3-70b-instruct-v1:0
meta.llama2-13b-chat-v1
meta.llama2-70b-chat-v1
Cohere: Command Models
cohere.command-text-v14
cohere.command-light-text-v14
Stability AI: SDXL Models
stability.stable-diffusion-xl-v1
AI21labs: Jurassic models
ai21.j2-ultra-v1
ai21.j2-mid-v1
Custom models
{custom model ID}
[Type here]
[Type here]
Mitra, Sumit | RSI
Remember that you can use any available model from Amazon Bedrock, and are
not limited to the list above. If a model ID is not listed, please refer to the latest
available models (IDs) on the Amazon Bedrock documentation page here .
Conclusion
You can leverage the provided project to fine-tune and benchmark this solution
against your own datasets and use cases. Explore different model combinations,
push the boundaries of what's possible, and drive innovation in the ever-evolving
landscape of generative AI.
[Type here]
[Type here]
Mitra, Sumit | RSI
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )