Skip to content

Commit adb7692

Browse files
dineshSajwandinsajwa
andauthored
chore(documentation): updated bedrock readme file (#924)
* chore(documentation): updated bedrock readme file --------- Co-authored-by: dinsajwa <dinsajwa@amazon.com>
1 parent 4f1176f commit adb7692

File tree

1 file changed

+186
-12
lines changed

1 file changed

+186
-12
lines changed

src/cdk-lib/bedrock/README.md

Lines changed: 186 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
| ![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) TypeScript | `@cdklabs/generative-ai-cdk-constructs` |
2020
| ![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python | `cdklabs.generative_ai_cdk_constructs` |
2121

22-
[Amazon Bedrock](https://aws.amazon.com/bedrock/) is a fully managed service that offers a choice of foundation models (FMs) along with a broad set of capabilities for building generative AI applications.
22+
[Amazon Bedrock](https://aws.amazon.com/bedrock/) is a fully managed service that offers a choice of high-performing foundation models (FMs) from leading AI companies and Amazon through a single API, along with a broad set of capabilities you need to build generative AI applications with security, privacy, and responsible AI.
2323

24-
This construct library includes CloudFormation L1 resources to deploy Bedrock features.
24+
This construct library facilitates the deployment of Knowledge Bases, Bedrock Agents, Guardrails, Prompt Management, and Inference Pipelines. It leverages underlying CloudFormation L1 resources to provision these Bedrock features.
2525

2626
## Table of contents
2727

@@ -38,7 +38,7 @@ See the [API documentation](../../../apidocs/namespaces/bedrock/README.md).
3838

3939
## Knowledge Bases
4040

41-
With Knowledge Bases for Amazon Bedrock, you can give FMs and agents contextual information from your company’s private data sources for Retrieval Augmented Generation (RAG) to deliver more relevant, accurate, and customized responses.
41+
Amazon Bedrock Knowledge Bases enable you to provide foundation models and agents with contextual information from your company’s private data sources. This enhances the relevance, accuracy, and customization of their responses.
4242

4343
### Create a Knowledge Base
4444

@@ -48,6 +48,25 @@ The resource accepts an `instruction` prop that is provided to any Bedrock Agent
4848

4949
Amazon Bedrock Knowledge Bases currently only supports S3 as a data source. The `S3DataSource` resource is used to configure how the Knowledge Base handles the data source.
5050

51+
## Knowledge Base Properties
52+
53+
54+
| Name | Type | Required | Description |
55+
|---|---|---|---|
56+
| embeddingsModel | BedrockFoundationModel | Yes | The embeddings model for the knowledge base |
57+
| name | string | No | The name of the knowledge base |
58+
| description | string | No | The description of the knowledge base |
59+
| instruction | string | No | Instructions for agents based on the design and type of information of the Knowledge Base that will impact how Agents interact with the Knowledge Base |
60+
| existingRole | iam.IRole | No | Existing IAM role with a policy statement granting permission to invoke the specific embeddings model |
61+
| indexName | string | No | The name of the vector index (only applicable if vectorStore is of type VectorCollection) |
62+
| vectorField | string | No | The name of the field in the vector index (only applicable if vectorStore is of type VectorCollection) |
63+
| vectorStore | VectorCollection \| PineconeVectorStore \| AmazonAuroraVectorStore \| ExistingAmazonAuroraVectorStore | No | The vector store for the knowledge base |
64+
| vectorIndex | VectorIndex | No | The vector index for the OpenSearch Serverless backed knowledge base |
65+
| knowledgeBaseState | string | No | Specifies whether to use the knowledge base or not when sending an InvokeAgent request |
66+
| tags | Record<string, string> | No | Tag (KEY-VALUE) bedrock agent resource |
67+
68+
## Initializer
69+
5170
Example of `OpenSearch Serverless`:
5271

5372
TypeScript
@@ -595,7 +614,7 @@ class PythonTestStack(Stack):
595614
Python
596615

597616
```python
598-
ChunkingStrategy.DEFAULT;
617+
ChunkingStrategy.DEFAULT
599618
```
600619

601620
- **Fixed Size Chunking**: This method divides the data into fixed-size chunks, with each chunk
@@ -617,7 +636,7 @@ class PythonTestStack(Stack):
617636

618637
```python
619638
# Fixed Size Chunking with sane defaults.
620-
ChunkingStrategy.FIXED_SIZE;
639+
ChunkingStrategy.FIXED_SIZE
621640

622641
# Fixed Size Chunking with custom values.
623642
ChunkingStrategy.fixed_size(
@@ -706,7 +725,7 @@ class PythonTestStack(Stack):
706725
Python
707726

708727
```python
709-
ChunkingStrategy.NONE;
728+
ChunkingStrategy.NONE
710729
```
711730

712731
#### Knowledge Base - Parsing Strategy
@@ -769,12 +788,35 @@ CustomTransformation.lambda_(
769788

770789
## Agents
771790

772-
Enable generative AI applications to execute multistep tasks across company systems and data sources.
791+
Amazon Bedrock Agents allow generative AI applications to automate complex, multistep tasks by seamlessly integrating with your company’s systems, APIs, and data sources.
792+
793+
794+
### Agent Properties
795+
796+
| Name | Type | Required | Description |
797+
|---|---|---|---|
798+
| name | string | No | The name of the agent. Defaults to a name generated by CDK |
799+
| instruction | string | Yes | The instruction used by the agent that determines how it will perform its task. Must have a minimum of 40 characters |
800+
| foundationModel | IInvokable | Yes | The foundation model used for orchestration by the agent |
801+
| existingRole | iam.IRole | No | The existing IAM Role for the agent to use. Must have a trust policy allowing Bedrock service to assume the role. Defaults to a new created role |
802+
| shouldPrepareAgent | boolean | No | Specifies whether to automatically update the `DRAFT` version of the agent after making changes. Defaults to false |
803+
| idleSessionTTL | Duration | No | How long sessions should be kept open for the agent. Session expires if no conversation occurs during this time. Defaults to 1 hour |
804+
| kmsKey | kms.IKey | No | The KMS key of the agent if custom encryption is configured. Defaults to AWS managed key |
805+
| description | string | No | A description of the agent. Defaults to no description |
806+
| knowledgeBases | IKnowledgeBase[] | No | The KnowledgeBases associated with the agent |
807+
| actionGroups | AgentActionGroup[] | No | The Action Groups associated with the agent |
808+
| guardrail | IGuardrail | No | The guardrail that will be associated with the agent |
809+
| promptOverrideConfiguration | PromptOverrideConfiguration | No | Overrides some prompt templates in different parts of an agent sequence configuration |
810+
| userInputEnabled | boolean | No | Select whether the agent can prompt additional information from the user when it lacks enough information. Defaults to false |
811+
| codeInterpreterEnabled | boolean | No | Select whether the agent can generate, run, and troubleshoot code when trying to complete a task. Defaults to false |
812+
| forceDelete | boolean | No | Whether to delete the resource even if it's in use. Defaults to true |
773813

774814
### Create an Agent
775815

776816
The following example creates an Agent with a simple instruction and default prompts that consults a Knowledge Base.
777817

818+
### Initializer
819+
778820
TypeScript
779821

780822
```ts
@@ -795,7 +837,7 @@ agent = bedrock.Agent(
795837
foundation_model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
796838
instruction="You are a helpful and friendly agent that answers questions about insurance claims.",
797839
)
798-
agent.add_knowledge_base(kb);
840+
agent.add_knowledge_base(kb)
799841
```
800842

801843
You can also use system defined inference profiles to enable cross region inference requests for supported models. For instance:
@@ -836,6 +878,22 @@ For more information on cross region inference, please refer to [System defined
836878

837879
An action group defines functions your agent can call. The functions are Lambda functions. The action group uses an OpenAPI schema to tell the agent what your functions do and how to call them.
838880

881+
### Action Group Properties
882+
883+
| Name | Type | Required | Description |
884+
|---|---|---|---|
885+
| name | string | Yes | The name of the action group |
886+
| description | string | No | A description of the action group |
887+
| apiSchema | ApiSchema | No | The API Schema |
888+
| executor | ActionGroupExecutor | No | The action group executor |
889+
| enabled | boolean | No | Specifies whether the action group is available for the agent to invoke or not when sending an InvokeAgent request. Defaults to true |
890+
| forceDelete | boolean | No | Specifies whether to delete the resource even if it's in use. Defaults to false |
891+
| functionSchema | CfnAgent.FunctionSchemaProperty | No | Defines functions that each define parameters that the agent needs to invoke from the user |
892+
| parentActionGroupSignature | ParentActionGroupSignature | No | The AWS Defined signature for enabling certain capabilities in your agent. When specified, description, apiSchema, and actionGroupExecutor must be blank |
893+
894+
895+
### Initializer
896+
839897
```ts
840898
const actionGroupFunction = new lambda_python.PythonFunction(this, 'ActionGroupFunction', {
841899
runtime: lambda.Runtime.PYTHON_3_12,
@@ -866,11 +924,10 @@ action_group_function = PythonFunction(
866924
handler="lambda_handler",
867925
)
868926

869-
actionGroup = bedrock.AgentActionGroup(self,
870-
"MyActionGroup",
927+
actionGroup = bedrock.AgentActionGroup(
871928
name="query-library",
872929
description="Use these functions to get information about the books in the library.",
873-
action_group_executor= bedrock.ActionGroupExecutor.from_lambda_function(action_group_function),
930+
executor= bedrock.ActionGroupExecutor.fromlambda_function(action_group_function),
874931
enabled=True,
875932
api_schema=bedrock.ApiSchema.from_local_asset("action-group.yaml"))
876933

@@ -1201,10 +1258,38 @@ const prompt1 = new Prompt(this, 'prompt1', {
12011258
description: 'my first prompt',
12021259
defaultVariant: variant1,
12031260
variants: [variant1],
1204-
encryptionKey: cmk,
1261+
kmsKey: cmk,
12051262
});
12061263
```
12071264

1265+
Python
1266+
1267+
```python
1268+
cmk = kms.Key(self, "cmk")
1269+
claude_model = bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0
1270+
1271+
variant1 = bedrock.PromptVariant.text(
1272+
variant_name="variant1",
1273+
model=claude_model,
1274+
prompt_variables=["topic"],
1275+
prompt_text="This is my first text prompt. Please summarize our conversation on: {{topic}}.",
1276+
inference_configuration={
1277+
"temperature": 1.0,
1278+
"top_p": 0.999,
1279+
"max_tokens": 2000,
1280+
}
1281+
)
1282+
1283+
prompt = bedrock.Prompt(
1284+
self,
1285+
"myprompt",
1286+
prompt_name="prompt1",
1287+
description="my first prompt",
1288+
default_variant=variant1,
1289+
variants=[variant1],
1290+
kms_key=cmk
1291+
)
1292+
```
12081293
Example of a "Chat" `Prompt`. Use this template type when the model supports the Converse API or the Anthropic Claude Messages API.
12091294
This allows you to include a System prompt and previous User messages and Assistant messages for context.
12101295

@@ -1258,6 +1343,68 @@ new Prompt(stack, 'prompt1', {
12581343
});
12591344
```
12601345

1346+
Python
1347+
1348+
```python
1349+
1350+
# Create KMS key
1351+
cmk = kms.Key(self, "cmk")
1352+
1353+
# Create tool specification
1354+
tool_spec = CfnPrompt.ToolSpecificationProperty(
1355+
name="top_song",
1356+
description="Get the most popular song played on a radio station.",
1357+
input_schema=CfnPrompt.ToolInputSchemaProperty(
1358+
json={
1359+
"type": "object",
1360+
"properties": {
1361+
"sign": {
1362+
"type": "string",
1363+
"description": "The call sign for the radio station for which you want the most popular song. Example calls signs are WZPZ and WKR."
1364+
}
1365+
},
1366+
"required": ["sign"]
1367+
}
1368+
)
1369+
)
1370+
1371+
# Create tool configuration
1372+
tool_config = bedrock.ToolConfiguration(
1373+
tool_choice=bedrock.ToolChoice.AUTO,
1374+
tools=[
1375+
CfnPrompt.ToolProperty(
1376+
tool_spec=tool_spec
1377+
)
1378+
]
1379+
)
1380+
1381+
# Create chat variant
1382+
variant_chat = bedrock.PromptVariant.chat(
1383+
variant_name="variant1",
1384+
model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
1385+
messages=[
1386+
bedrock.ChatMessage.user("From now on, you speak Japanese!"),
1387+
bedrock.ChatMessage.assistant("Konnichiwa!"),
1388+
bedrock.ChatMessage.user("From now on, you speak {{language}}!"),
1389+
],
1390+
system="You are a helpful assistant that only speaks the language you're told.",
1391+
prompt_variables=["language"],
1392+
tool_configuration=tool_config
1393+
)
1394+
1395+
# Create prompt
1396+
prompt = bedrock.Prompt(
1397+
self,
1398+
"prompt1",
1399+
prompt_name="prompt-chat",
1400+
description="my first chat prompt",
1401+
default_variant=variant_chat,
1402+
variants=[variant_chat],
1403+
kms_key=cmk
1404+
)
1405+
1406+
```
1407+
12611408
### Prompt Variants
12621409

12631410
Prompt variants in the context of Amazon Bedrock refer to alternative configurations of a prompt,
@@ -1287,6 +1434,24 @@ const variant2 = PromptVariant.text({
12871434

12881435
prompt1.addVariant(variant2);
12891436
```
1437+
Python
1438+
1439+
```python
1440+
1441+
variant2 = bedrock.PromptVariant.text(
1442+
variant_name="variant2",
1443+
model=claude_model,
1444+
prompt_variables=["topic"],
1445+
prompt_text="This is my second text prompt. Please summarize our conversation on: {{topic}}.",
1446+
inference_configuration={
1447+
"temperature": 0.5,
1448+
"topP": 0.999,
1449+
"maxTokens": 2000,
1450+
}
1451+
)
1452+
1453+
prompt.add_variant(variant2)
1454+
```
12901455

12911456
### Prompt routing
12921457

@@ -1344,12 +1509,21 @@ to update the version whenever a certain configuration property changes.
13441509
new PromptVersion(prompt1, 'my first version');
13451510
```
13461511

1512+
```python
1513+
bedrock.PromptVersion(self, "my first version")
1514+
1515+
```
1516+
13471517
or alternatively:
13481518

13491519
```ts
13501520
prompt1.createVersion('my first version');
13511521
```
13521522

1523+
```python
1524+
prompt.create_version("version1", "my first version")
1525+
```
1526+
13531527
## System defined inference profiles
13541528

13551529
You can build a CrossRegionInferenceProfile using a system defined inference profile. The inference profile will route requests to the Regions defined in the cross region (system-defined) inference profile that you choose. You can find the system defined inference profiles by navigating to your console (Amazon Bedrock -> Cross-region inference) or programmatically, for instance using [boto3](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock/client/list_inference_profiles.html).

0 commit comments

Comments
 (0)