The Agent Blueprints feature aims to address the challenge of simplifying the process of getting started with building agents for Amazon Bedrock Agents. These constructs are available as an NPM module agents-for-amazon-bedrock-blueprints
The BedrockAgentBlueprintsConstruct
is an L3 construct for AWS CDK (Cloud Development Kit) that allows you to create and deploy Bedrock agents, which are AI-powered conversational agents, on AWS.
This construct simplifies the process of creating and configuring Bedrock agents by providing a high-level interface for defining agent definitions, action groups, and knowledge bases.
The easiest way to get started with Agent Blueprints is to follow our Getting Started guide.
For complete project documentation, please see our official project documentation site.
To view a library of templates leveraging the agents-for-amazon-bedrock-blueprints
and a library of prompts, please see our Bedrock Samples Repository.
The BedrockAgentBlueprintsConstruct
is composed of the following key components:
-
Agent Definition: An
AgentDefinitionBuilder
is used to define the agent's properties like name, instruction, foundationModel etc. This also allows users to build the agent with different prompts from the library. -
Action Groups: An
AgentActionGroup
is a placeholder construct used to define the actions that the agent can perform, and helps in setup of associated Lambda function code and OpenAPI schema. -
Knowledge Bases: An
AgentKnowledgeBase
is used to define the knowledge base for the agent, which can include various asset files for the data source. Currently this supports automated creation of an AOSS cluster, deploys the assets to an assets bucket, builds a data source, builds a KB and syncs the data source. -
Guardrails: The
BedrockGuardrailsBuilder
simplifies the creation of Amazon Bedrock Guardrails. Guardrails are a set of rules and policies that help ensure the safety and compliance of your AI applications.
Run the following command to install the agents-for-amazon-bedrock-blueprints
dependency in your project.
npm i @aws/agents-for-amazon-bedrock-blueprints
Here's an example of how to use the BedrockAgentBlueprintsConstruct
:
export class DemoTemplateStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// 1. Define the agent definition
const agentDef = new AgentDefinitionBuilder(this, 'NewAgentDef', {})
.withAgentName('MyFirstAgent')
.withInstruction('Amazing new fun agent to do great things in code')
.withPostProcessingPrompt(PROMPT_LIBRARY.json_converter)
.build();
// 2. Define the action group [Optional]
const inlineCode = Buffer.from(/* ... */);
const inlineSchema = /* ... */;
const action = new AgentActionGroup(this, 'NewAction', {
actionGroupName: 'FetchAssets',
description: 'Dummy action for first agent',
lambdaCode: {
lambdaCode: inlineCode,
lambdaHandler: 'index.handler',
lambdaRuntime: Runtime.NODEJS_18_X
},
inlineSchema: inlineSchema
});
// 3. Define the knowledge base [Optional]
const fileBuffer = fs.readFileSync(/* ... */);
const knowledgeBase = new AgentKnowledgeBase(this, 'NewKB', {
kbName: 'DummyKB',
description: 'Dummy KB for dummy agent',
assetFiles: [fileBuffer]
});
// 4. Define the Guardrail [Optional]
const guardrail = new BedrockGuardrailsBuilder(this, "AgentGuardrail", {
name: "RubyOnRails",
generateKmsKey: true,
})
.withFiltersConfig(FilterType.INSULTS)
.withManagedWordsConfig(ManagedWordsTypes.PROFANITY)
.withWordsConfig(['government', 'dictator'])
.withPIIConfig(PIIAction.ANONYMIZE, PIIType.US_SOCIAL_SECURITY_NUMBER)
.withTopicConfig("Arts", "Anything related to arts and crafts", ['painting', 'ceramics'])
.build();
// 4. Create the BedrockAgentBlueprintsConstruct
new BedrockAgentBlueprintsConstruct(this, 'AmazonBedrockAgentBlueprintsStack', {
agentDefinition: agentDef,
actionGroups: [action],
knowledgeBases: [knowledgeBase],
guardrail: guardrail
});
}
}
In this example, we:
- Define the agent definition using the
AgentDefinitionBuilder
- Define an action group with an inline Lambda function and OpenAPI schema.
- Define a knowledge base with a CSV file.
- Define a guardrail that blocks anything related to arts and crafts.
- Create the
BedrockAgentBlueprintsConstruct
and pass in the agent definition, action groups, guardrail and knowledge bases.
When you deploy this CDK stack, it will create the necessary AWS resources to deploy the Bedrock agent with the specified configuration.
Opt-out of resource creation for KB: Users can choose to opt-out of creating KB resources as it may become expensive to deploy the AOSS clusters for KB. If any templates initializes KB, you can skip KB creation by adding a flag skipKBCreation in the CDK context.
Example:
cdk synth <STACK_NAME> --context skipKBCreation=true
To deploy the BedrockAgentBlueprintsConstruct
, you can use the standard CDK deployment process:
-
Create an application that deploys the stack
const app = new cdk.App(); const permissionObject = { env: { account: 'XXXXXXXXXX', region: 'us-east-1' }, }; new DemoTemplateStack(app, 'AmazonBedrockAgentBlueprintsStack', permissionObject);
-
Synthesize the CloudFormation template:
cdk synth AmazonBedrockAgentBlueprintsStack
-
Bootstrap your account if not already:
cdk bootstrap aws://<AWS_ACCOUNT_ID>/<AWS_REGION>
-
Deploy the stack:
cdk deploy AmazonBedrockAgentBlueprintsStack
This will create the necessary AWS resources, including the Bedrock agent, and deploy the agent to your AWS environment.
Please see Guidelines on GitHub for details on contributions.
For additional details, learning recommendations, step-by-step instructions, and customization options, see our official documentation site. To post feedback, submit feature ideas, or report bugs, use the Issues section of this GitHub repo.
This library is licensed under the "MIT-0" License.