konokenj.cdk-api-mcp-server 0.26.0__py3-none-any.whl → 0.28.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of konokenj.cdk-api-mcp-server might be problematic. Click here for more details.

Files changed (43) hide show
  1. cdk_api_mcp_server/__about__.py +1 -1
  2. cdk_api_mcp_server/resources/aws-cdk/constructs/@aws-cdk/aws-amplify-alpha/README.md +14 -0
  3. cdk_api_mcp_server/resources/aws-cdk/constructs/@aws-cdk/aws-bedrock-alpha/README.md +608 -0
  4. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-apigateway/integ.model-schema-additional-items.ts +72 -0
  5. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-cloudfront/README.md +8 -0
  6. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-cloudfront/integ.distribution-basic.ts +1 -1
  7. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-codedeploy/integ.deployment-config.ts +15 -4
  8. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-codedeploy/integ.deployment-group.ts +40 -218
  9. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-codepipeline-actions/README.md +34 -0
  10. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-codepipeline-actions/integ.pipeline-ec2-deploy-ssm-managed.ts +140 -0
  11. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-codepipeline-actions/integ.pipeline-ec2-deploy.ts +140 -0
  12. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ec2/README.md +55 -1
  13. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ec2/integ.machine-image-cached.ts +53 -0
  14. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ec2/integ.volume-initialization-rate.ts +21 -0
  15. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs/README.md +16 -0
  16. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs/integ.availability-zone-rebalancing.ts +4 -14
  17. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs/integ.enable-execute-command.ts +29 -35
  18. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs/integ.exec-command.ts +22 -16
  19. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs/integ.lb-awsvpc-nw.ts +16 -26
  20. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ecs/integ.pseudo-terminal.ts +8 -18
  21. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-eks/README.md +6 -0
  22. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-eks/integ.custom-addons.ts +48 -0
  23. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-logs/README.md +1 -0
  24. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-logs/integ.expose-metric-with-dimensions.ts +47 -0
  25. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-opensearchservice/integ.opensearch.gp3.ts +16 -1
  26. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-opensearchservice/integ.opensearch.https.ts +54 -0
  27. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-rds/README.md +25 -2
  28. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-rds/integ.cluster-serverless-v2-autopause.ts +27 -0
  29. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-rds/integ.instance-from-cluster-snapshot.ts +23 -0
  30. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-ssm/README.md +16 -0
  31. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-stepfunctions/README.md +21 -0
  32. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-stepfunctions/integ.map-jsonata-itemselector.ts +36 -0
  33. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-stepfunctions-tasks/integ.invoke-jsonata.ts +80 -87
  34. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-stepfunctions-tasks/integ.invoke.ts +69 -87
  35. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-stepfunctions-tasks/integ.start-job-run.ts +104 -102
  36. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-synthetics/README.md +23 -0
  37. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-synthetics/integ.canary-dryrun-update.ts +32 -0
  38. cdk_api_mcp_server/resources/aws-cdk/constructs/aws-cdk-lib/aws-synthetics/integ.canary.ts +2 -0
  39. {konokenj_cdk_api_mcp_server-0.26.0.dist-info → konokenj_cdk_api_mcp_server-0.28.0.dist-info}/METADATA +2 -2
  40. {konokenj_cdk_api_mcp_server-0.26.0.dist-info → konokenj_cdk_api_mcp_server-0.28.0.dist-info}/RECORD +43 -30
  41. {konokenj_cdk_api_mcp_server-0.26.0.dist-info → konokenj_cdk_api_mcp_server-0.28.0.dist-info}/WHEEL +0 -0
  42. {konokenj_cdk_api_mcp_server-0.26.0.dist-info → konokenj_cdk_api_mcp_server-0.28.0.dist-info}/entry_points.txt +0 -0
  43. {konokenj_cdk_api_mcp_server-0.26.0.dist-info → konokenj_cdk_api_mcp_server-0.28.0.dist-info}/licenses/LICENSE.txt +0 -0
@@ -1,4 +1,4 @@
1
1
  # SPDX-FileCopyrightText: 2025-present Kenji Kono <konoken@amazon.co.jp>
2
2
  #
3
3
  # SPDX-License-Identifier: MIT
4
- __version__ = "0.26.0"
4
+ __version__ = "0.28.0"
@@ -293,3 +293,17 @@ declare const asset: assets.Asset;
293
293
  declare const amplifyApp: amplify.App;
294
294
  const branch = amplifyApp.addBranch("dev", { asset: asset });
295
295
  ```
296
+
297
+ ## Skew protection for Amplify Deployments
298
+
299
+ Deployment skew protection is available to Amplify applications to eliminate version skew issues between client and servers in web applications.
300
+ When you apply skew protection to an Amplify application, you can ensure that your clients always interact with the correct version of server-side assets, regardless of when a deployment occurs.
301
+
302
+ For more information, see [Skew protection for Amplify deployments](https://docs.aws.amazon.com/amplify/latest/userguide/skew-protection.html).
303
+
304
+ To enable skew protection, set the `skewProtection` property to `true`:
305
+
306
+ ```ts
307
+ declare const amplifyApp: amplify.App;
308
+ const branch = amplifyApp.addBranch("dev", { skewProtection: true });
309
+ ```
@@ -0,0 +1,608 @@
1
+ # Amazon Bedrock Construct Library
2
+
3
+ <!--BEGIN STABILITY BANNER-->
4
+
5
+ ---
6
+
7
+ ![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)
8
+
9
+ > The APIs of higher level constructs in this module are experimental and under active development.
10
+ > They are subject to non-backward compatible changes or removal in any future version. These are
11
+ > not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be
12
+ > announced in the release notes. This means that while you may use them, you may need to update
13
+ > your source code when upgrading to a newer version of this package.
14
+
15
+ ---
16
+
17
+ <!--END STABILITY BANNER-->
18
+
19
+ | **Language** | **Package** |
20
+ | :--------------------------------------------------------------------------------------------- | --------------------------------------- |
21
+ | ![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) TypeScript | `@aws-cdk/aws-bedrock-alpha` |
22
+
23
+ [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.
24
+
25
+ This construct library facilitates the deployment of Bedrock Agents, enabling you to create sophisticated AI applications that can interact with your systems and data sources.
26
+
27
+ ## Table of contents
28
+
29
+ - [Agents](#agents)
30
+ - [Create an Agent](#create-an-agent)
31
+ - [Action groups](#action-groups)
32
+ - [Prepare the Agent](#prepare-the-agent)
33
+ - [Prompt Override Configuration](#prompt-override-configuration)
34
+ - [Memory Configuration](#memory-configuration)
35
+ - [Agent Collaboration](#agent-collaboration)
36
+ - [Custom Orchestration](#custom-orchestration)
37
+ - [Agent Alias](#agent-alias)
38
+
39
+ ## Agents
40
+
41
+ Amazon Bedrock Agents allow generative AI applications to automate complex, multistep tasks by seamlessly integrating with your company's systems, APIs, and data sources. It uses the reasoning of foundation models (FMs), APIs, and data to break down user requests, gather relevant information, and efficiently complete tasks.
42
+
43
+ ### Create an Agent
44
+
45
+ Building an agent is straightforward and fast.
46
+ The following example creates an Agent with a simple instruction and default prompts:
47
+
48
+ ```ts fixture=default
49
+ const agent = new bedrock.Agent(this, 'Agent', {
50
+ foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
51
+ instruction: 'You are a helpful and friendly agent that answers questions about literature.',
52
+ });
53
+ ```
54
+
55
+ ### Agent Properties
56
+
57
+ The Bedrock Agent class supports the following properties.
58
+
59
+ | Name | Type | Required | Description |
60
+ |---|---|---|---|
61
+ | name | string | No | The name of the agent. Defaults to a name generated by CDK |
62
+ | instruction | string | Yes | The instruction used by the agent that determines how it will perform its task. Must have a minimum of 40 characters |
63
+ | foundationModel | IBedrockInvokable | Yes | The foundation model used for orchestration by the agent |
64
+ | 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 |
65
+ | shouldPrepareAgent | boolean | No | Specifies whether to automatically update the `DRAFT` version of the agent after making changes. Defaults to false |
66
+ | 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 |
67
+ | kmsKey | kms.IKey | No | The KMS key of the agent if custom encryption is configured. Defaults to AWS managed key |
68
+ | description | string | No | A description of the agent. Defaults to no description |
69
+ | actionGroups | AgentActionGroup[] | No | The Action Groups associated with the agent |
70
+ | promptOverrideConfiguration | PromptOverrideConfiguration | No | Overrides some prompt templates in different parts of an agent sequence configuration |
71
+ | userInputEnabled | boolean | No | Select whether the agent can prompt additional information from the user when it lacks enough information. Defaults to false |
72
+ | codeInterpreterEnabled | boolean | No | Select whether the agent can generate, run, and troubleshoot code when trying to complete a task. Defaults to false |
73
+ | forceDelete | boolean | No | Whether to delete the resource even if it's in use. Defaults to true |
74
+ | agentCollaboration | AgentCollaboration | No | Configuration for agent collaboration settings, including type and collaborators. This property allows you to define how the agent collaborates with other agents and what collaborators it can work with. Defaults to no agent collaboration configuration |
75
+ | customOrchestrationExecutor | CustomOrchestrationExecutor | No | The Lambda function to use for custom orchestration. If provided, orchestrationType is set to CUSTOM_ORCHESTRATION. If not provided, orchestrationType defaults to DEFAULT. Defaults to default orchestration |
76
+
77
+ ### Action Groups
78
+
79
+ 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.
80
+
81
+ #### Action Group Properties
82
+
83
+ The AgentActionGroup class supports the following properties.
84
+
85
+ | Name | Type | Required | Description |
86
+ |---|---|---|---|
87
+ | name | string | No | The name of the action group. Defaults to a name generated in the format 'action_group_quick_start_UUID' |
88
+ | description | string | No | A description of the action group |
89
+ | apiSchema | ApiSchema | No | The OpenAPI schema that defines the functions in the action group |
90
+ | executor | ActionGroupExecutor | No | The Lambda function that executes the actions in the group |
91
+ | enabled | boolean | No | Whether the action group is enabled. Defaults to true |
92
+ | forceDelete | boolean | No | Whether to delete the resource even if it's in use. Defaults to false |
93
+ | functionSchema | FunctionSchema | No | Defines functions that each define parameters that the agent needs to invoke from the user |
94
+ | parentActionGroupSignature | ParentActionGroupSignature | No | The AWS Defined signature for enabling certain capabilities in your agent |
95
+
96
+ There are three ways to provide an API schema for your action group:
97
+
98
+ From a local asset file (requires binding to scope):
99
+
100
+ ```ts fixture=default
101
+ const actionGroupFunction = new lambda.Function(this, 'ActionGroupFunction', {
102
+ runtime: lambda.Runtime.PYTHON_3_12,
103
+ handler: 'index.handler',
104
+ code: lambda.Code.fromAsset(path.join(__dirname, '../lambda/action-group')),
105
+ });
106
+
107
+ // When using ApiSchema.fromLocalAsset, you must bind the schema to a scope
108
+ const schema = bedrock.ApiSchema.fromLocalAsset(path.join(__dirname, 'action-group.yaml'));
109
+ schema.bind(this);
110
+
111
+ const actionGroup = new bedrock.AgentActionGroup({
112
+ name: 'query-library',
113
+ description: 'Use these functions to get information about the books in the library.',
114
+ executor: bedrock.ActionGroupExecutor.fromLambda(actionGroupFunction),
115
+ enabled: true,
116
+ apiSchema: schema,
117
+ });
118
+
119
+ const agent = new bedrock.Agent(this, 'Agent', {
120
+ foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
121
+ instruction: 'You are a helpful and friendly agent that answers questions about literature.',
122
+ });
123
+
124
+ agent.addActionGroup(actionGroup);
125
+ ```
126
+
127
+ From an inline OpenAPI schema:
128
+
129
+ ```ts fixture=default
130
+ const inlineSchema = bedrock.ApiSchema.fromInline(`
131
+ openapi: 3.0.3
132
+ info:
133
+ title: Library API
134
+ version: 1.0.0
135
+ paths:
136
+ /search:
137
+ get:
138
+ summary: Search for books
139
+ operationId: searchBooks
140
+ parameters:
141
+ - name: query
142
+ in: query
143
+ required: true
144
+ schema:
145
+ type: string
146
+ `);
147
+
148
+ const actionGroupFunction = new lambda.Function(this, 'ActionGroupFunction', {
149
+ runtime: lambda.Runtime.PYTHON_3_12,
150
+ handler: 'index.handler',
151
+ code: lambda.Code.fromAsset(path.join(__dirname, '../lambda/action-group')),
152
+ });
153
+
154
+ const actionGroup = new bedrock.AgentActionGroup({
155
+ name: 'query-library',
156
+ description: 'Use these functions to get information about the books in the library.',
157
+ executor: bedrock.ActionGroupExecutor.fromLambda(actionGroupFunction),
158
+ enabled: true,
159
+ apiSchema: inlineSchema,
160
+ });
161
+
162
+ const agent = new bedrock.Agent(this, 'Agent', {
163
+ foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
164
+ instruction: 'You are a helpful and friendly agent that answers questions about literature.',
165
+ });
166
+
167
+ agent.addActionGroup(actionGroup);
168
+ ```
169
+
170
+ From an existing S3 file:
171
+
172
+ ```ts fixture=default
173
+ const bucket = s3.Bucket.fromBucketName(this, 'ExistingBucket', 'my-schema-bucket');
174
+ const s3Schema = bedrock.ApiSchema.fromS3File(bucket, 'schemas/action-group.yaml');
175
+
176
+ const actionGroupFunction = new lambda.Function(this, 'ActionGroupFunction', {
177
+ runtime: lambda.Runtime.PYTHON_3_12,
178
+ handler: 'index.handler',
179
+ code: lambda.Code.fromAsset(path.join(__dirname, '../lambda/action-group')),
180
+ });
181
+
182
+ const actionGroup = new bedrock.AgentActionGroup({
183
+ name: 'query-library',
184
+ description: 'Use these functions to get information about the books in the library.',
185
+ executor: bedrock.ActionGroupExecutor.fromLambda(actionGroupFunction),
186
+ enabled: true,
187
+ apiSchema: s3Schema,
188
+ });
189
+
190
+ const agent = new bedrock.Agent(this, 'Agent', {
191
+ foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
192
+ instruction: 'You are a helpful and friendly agent that answers questions about literature.',
193
+ });
194
+
195
+ agent.addActionGroup(actionGroup);
196
+ ```
197
+
198
+ ### Using FunctionSchema with Action Groups
199
+
200
+ As an alternative to using OpenAPI schemas, you can define functions directly using the `FunctionSchema` class. This approach provides a more structured way to define the functions that your agent can call.
201
+
202
+ ```ts fixture=default
203
+ const actionGroupFunction = new lambda.Function(this, 'ActionGroupFunction', {
204
+ runtime: lambda.Runtime.PYTHON_3_12,
205
+ handler: 'index.handler',
206
+ code: lambda.Code.fromAsset(path.join(__dirname, '../lambda/action-group')),
207
+ });
208
+
209
+ // Define a function schema with parameters
210
+ const functionSchema = new bedrock.FunctionSchema({
211
+ functions: [
212
+ {
213
+ name: 'searchBooks',
214
+ description: 'Search for books in the library catalog',
215
+ parameters: {
216
+ 'query': {
217
+ type: bedrock.ParameterType.STRING,
218
+ required: true,
219
+ description: 'The search query string',
220
+ },
221
+ 'maxResults': {
222
+ type: bedrock.ParameterType.INTEGER,
223
+ required: false,
224
+ description: 'Maximum number of results to return',
225
+ },
226
+ 'includeOutOfPrint': {
227
+ type: bedrock.ParameterType.BOOLEAN,
228
+ required: false,
229
+ description: 'Whether to include out-of-print books',
230
+ }
231
+ },
232
+ requireConfirmation: bedrock.RequireConfirmation.DISABLED,
233
+ },
234
+ {
235
+ name: 'getBookDetails',
236
+ description: 'Get detailed information about a specific book',
237
+ parameters: {
238
+ 'bookId': {
239
+ type: bedrock.ParameterType.STRING,
240
+ required: true,
241
+ description: 'The unique identifier of the book',
242
+ }
243
+ },
244
+ requireConfirmation: bedrock.RequireConfirmation.ENABLED,
245
+ }
246
+ ]
247
+ });
248
+
249
+ // Create an action group using the function schema
250
+ const actionGroup = new bedrock.AgentActionGroup({
251
+ name: 'library-functions',
252
+ description: 'Functions for interacting with the library catalog',
253
+ executor: bedrock.ActionGroupExecutor.fromLambda(actionGroupFunction),
254
+ functionSchema: functionSchema,
255
+ enabled: true,
256
+ });
257
+
258
+ const agent = new bedrock.Agent(this, 'Agent', {
259
+ foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
260
+ instruction: 'You are a helpful and friendly agent that answers questions about literature.',
261
+ actionGroups: [actionGroup],
262
+ });
263
+ ```
264
+
265
+ The `FunctionSchema` approach offers several advantages:
266
+
267
+ - Type-safe definition of functions and parameters
268
+ - Built-in validation of parameter names, descriptions, and other properties
269
+ - Clear structure that maps directly to the AWS Bedrock API
270
+ - Support for parameter types including string, number, integer, boolean, array, and object
271
+ - Option to require user confirmation before executing specific functions
272
+
273
+ If you chose to load your schema file from S3, the construct will provide the necessary permissions to your agent's execution role to access the schema file from the specific bucket. Similar to performing the operation through the console, the agent execution role will get a permission like:
274
+
275
+ ```json
276
+ {
277
+ "Version": "2012-10-17",
278
+ "Statement": [
279
+ {
280
+ "Sid": "AmazonBedrockAgentS3PolicyProd",
281
+ "Effect": "Allow",
282
+ "Action": [
283
+ "s3:GetObject"
284
+ ],
285
+ "Resource": [
286
+ "arn:aws:s3:::<BUCKET_NAME>/<OBJECT_KEY>"
287
+ ],
288
+ "Condition": {
289
+ "StringEquals": {
290
+ "aws:ResourceAccount": "ACCOUNT_NUMBER"
291
+ }
292
+ }
293
+ }
294
+ ]
295
+ }
296
+ ```
297
+
298
+ ```ts fixture=default
299
+ // create a bucket containing the input schema
300
+ const schemaBucket = new s3.Bucket(this, 'SchemaBucket', {
301
+ enforceSSL: true,
302
+ versioned: true,
303
+ publicReadAccess: false,
304
+ blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
305
+ encryption: s3.BucketEncryption.S3_MANAGED,
306
+ removalPolicy: RemovalPolicy.DESTROY,
307
+ autoDeleteObjects: true,
308
+ });
309
+
310
+ // deploy the local schema file to S3
311
+ const deployement = new aws_s3_deployment.BucketDeployment(this, 'DeployWebsite', {
312
+ sources: [aws_s3_deployment.Source.asset(path.join(__dirname, '../inputschema'))],
313
+ destinationBucket: schemaBucket,
314
+ destinationKeyPrefix: 'inputschema',
315
+ });
316
+
317
+ // create the agent
318
+ const agent = new bedrock.Agent(this, 'Agent', {
319
+ foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
320
+ instruction: 'You are a helpful and friendly agent that answers questions about literature.',
321
+ userInputEnabled: true,
322
+ shouldPrepareAgent:true
323
+ });
324
+
325
+ // create a lambda function
326
+ const actionGroupFunction = new lambda.Function(this, 'ActionGroupFunction', {
327
+ runtime: lambda.Runtime.PYTHON_3_12,
328
+ handler: 'index.handler',
329
+ code: lambda.Code.fromAsset(path.join(__dirname, '../lambda/action-group')),
330
+ });
331
+
332
+ // create an action group and read the schema file from S3
333
+ const actionGroup = new bedrock.AgentActionGroup({
334
+ name: 'query-library',
335
+ description: 'Use these functions to get information about the books in the library.',
336
+ executor: bedrock.ActionGroupExecutor.fromLambda(actionGroupFunction),
337
+ enabled: true,
338
+ apiSchema: bedrock.ApiSchema.fromS3File(schemaBucket, 'inputschema/action-group.yaml'),
339
+ });
340
+
341
+ // add the action group to the agent
342
+ agent.addActionGroup(actionGroup);
343
+
344
+ // add dependency for the agent on the s3 deployment
345
+ agent.node.addDependency(deployement);
346
+ ```
347
+
348
+ ### Prepare the Agent
349
+
350
+ The `Agent` constructs take an optional parameter `shouldPrepareAgent` to indicate that the Agent should be prepared after any updates to an agent or action group. This may increase the time to create and update those resources. By default, this value is false.
351
+
352
+ #### Prepare Agent Properties
353
+
354
+ | Name | Type | Required | Description |
355
+ |---|---|---|---|
356
+ | shouldPrepareAgent | boolean | No | Whether to automatically update the DRAFT version of the agent after making changes. Defaults to false |
357
+
358
+ Creating an agent alias will not prepare the agent, so if you create an alias using the `AgentAlias` resource then you should set `shouldPrepareAgent` to **_true_**.
359
+
360
+ ### Prompt Override Configuration
361
+
362
+ Bedrock Agents allows you to customize the prompts and LLM configuration for different steps in the agent sequence. The implementation provides type-safe configurations for each step type, ensuring correct usage at compile time.
363
+
364
+ #### Prompt Override Configuration Properties
365
+
366
+ | Name | Type | Required | Description |
367
+ |---|---|---|---|
368
+ | steps | PromptStepConfiguration[] | Yes | Array of step configurations for different parts of the agent sequence |
369
+ | parser | lambda.IFunction | No | Lambda function for custom parsing of agent responses |
370
+
371
+ #### Prompt Step Configuration Properties
372
+
373
+ Each step in the `steps` array supports the following properties:
374
+
375
+ | Name | Type | Required | Description |
376
+ |---|---|---|---|
377
+ | stepType | AgentStepType | Yes | The type of step being configured (PRE_PROCESSING, ORCHESTRATION, POST_PROCESSING, ROUTING_CLASSIFIER, MEMORY_SUMMARIZATION, KNOWLEDGE_BASE_RESPONSE_GENERATION) |
378
+ | stepEnabled | boolean | No | Whether this step is enabled. Defaults to true |
379
+ | customPromptTemplate | string | No | Custom prompt template to use for this step |
380
+ | inferenceConfig | InferenceConfiguration | No | Configuration for model inference parameters |
381
+ | foundationModel | BedrockFoundationModel | No | Alternative foundation model to use for this step (only valid for ROUTING_CLASSIFIER step) |
382
+ | useCustomParser | boolean | No | Whether to use a custom parser for this step. Requires parser to be provided in PromptOverrideConfiguration |
383
+
384
+ #### Inference Configuration Properties
385
+
386
+ When providing `inferenceConfig`, the following properties are supported:
387
+
388
+ | Name | Type | Required | Description |
389
+ |---|---|---|---|
390
+ | temperature | number | No | Controls randomness in the model's output (0.0-1.0) |
391
+ | topP | number | No | Controls diversity via nucleus sampling (0.0-1.0) |
392
+ | topK | number | No | Controls diversity by limiting the cumulative probability |
393
+ | maximumLength | number | No | Maximum length of generated text |
394
+ | stopSequences | string[] | No | Sequences where the model should stop generating |
395
+
396
+ The following steps can be configured:
397
+
398
+ - PRE_PROCESSING: Prepares the user input for orchestration
399
+ - ORCHESTRATION: Main step that determines the agent's actions
400
+ - POST_PROCESSING: Refines the agent's response
401
+ - ROUTING_CLASSIFIER: Classifies and routes requests to appropriate collaborators
402
+ - MEMORY_SUMMARIZATION: Summarizes conversation history for memory retention
403
+ - KNOWLEDGE_BASE_RESPONSE_GENERATION: Generates responses using knowledge base content
404
+
405
+ Example with pre-processing configuration:
406
+
407
+ ```ts fixture=default
408
+ const agent = new bedrock.Agent(this, 'Agent', {
409
+ foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
410
+ instruction: 'You are a helpful assistant.',
411
+ promptOverrideConfiguration: bedrock.PromptOverrideConfiguration.fromSteps([
412
+ {
413
+ stepType: bedrock.AgentStepType.PRE_PROCESSING,
414
+ stepEnabled: true,
415
+ customPromptTemplate: 'Your custom prompt template here',
416
+ inferenceConfig: {
417
+ temperature: 0.0,
418
+ topP: 1,
419
+ topK: 250,
420
+ maximumLength: 1,
421
+ stopSequences: ["\n\nHuman:"],
422
+ },
423
+ }
424
+ ])
425
+ });
426
+ ```
427
+
428
+ Example with routing classifier and foundation model:
429
+
430
+ ```ts fixture=default
431
+ const agent = new bedrock.Agent(this, 'Agent', {
432
+ foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
433
+ instruction: 'You are a helpful assistant.',
434
+ promptOverrideConfiguration: bedrock.PromptOverrideConfiguration.fromSteps([
435
+ {
436
+ stepType: bedrock.AgentStepType.ROUTING_CLASSIFIER,
437
+ stepEnabled: true,
438
+ customPromptTemplate: 'Your routing template here',
439
+ foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_V2
440
+ } as bedrock.PromptRoutingClassifierConfigCustomParser
441
+ ])
442
+ });
443
+ ```
444
+
445
+ Using a custom Lambda parser:
446
+
447
+ ```ts fixture=default
448
+ const parserFunction = new lambda.Function(this, 'ParserFunction', {
449
+ runtime: lambda.Runtime.PYTHON_3_10,
450
+ handler: 'index.handler',
451
+ code: lambda.Code.fromAsset('lambda'),
452
+ });
453
+
454
+ const agent = new bedrock.Agent(this, 'Agent', {
455
+ foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
456
+ instruction: 'You are a helpful assistant.',
457
+ promptOverrideConfiguration: bedrock.PromptOverrideConfiguration.withCustomParser({
458
+ parser: parserFunction,
459
+ preProcessingStep: {
460
+ stepType: bedrock.AgentStepType.PRE_PROCESSING,
461
+ useCustomParser: true
462
+ }
463
+ })
464
+ });
465
+ ```
466
+
467
+ Foundation models can only be specified for the ROUTING_CLASSIFIER step.
468
+
469
+ ### Memory Configuration
470
+
471
+ Agents can maintain context across multiple sessions and recall past interactions using memory. This feature is useful for creating a more coherent conversational experience.
472
+
473
+ #### Memory Configuration Properties
474
+
475
+ | Name | Type | Required | Description |
476
+ |---|---|---|---|
477
+ | maxRecentSessions | number | No | Maximum number of recent session summaries to retain |
478
+ | memoryDuration | Duration | No | How long to retain session summaries |
479
+
480
+ Example:
481
+
482
+ ```ts fixture=default
483
+ const agent = new bedrock.Agent(this, 'MyAgent', {
484
+ agentName: 'MyAgent',
485
+ instruction: 'Your instruction here',
486
+ foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
487
+ memory: Memory.sessionSummary({
488
+ maxRecentSessions: 10, // Keep the last 10 session summaries
489
+ memoryDuration: Duration.days(20), // Retain summaries for 20 days
490
+ }),
491
+ });
492
+ ```
493
+
494
+ ### Agent Collaboration
495
+
496
+ Agent Collaboration enables multiple Bedrock Agents to work together on complex tasks. This feature allows agents to specialize in different areas and collaborate to provide more comprehensive responses to user queries.
497
+
498
+ #### Agent Collaboration Properties
499
+
500
+ | Name | Type | Required | Description |
501
+ |---|---|---|---|
502
+ | type | AgentCollaboratorType | Yes | Type of collaboration (SUPERVISOR or PEER) |
503
+ | collaborators | AgentCollaborator[] | Yes | List of agent collaborators |
504
+
505
+ #### Agent Collaborator Properties
506
+
507
+ | Name | Type | Required | Description |
508
+ |---|---|---|---|
509
+ | agentAlias | AgentAlias | Yes | The agent alias to collaborate with |
510
+ | collaborationInstruction | string | Yes | Instructions for how to collaborate with this agent |
511
+ | collaboratorName | string | Yes | Name of the collaborator |
512
+ | relayConversationHistory | boolean | No | Whether to relay conversation history to the collaborator. Defaults to false |
513
+
514
+ Example:
515
+
516
+ ```ts fixture=default
517
+ // Create a specialized agent
518
+ const customerSupportAgent = new bedrock.Agent(this, 'CustomerSupportAgent', {
519
+ instruction: 'You specialize in answering customer support questions.',
520
+ foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
521
+ });
522
+
523
+ // Create an agent alias
524
+ const customerSupportAlias = new bedrock.AgentAlias(this, 'CustomerSupportAlias', {
525
+ agent: customerSupportAgent,
526
+ agentAliasName: 'production',
527
+ });
528
+
529
+ // Create a main agent that collaborates with the specialized agent
530
+ const mainAgent = new bedrock.Agent(this, 'MainAgent', {
531
+ instruction: 'You route specialized questions to other agents.',
532
+ foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
533
+ agentCollaboration: {
534
+ type: bedrock.AgentCollaboratorType.SUPERVISOR,
535
+ collaborators: [
536
+ new bedrock.AgentCollaborator({
537
+ agentAlias: customerSupportAlias,
538
+ collaborationInstruction: 'Route customer support questions to this agent.',
539
+ collaboratorName: 'CustomerSupport',
540
+ relayConversationHistory: true
541
+ }),
542
+ ],
543
+ },
544
+ });
545
+ ```
546
+
547
+ ### Custom Orchestration
548
+
549
+ Custom Orchestration allows you to override the default agent orchestration flow with your own Lambda function. This enables more control over how the agent processes user inputs and invokes action groups.
550
+
551
+ When you provide a customOrchestrationExecutor, the agent's orchestrationType is automatically set to CUSTOM_ORCHESTRATION. If no customOrchestrationExecutor is provided, the orchestrationType defaults to DEFAULT, using Amazon Bedrock's built-in orchestration.
552
+
553
+ #### Custom Orchestration Properties
554
+
555
+ | Name | Type | Required | Description |
556
+ |---|---|---|---|
557
+ | function | lambda.IFunction | Yes | The Lambda function that implements the custom orchestration logic |
558
+
559
+ Example:
560
+
561
+ ```ts fixture=default
562
+ const orchestrationFunction = new lambda.Function(this, 'OrchestrationFunction', {
563
+ runtime: lambda.Runtime.PYTHON_3_10,
564
+ handler: 'index.handler',
565
+ code: lambda.Code.fromAsset('lambda/orchestration'),
566
+ });
567
+
568
+ const agent = new bedrock.Agent(this, 'CustomOrchestrationAgent', {
569
+ instruction: 'You are a helpful assistant with custom orchestration logic.',
570
+ foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
571
+ customOrchestrationExecutor: bedrock.CustomOrchestrationExecutor.fromLambda(orchestrationFunction),
572
+ });
573
+ ```
574
+
575
+ ### Agent Alias
576
+
577
+ After you have sufficiently iterated on your working draft and are satisfied with the behavior of your agent, you can set it up for deployment and integration into your application by creating aliases.
578
+
579
+ To deploy your agent, you need to create an alias. During alias creation, Amazon Bedrock automatically creates a version of your agent. The alias points to this newly created version. You can point the alias to a previously created version if necessary. You then configure your application to make API calls to that alias.
580
+
581
+ By default, the Agent resource creates a test alias named 'AgentTestAlias' that points to the 'DRAFT' version. This test alias is accessible via the `testAlias` property of the agent. You can also create additional aliases for different environments using the AgentAlias construct.
582
+
583
+ #### Agent Alias Properties
584
+
585
+ | Name | Type | Required | Description |
586
+ |---|---|---|---|
587
+ | agent | Agent | Yes | The agent to create an alias for |
588
+ | agentAliasName | string | No | The name of the agent alias. Defaults to a name generated by CDK |
589
+ | description | string | No | A description of the agent alias. Defaults to no description |
590
+ | routingConfiguration | AgentAliasRoutingConfiguration | No | Configuration for routing traffic between agent versions |
591
+ | agentVersion | string | No | The version of the agent to use. If not specified, a new version is created |
592
+
593
+ When redeploying an agent with changes, you must ensure the agent version is updated to avoid deployment failures with "agent already exists" errors. The recommended way to handle this is to include the `lastUpdated` property in the agent's description, which automatically updates whenever the agent is modified. This ensures a new version is created on each deployment.
594
+
595
+ Example:
596
+
597
+ ```ts fixture=default
598
+ const agent = new bedrock.Agent(this, 'Agent', {
599
+ foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
600
+ instruction: 'You are a helpful and friendly agent that answers questions about literature.',
601
+ });
602
+
603
+ const agentAlias = new bedrock.AgentAlias(this, 'myAlias', {
604
+ agentAliasName: 'production',
605
+ agent: agent,
606
+ description: `Production version of my agent. Created at ${agent.lastUpdated}` // ensure the version update
607
+ });
608
+ ```