awslabs.cdk-mcp-server 0.1.1__py3-none-any.whl → 0.1.3__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.
- awslabs/cdk_mcp_server/core/resources.py +104 -15
- awslabs/cdk_mcp_server/core/server.py +4 -3
- awslabs/cdk_mcp_server/core/tools.py +6 -1
- awslabs/cdk_mcp_server/data/genai_cdk_loader.py +508 -349
- {awslabs_cdk_mcp_server-0.1.1.dist-info → awslabs_cdk_mcp_server-0.1.3.dist-info}/METADATA +24 -1
- awslabs_cdk_mcp_server-0.1.3.dist-info/RECORD +33 -0
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/agent/actiongroups.md +0 -137
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/agent/alias.md +0 -39
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/agent/collaboration.md +0 -91
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/agent/creation.md +0 -149
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/agent/custom_orchestration.md +0 -74
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/agent/overview.md +0 -78
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/agent/prompt_override.md +0 -70
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/bedrockguardrails.md +0 -188
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/knowledgebases/chunking.md +0 -137
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/knowledgebases/datasources.md +0 -225
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/knowledgebases/kendra.md +0 -81
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/knowledgebases/overview.md +0 -116
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/knowledgebases/parsing.md +0 -36
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/knowledgebases/transformation.md +0 -30
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/knowledgebases/vector/aurora.md +0 -185
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/knowledgebases/vector/creation.md +0 -80
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/knowledgebases/vector/opensearch.md +0 -56
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/knowledgebases/vector/pinecone.md +0 -66
- awslabs/cdk_mcp_server/static/genai_cdk/bedrock/profiles.md +0 -153
- awslabs/cdk_mcp_server/static/genai_cdk/opensearch-vectorindex/overview.md +0 -135
- awslabs/cdk_mcp_server/static/genai_cdk/opensearchserverless/overview.md +0 -17
- awslabs_cdk_mcp_server-0.1.1.dist-info/RECORD +0 -54
- {awslabs_cdk_mcp_server-0.1.1.dist-info → awslabs_cdk_mcp_server-0.1.3.dist-info}/WHEEL +0 -0
- {awslabs_cdk_mcp_server-0.1.1.dist-info → awslabs_cdk_mcp_server-0.1.3.dist-info}/entry_points.txt +0 -0
- {awslabs_cdk_mcp_server-0.1.1.dist-info → awslabs_cdk_mcp_server-0.1.3.dist-info}/licenses/LICENSE +0 -0
- {awslabs_cdk_mcp_server-0.1.1.dist-info → awslabs_cdk_mcp_server-0.1.3.dist-info}/licenses/NOTICE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: awslabs.cdk-mcp-server
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: An AWS CDK MCP server that provides guidance on AWS Cloud Development Kit best practices, infrastructure as code patterns, and security compliance with CDK Nag. This server offers tools to validate infrastructure designs, explain CDK Nag rules, analyze suppressions, generate Bedrock Agent schemas, and discover Solutions Constructs patterns.
|
|
5
5
|
Project-URL: Homepage, https://awslabs.github.io/mcp/
|
|
6
6
|
Project-URL: Documentation, https://awslabs.github.io/mcp/servers/cdk-mcp-server/
|
|
@@ -186,6 +186,29 @@ Here are some ways you can work with MCP across AWS, and we'll be adding support
|
|
|
186
186
|
}
|
|
187
187
|
```
|
|
188
188
|
|
|
189
|
+
or docker after a succesful `docker build -t awslabs/cdk-mcp-server .`:
|
|
190
|
+
|
|
191
|
+
```json
|
|
192
|
+
{
|
|
193
|
+
"mcpServers": {
|
|
194
|
+
"awslabs.cdk-mcp-server": {
|
|
195
|
+
"command": "docker",
|
|
196
|
+
"args": [
|
|
197
|
+
"run",
|
|
198
|
+
"--rm",
|
|
199
|
+
"--interactive",
|
|
200
|
+
"--env",
|
|
201
|
+
"FASTMCP_LOG_LEVEL=ERROR",
|
|
202
|
+
"awslabs/cdk-mcp-server:latest"
|
|
203
|
+
],
|
|
204
|
+
"env": {},
|
|
205
|
+
"disabled": false,
|
|
206
|
+
"autoApprove": []
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
189
212
|
## Security Considerations
|
|
190
213
|
|
|
191
214
|
When using this MCP server, you should consider:
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
awslabs/__init__.py,sha256=CyFUCiG6C9srM7h_p6i9w72Y_G53m4QN-jK0duBu948,558
|
|
2
|
+
awslabs/cdk_mcp_server/__init__.py,sha256=tE_wgU3b_iQUzMy9HlAJUehazMBzM9hGM94kDKPEDq4,748
|
|
3
|
+
awslabs/cdk_mcp_server/server.py,sha256=Mom-3sv93jLG-KdESEfbrIEo3isXdAMhHcyTxANFtBw,693
|
|
4
|
+
awslabs/cdk_mcp_server/core/__init__.py,sha256=P5jMlOb_nAqCEM22QnIe9RZMUCLVHwmAnwqJInvcQfc,605
|
|
5
|
+
awslabs/cdk_mcp_server/core/resources.py,sha256=-JQijnp64JYmd7Nt4SAZ4f9gsS93R3pSNqM8ZsZTuf0,13662
|
|
6
|
+
awslabs/cdk_mcp_server/core/search_utils.py,sha256=GLaNJBFzmDgwM8OY98R4VHfgj2Cw7GEBk-Y2lLZcPjM,6144
|
|
7
|
+
awslabs/cdk_mcp_server/core/server.py,sha256=k0f7wvOuBebMZVeZA1bLDohCsjNH2IwZqZPPg3QBpSo,3288
|
|
8
|
+
awslabs/cdk_mcp_server/core/tools.py,sha256=WZdR7K5Ilv9xlcwhQf4ZCdeIgUcA-Gb-NubEhTSc8IU,22007
|
|
9
|
+
awslabs/cdk_mcp_server/data/__init__.py,sha256=8o7-TnXbiVvfwc_xc6LGnDfERnD9GMPRFfnWcgf--0Y,605
|
|
10
|
+
awslabs/cdk_mcp_server/data/cdk_nag_parser.py,sha256=AKJU0O9lkzeVLAElzgBkV7rpKNUktywIXwmA52m3Vec,11477
|
|
11
|
+
awslabs/cdk_mcp_server/data/construct_descriptions.py,sha256=CBfKFM_pJo6Sn_NA7hr-0oVB8piXdncQ_A5ewnTCx30,3164
|
|
12
|
+
awslabs/cdk_mcp_server/data/genai_cdk_loader.py,sha256=xBEdhT5GVNom7lN0Vshm2y-P3yZJGNU7S_qL0UUHWxY,21516
|
|
13
|
+
awslabs/cdk_mcp_server/data/lambda_layer_parser.py,sha256=TWInqjN56Vkhs-sXqLnIvhAPCBbq3Zlm1bAerUGb1cQ,8611
|
|
14
|
+
awslabs/cdk_mcp_server/data/lambda_powertools_loader.py,sha256=XtJb8tTYhmAQ6Ulor6nhKWLQ56aIh2eElpBuw2D9sco,2411
|
|
15
|
+
awslabs/cdk_mcp_server/data/schema_generator.py,sha256=eAjLnok3dqxnf3PtnwRno_Ps24ZZTo2iJcBv1H23sE0,29269
|
|
16
|
+
awslabs/cdk_mcp_server/data/solutions_constructs_parser.py,sha256=NVOKV0cZl-9PdyoRtPo2JspSAEbCdebE8XR10dpCxyE,28243
|
|
17
|
+
awslabs/cdk_mcp_server/static/CDK_GENERAL_GUIDANCE.md,sha256=-O0LIpmeDXr1JoVxxbQnVp0oNqvSbX20xOgcZqknr_c,8532
|
|
18
|
+
awslabs/cdk_mcp_server/static/CDK_NAG_GUIDANCE.md,sha256=zJtHJp9ruaaJ-xa68k9kDrPmEaXpiWCZZf7JIy8NK0w,5839
|
|
19
|
+
awslabs/cdk_mcp_server/static/__init__.py,sha256=NqWI8Mnqoc_sEr70ZtQ_oI6W_mdhuRCmgIbgmIWljzU,858
|
|
20
|
+
awslabs/cdk_mcp_server/static/lambda_powertools/bedrock.md,sha256=vxYfQvp2UcXSszAB4oQQ7xPY808WjKSPRgOnIA31nLk,4114
|
|
21
|
+
awslabs/cdk_mcp_server/static/lambda_powertools/cdk.md,sha256=rcYvoKOEj9R2Ptd5H61spys8j09nLgmpkD_o2niynvs,1900
|
|
22
|
+
awslabs/cdk_mcp_server/static/lambda_powertools/dependencies.md,sha256=nZ2Fv54rG1rUmD_YHkM9h5VNvB81-Hk8Qx3ZNQSFZLY,1520
|
|
23
|
+
awslabs/cdk_mcp_server/static/lambda_powertools/index.md,sha256=yivjInZAZ3tENKGrrAv7geICzUvKUTskWuaNj9nuPbI,1819
|
|
24
|
+
awslabs/cdk_mcp_server/static/lambda_powertools/insights.md,sha256=jcyOHZvKHk2CgJwIu0B5SkP1SRMAhIOQ4FtWHlUs_IE,3212
|
|
25
|
+
awslabs/cdk_mcp_server/static/lambda_powertools/logging.md,sha256=6CSgD8QB3Bs4s_x4RnbKwZoWvG6aG4etCnmDH6HU9XY,1797
|
|
26
|
+
awslabs/cdk_mcp_server/static/lambda_powertools/metrics.md,sha256=DQlznxRizJep8jphzFgbk7crH5LwWjSjdygP-1K6mxk,2559
|
|
27
|
+
awslabs/cdk_mcp_server/static/lambda_powertools/tracing.md,sha256=Q3dSCvgktb9sUsuuQ5ONU2Qdb1OTwbNOYpK--MDzBNw,2539
|
|
28
|
+
awslabs_cdk_mcp_server-0.1.3.dist-info/METADATA,sha256=y17PsKmht9QeE03mOHreaqnlTrG4uJnX-cuWxeT8y6I,9134
|
|
29
|
+
awslabs_cdk_mcp_server-0.1.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
30
|
+
awslabs_cdk_mcp_server-0.1.3.dist-info/entry_points.txt,sha256=LertzmID_mUU1YYZPySAF1IY1zE7ySTvzFxiGyo3VjY,78
|
|
31
|
+
awslabs_cdk_mcp_server-0.1.3.dist-info/licenses/LICENSE,sha256=CeipvOyAZxBGUsFoaFqwkx54aPnIKEtm9a5u2uXxEws,10142
|
|
32
|
+
awslabs_cdk_mcp_server-0.1.3.dist-info/licenses/NOTICE,sha256=MNXNmhkltaxAzlo-r5BhjfS30nUE7I_w7cyDY8cxDL0,90
|
|
33
|
+
awslabs_cdk_mcp_server-0.1.3.dist-info/RECORD,,
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
# Action Groups
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
Action groups define functions your agent can call, connecting Bedrock Agents to your business logic via Lambda functions. The agent uses an OpenAPI schema to understand what your functions do and how to call them.
|
|
6
|
-
|
|
7
|
-
```mermaid
|
|
8
|
-
graph LR
|
|
9
|
-
A[Agent] --> B[Action Group]
|
|
10
|
-
B --> C[Lambda Function]
|
|
11
|
-
B --> D[OpenAPI Schema]
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Action Group Properties
|
|
15
|
-
|
|
16
|
-
| Name | Type | Required | Description |
|
|
17
|
-
|---|---|---|---|
|
|
18
|
-
| name | string | Yes | The name of the action group |
|
|
19
|
-
| description | string | No | A description of the action group |
|
|
20
|
-
| apiSchema | ApiSchema | No | The API Schema |
|
|
21
|
-
| executor | ActionGroupExecutor | No | The action group executor |
|
|
22
|
-
| 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 |
|
|
23
|
-
| forceDelete | boolean | No | Specifies whether to delete the resource even if it's in use. Defaults to false |
|
|
24
|
-
| functionSchema | CfnAgent.FunctionSchemaProperty | No | Defines functions that each define parameters that the agent needs to invoke from the user |
|
|
25
|
-
| parentActionGroupSignature | ParentActionGroupSignature | No | The AWS Defined signature for enabling certain capabilities in your agent. When specified, description, apiSchema, and actionGroupExecutor must be blank |
|
|
26
|
-
|
|
27
|
-
## OpenAPI Schema Generation & Best Practices
|
|
28
|
-
|
|
29
|
-
For Action Groups, use the built-in OpenAPI schema generation tool provided by the AWS CDK MCP server:
|
|
30
|
-
|
|
31
|
-
```typescript
|
|
32
|
-
// Using MCP client
|
|
33
|
-
const result = await use_mcp_tool({
|
|
34
|
-
server_name: "awslabs.cdk-mcp-server",
|
|
35
|
-
tool_name: "GenerateBedrockAgentSchema",
|
|
36
|
-
arguments: {
|
|
37
|
-
lambda_code_path: "path/to/your/lambda.py",
|
|
38
|
-
output_path: "path/to/output/openapi.json"
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
The tool will:
|
|
44
|
-
|
|
45
|
-
1. Parse your Lambda function code
|
|
46
|
-
2. Extract function signatures and docstrings
|
|
47
|
-
3. Generate a Bedrock-compatible OpenAPI schema
|
|
48
|
-
4. Save it to the specified output path
|
|
49
|
-
|
|
50
|
-
### Key Requirements
|
|
51
|
-
- Ensure each operation has a unique operationId
|
|
52
|
-
- Define complete response schemas
|
|
53
|
-
- Use `fromLocalAsset` (not `fromAsset`) for API schemas
|
|
54
|
-
- Include detailed descriptions for all endpoints, parameters, and return values
|
|
55
|
-
- Use proper type annotations with Python type hints
|
|
56
|
-
|
|
57
|
-
### Lambda Function Example
|
|
58
|
-
|
|
59
|
-
```python
|
|
60
|
-
from aws_lambda_powertools.event_handler import BedrockAgentResolver
|
|
61
|
-
from typing import Annotated, List
|
|
62
|
-
from aws_lambda_powertools.event_handler.openapi.params import Query, Path
|
|
63
|
-
from pydantic import BaseModel, Field
|
|
64
|
-
|
|
65
|
-
app = BedrockAgentResolver()
|
|
66
|
-
|
|
67
|
-
class Product(BaseModel):
|
|
68
|
-
product_id: str = Field(description="Unique product identifier")
|
|
69
|
-
name: str = Field(description="Product name")
|
|
70
|
-
price: float = Field(description="Product price in USD")
|
|
71
|
-
|
|
72
|
-
@app.get("/products", description="List available products")
|
|
73
|
-
def list_products(
|
|
74
|
-
category: Annotated[str, Query(description="Product category")] = None
|
|
75
|
-
) -> List[Product]:
|
|
76
|
-
# Your business logic here
|
|
77
|
-
return [Product(product_id="1", name="Product A", price=19.99)]
|
|
78
|
-
|
|
79
|
-
def lambda_handler(event, context):
|
|
80
|
-
return app.resolve(event, context)
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Examples
|
|
84
|
-
|
|
85
|
-
### TypeScript
|
|
86
|
-
|
|
87
|
-
```ts
|
|
88
|
-
const actionGroupFunction = new lambda_python.PythonFunction(this, 'ActionGroupFunction', {
|
|
89
|
-
runtime: lambda.Runtime.PYTHON_3_12,
|
|
90
|
-
entry: path.join(__dirname, '../lambda/action-group'),
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// Example of proper Action Group setup with fromLocalAsset
|
|
94
|
-
const actionGroup = new AgentActionGroup({
|
|
95
|
-
name: 'query-library',
|
|
96
|
-
description: 'Use these functions to get information about the books in the library.',
|
|
97
|
-
executor: bedrock.ActionGroupExecutor.fromlambdaFunction(actionGroupFunction),
|
|
98
|
-
enabled: true,
|
|
99
|
-
apiSchema: bedrock.ApiSchema.fromLocalAsset(path.join(__dirname, 'action-group.yaml')),
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
agent.addActionGroup(actionGroup);
|
|
103
|
-
|
|
104
|
-
// Real-world example with account actions
|
|
105
|
-
const agentAccountActions = new AgentActionGroup({
|
|
106
|
-
name: "agent-account-actions",
|
|
107
|
-
description: "Use these functions to take actions on authenticated user's accounts",
|
|
108
|
-
executor: bedrock.ActionGroupExecutor.fromlambdaFunction(accountActionsLambda),
|
|
109
|
-
apiSchema: bedrock.ApiSchema.fromLocalAsset(
|
|
110
|
-
path.join(agentsLambdaDir, "account_actions", "openapi.json"),
|
|
111
|
-
),
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
agent.addActionGroup(agentAccountActions);
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
### Python
|
|
118
|
-
|
|
119
|
-
```python
|
|
120
|
-
action_group_function = PythonFunction(
|
|
121
|
-
self,
|
|
122
|
-
"LambdaFunction",
|
|
123
|
-
runtime=Runtime.PYTHON_3_12,
|
|
124
|
-
entry="./lambda",
|
|
125
|
-
index="app.py",
|
|
126
|
-
handler="lambda_handler",
|
|
127
|
-
)
|
|
128
|
-
|
|
129
|
-
actionGroup = bedrock.AgentActionGroup(
|
|
130
|
-
name="query-library",
|
|
131
|
-
description="Use these functions to get information about the books in the library.",
|
|
132
|
-
executor= bedrock.ActionGroupExecutor.fromlambda_function(action_group_function),
|
|
133
|
-
enabled=True,
|
|
134
|
-
api_schema=bedrock.ApiSchema.from_local_asset("action-group.yaml"))
|
|
135
|
-
|
|
136
|
-
agent.add_action_group(actionGroup)
|
|
137
|
-
```
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# Agent Alias
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
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 of your agent.
|
|
6
|
-
|
|
7
|
-
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.
|
|
8
|
-
|
|
9
|
-
By default, the `Agent` resource does not create any aliases, and you can use the 'DRAFT' version.
|
|
10
|
-
|
|
11
|
-
## Specific Version
|
|
12
|
-
|
|
13
|
-
You can use the `AgentAlias` resource if you want to create an Alias for an existing Agent.
|
|
14
|
-
|
|
15
|
-
## Example
|
|
16
|
-
|
|
17
|
-
### TypeScript
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
const agentAlias2 = new bedrock.AgentAlias(this, 'myalias2', {
|
|
21
|
-
aliasName: 'myalias',
|
|
22
|
-
agent: agent,
|
|
23
|
-
agentVersion: '1', // optional
|
|
24
|
-
description: 'mytest'
|
|
25
|
-
});
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
### Python
|
|
29
|
-
|
|
30
|
-
```python
|
|
31
|
-
agent_alias_2 = bedrock.AgentAlias(self, 'myalias2',
|
|
32
|
-
alias_name='myalias',
|
|
33
|
-
agent=agent,
|
|
34
|
-
agent_version='1', # optional
|
|
35
|
-
description='mytest'
|
|
36
|
-
)
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
[View full documentation](https://github.com/awslabs/generative-ai-cdk-constructs/blob/main/src/cdk-lib/bedrock/README.md)
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
# Agent Collaboration
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
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.
|
|
6
|
-
|
|
7
|
-
## Collaboration Types
|
|
8
|
-
|
|
9
|
-
You can configure collaboration for an agent using the `agentCollaboration` and `agentCollaborators` properties in the `AgentProps` interface.
|
|
10
|
-
|
|
11
|
-
- **SUPERVISOR**: The agent acts as a supervisor that can delegate tasks to other agents.
|
|
12
|
-
- **SUPERVISOR_ROUTER**: The agent acts as a supervisor that can route requests to specialized agents.
|
|
13
|
-
- **DISABLED**: Collaboration is disabled (default).
|
|
14
|
-
|
|
15
|
-
## Example
|
|
16
|
-
|
|
17
|
-
### TypeScript
|
|
18
|
-
|
|
19
|
-
```typescript
|
|
20
|
-
import { Agent, AgentCollaboratorType, RelayConversationHistoryType } from '@cdklabs/generative-ai-cdk-constructs';
|
|
21
|
-
|
|
22
|
-
// Create a specialized agent for customer support
|
|
23
|
-
const customerSupportAgent = new Agent(this, 'CustomerSupportAgent', {
|
|
24
|
-
name: 'CustomerSupportAgent',
|
|
25
|
-
instruction: 'You specialize in answering customer support questions about our products.',
|
|
26
|
-
foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// Create an agent alias for the specialized agent
|
|
30
|
-
const customerSupportAlias = new AgentAlias(this, 'CustomerSupportAlias', {
|
|
31
|
-
agent: customerSupportAgent,
|
|
32
|
-
aliasName: 'production',
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// Create a main agent that can collaborate with the specialized agent
|
|
36
|
-
const mainAgent = new Agent(this, 'MainAgent', {
|
|
37
|
-
name: 'MainAgent',
|
|
38
|
-
instruction: 'You are a helpful assistant that can answer general questions and route specialized customer support questions to the customer support agent.',
|
|
39
|
-
foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
|
|
40
|
-
agentCollaboration: AgentCollaboratorType.SUPERVISOR,
|
|
41
|
-
agentCollaborators: [
|
|
42
|
-
new bedrock.AgentCollaborator({
|
|
43
|
-
agentAlias: customerSupportAlias,
|
|
44
|
-
collaborationInstruction: 'Route customer support questions to this agent.',
|
|
45
|
-
collaboratorName: 'CustomerSupport',
|
|
46
|
-
relayConversationHistory: true,
|
|
47
|
-
}),
|
|
48
|
-
],
|
|
49
|
-
});
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Python
|
|
53
|
-
|
|
54
|
-
```python
|
|
55
|
-
from cdklabs.generative_ai_cdk_constructs import (
|
|
56
|
-
bedrock,
|
|
57
|
-
AgentCollaboratorType,
|
|
58
|
-
RelayConversationHistoryType
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
# Create a specialized agent for customer support
|
|
62
|
-
customer_support_agent = bedrock.Agent(self, 'CustomerSupportAgent',
|
|
63
|
-
name='CustomerSupportAgent',
|
|
64
|
-
instruction='You specialize in answering customer support questions about our products.',
|
|
65
|
-
foundation_model=bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
# Create an agent alias for the specialized agent
|
|
69
|
-
customer_support_alias = bedrock.AgentAlias(self, 'CustomerSupportAlias',
|
|
70
|
-
agent=customer_support_agent,
|
|
71
|
-
alias_name='production',
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
# Create a main agent that can collaborate with the specialized agent
|
|
75
|
-
main_agent = bedrock.Agent(self, 'MainAgent',
|
|
76
|
-
name='MainAgent',
|
|
77
|
-
instruction='You are a helpful assistant that can answer general questions and route specialized customer support questions to the customer support agent.',
|
|
78
|
-
foundation_model=bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
|
|
79
|
-
agent_collaboration=AgentCollaboratorType.SUPERVISOR,
|
|
80
|
-
agent_collaborators=[
|
|
81
|
-
bedrock.AgentCollaborator(
|
|
82
|
-
agent_alias= customer_support_alias,
|
|
83
|
-
collaboration_instruction= 'Route customer support questions to this agent.',
|
|
84
|
-
collaborator_name= 'CustomerSupport',
|
|
85
|
-
relay_conversation_history= true,
|
|
86
|
-
)
|
|
87
|
-
],
|
|
88
|
-
)
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
For more information on agent collaboration, refer to the [AWS Bedrock documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/agents-collaboration.html).
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
# Agent
|
|
2
|
-
|
|
3
|
-
## Properties
|
|
4
|
-
|
|
5
|
-
| Name | Type | Required | Description |
|
|
6
|
-
|---|---|---|---|
|
|
7
|
-
| name | string | No | The name of the agent. Defaults to a name generated by CDK |
|
|
8
|
-
| instruction | string | Yes | The instruction used by the agent that determines how it will perform its task. Must have a minimum of 40 characters |
|
|
9
|
-
| foundationModel | IInvokable | Yes | The foundation model used for orchestration by the agent |
|
|
10
|
-
| 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 |
|
|
11
|
-
| shouldPrepareAgent | boolean | No | Specifies whether to automatically update the `DRAFT` version of the agent after making changes. Defaults to false |
|
|
12
|
-
| 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 |
|
|
13
|
-
| kmsKey | kms.IKey | No | The KMS key of the agent if custom encryption is configured. Defaults to AWS managed key |
|
|
14
|
-
| description | string | No | A description of the agent. Defaults to no description |
|
|
15
|
-
| knowledgeBases | IKnowledgeBase[] | No | The KnowledgeBases associated with the agent |
|
|
16
|
-
| actionGroups | AgentActionGroup[] | No | The Action Groups associated with the agent |
|
|
17
|
-
| guardrail | IGuardrail | No | The guardrail that will be associated with the agent |
|
|
18
|
-
| promptOverrideConfiguration | PromptOverrideConfiguration | No | Overrides some prompt templates in different parts of an agent sequence configuration |
|
|
19
|
-
| userInputEnabled | boolean | No | Select whether the agent can prompt additional information from the user when it lacks enough information. Defaults to false |
|
|
20
|
-
| codeInterpreterEnabled | boolean | No | Select whether the agent can generate, run, and troubleshoot code when trying to complete a task. Defaults to false |
|
|
21
|
-
| forceDelete | boolean | No | Whether to delete the resource even if it's in use. Defaults to true |
|
|
22
|
-
|
|
23
|
-
## Create an Agent
|
|
24
|
-
|
|
25
|
-
The following example creates an Agent with a simple instruction and default prompts that consults a Knowledge Base.
|
|
26
|
-
|
|
27
|
-
### Example
|
|
28
|
-
|
|
29
|
-
#### TypeScript
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
const agent = new bedrock.Agent(this, 'Agent', {
|
|
33
|
-
foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
|
|
34
|
-
instruction: 'You are a helpful and friendly agent that answers questions about literature.',
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
agent.addKnowledgeBase(kb);
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
#### Python
|
|
41
|
-
|
|
42
|
-
```python
|
|
43
|
-
agent = bedrock.Agent(
|
|
44
|
-
self,
|
|
45
|
-
"Agent",
|
|
46
|
-
foundation_model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
|
|
47
|
-
instruction="You are a helpful and friendly agent that answers questions about insurance claims.",
|
|
48
|
-
)
|
|
49
|
-
agent.add_knowledge_base(kb)
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Enable Cross Region Inference for Supported Models
|
|
53
|
-
|
|
54
|
-
You can also use system defined inference profiles to enable cross region inference requests for supported models. For instance:
|
|
55
|
-
|
|
56
|
-
### Example
|
|
57
|
-
|
|
58
|
-
#### TypeScript
|
|
59
|
-
|
|
60
|
-
```ts
|
|
61
|
-
const cris = bedrock.CrossRegionInferenceProfile.fromConfig({
|
|
62
|
-
geoRegion: bedrock.CrossRegionInferenceProfileRegion.US,
|
|
63
|
-
model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const agent = new bedrock.Agent(this, 'Agent', {
|
|
67
|
-
foundationModel: cris,
|
|
68
|
-
instruction: 'You are a helpful and friendly agent that answers questions about agriculture.',
|
|
69
|
-
});
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
#### Python
|
|
73
|
-
|
|
74
|
-
```python
|
|
75
|
-
cris = bedrock.CrossRegionInferenceProfile.from_config(
|
|
76
|
-
geo_region= bedrock.CrossRegionInferenceProfileRegion.US,
|
|
77
|
-
model= bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
agent = bedrock.Agent(
|
|
81
|
-
self,
|
|
82
|
-
"Agent",
|
|
83
|
-
foundation_model=cris,
|
|
84
|
-
instruction="You are a helpful and friendly agent that answers questions about agriculture.",
|
|
85
|
-
)
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
For more information on cross region inference, please refer to [System defined inference profiles](#system-defined-inference-profiles)
|
|
89
|
-
|
|
90
|
-
## Prepare the Agent
|
|
91
|
-
|
|
92
|
-
The `Agent` constructs take an optional parameter `shouldPrepareAgent` to indicate that the Agent should be prepared after any updates to an agent, Knowledge Base association, or action group. This may increase the time to create and update those resources. By default, this value is false .
|
|
93
|
-
|
|
94
|
-
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_**.
|
|
95
|
-
|
|
96
|
-
## Memory Configuration
|
|
97
|
-
|
|
98
|
-
Agents can maintain context across multiple sessions and recall past interactions using memory. This feature is useful for creating a more coherent conversational experience.
|
|
99
|
-
|
|
100
|
-
### Memory Options
|
|
101
|
-
|
|
102
|
-
You can configure memory for an agent using the `memory` property in the `AgentProps` interface. The memory configuration allows you to specify the type of memory and its properties.
|
|
103
|
-
|
|
104
|
-
### Example
|
|
105
|
-
|
|
106
|
-
#### TypeScript
|
|
107
|
-
|
|
108
|
-
```typescript
|
|
109
|
-
import { Agent, Memory, SessionSummaryMemoryProps } from 'src/cdk-lib/bedrock/agents';
|
|
110
|
-
|
|
111
|
-
const agent = new Agent(this, 'MyAgent', {
|
|
112
|
-
name: 'MyAgent',
|
|
113
|
-
instruction: 'Your instruction here',
|
|
114
|
-
foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
|
|
115
|
-
memory: Memory.sessionSummary({
|
|
116
|
-
maxRecentSessions: 10, // Keep the last 20 session summaries
|
|
117
|
-
memoryDurationDays: 20, // Retain summaries for 30 days
|
|
118
|
-
}),
|
|
119
|
-
});
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
#### Python
|
|
123
|
-
|
|
124
|
-
```py
|
|
125
|
-
from src.cdk_lib.bedrock.agents import Agent, Memory, BedrockFoundationModel
|
|
126
|
-
|
|
127
|
-
agent = Agent(self, 'MyAgent',
|
|
128
|
-
name='MyAgent',
|
|
129
|
-
instruction='Your instruction here',
|
|
130
|
-
foundation_model=BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
|
|
131
|
-
memory=Memory.session_summary(
|
|
132
|
-
max_recent_sessions=10, # Keep the last 10 session summaries
|
|
133
|
-
memory_duration_days=20, # Retain summaries for 20 days
|
|
134
|
-
),
|
|
135
|
-
)
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### Memory Properties
|
|
139
|
-
|
|
140
|
-
- **memoryDurationDays**: Duration in days for which session summaries are retained (1-365). Default is 30 days.
|
|
141
|
-
- **maxRecentSessions**: Maximum number of recent session summaries to include (minimum 1). Default is 20.
|
|
142
|
-
|
|
143
|
-
### Memory Types
|
|
144
|
-
|
|
145
|
-
Currently, the following memory type is supported:
|
|
146
|
-
|
|
147
|
-
- **SESSION_SUMMARY**: Uses memory summarization to enhance accuracy by summarizing sessions.
|
|
148
|
-
|
|
149
|
-
For more information on memory configuration, refer to the [AWS Bedrock documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/agents-memory.html).
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
# Custom Orchestration
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
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, handles knowledge base queries, and invokes action groups.
|
|
6
|
-
|
|
7
|
-
## Orchestration Types
|
|
8
|
-
|
|
9
|
-
You can configure the orchestration type using the `orchestrationType` and `customOrchestration` properties in the `AgentProps` interface.
|
|
10
|
-
|
|
11
|
-
- **DEFAULT**: The default orchestration provided by Bedrock (default).
|
|
12
|
-
- **CUSTOM_ORCHESTRATION**: Custom orchestration using a Lambda function.
|
|
13
|
-
|
|
14
|
-
## Example
|
|
15
|
-
|
|
16
|
-
### TypeScript
|
|
17
|
-
|
|
18
|
-
```typescript
|
|
19
|
-
import { Agent, OrchestrationType, OrchestrationExecutor } from '@cdklabs/generative-ai-cdk-constructs';
|
|
20
|
-
import * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
21
|
-
import * as path from 'path';
|
|
22
|
-
|
|
23
|
-
// Create a Lambda function for custom orchestration
|
|
24
|
-
const orchestrationFunction = new lambda.Function(this, 'OrchestrationFunction', {
|
|
25
|
-
runtime: lambda.Runtime.PYTHON_3_10,
|
|
26
|
-
handler: 'index.handler',
|
|
27
|
-
code: lambda.Code.fromAsset(path.join(__dirname, 'lambda/orchestration')),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// Create an agent with custom orchestration
|
|
31
|
-
const agent = new Agent(this, 'CustomOrchestrationAgent', {
|
|
32
|
-
name: 'CustomOrchestrationAgent',
|
|
33
|
-
instruction: 'You are a helpful assistant with custom orchestration logic.',
|
|
34
|
-
foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
|
|
35
|
-
orchestrationType: OrchestrationType.CUSTOM_ORCHESTRATION,
|
|
36
|
-
customOrchestration: {
|
|
37
|
-
executor: OrchestrationExecutor.fromlambdaFunction(orchestrationFunction),
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### Python
|
|
43
|
-
|
|
44
|
-
```python
|
|
45
|
-
from cdklabs.generative_ai_cdk_constructs import (
|
|
46
|
-
bedrock,
|
|
47
|
-
OrchestrationType,
|
|
48
|
-
OrchestrationExecutor
|
|
49
|
-
)
|
|
50
|
-
import aws_cdk.aws_lambda as lambda_
|
|
51
|
-
import os
|
|
52
|
-
|
|
53
|
-
# Create a Lambda function for custom orchestration
|
|
54
|
-
orchestration_function = lambda_.Function(self, 'OrchestrationFunction',
|
|
55
|
-
runtime=lambda_.Runtime.PYTHON_3_10,
|
|
56
|
-
handler='index.handler',
|
|
57
|
-
code=lambda_.Code.from_asset(os.path.join(os.path.dirname(__file__), 'lambda/orchestration')),
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
# Create an agent with custom orchestration
|
|
61
|
-
agent = bedrock.Agent(self, 'CustomOrchestrationAgent',
|
|
62
|
-
name='CustomOrchestrationAgent',
|
|
63
|
-
instruction='You are a helpful assistant with custom orchestration logic.',
|
|
64
|
-
foundation_model=bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
|
|
65
|
-
orchestration_type=OrchestrationType.CUSTOM_ORCHESTRATION,
|
|
66
|
-
custom_orchestration=bedrock.CustomOrchestration(
|
|
67
|
-
executor= OrchestrationExecutor.fromlambda_function(orchestration_function),
|
|
68
|
-
)
|
|
69
|
-
)
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
The custom orchestration Lambda function receives events from Bedrock with the user's input and context, and it can control the flow of the conversation by deciding when to query knowledge bases, invoke action groups, or respond directly to the user.
|
|
73
|
-
|
|
74
|
-
For more information on custom orchestration, refer to the [AWS Bedrock documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/agents-custom-orchestration.html).
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
# Amazon Bedrock Agents
|
|
2
|
-
|
|
3
|
-
Amazon Bedrock Agents enable you to build AI assistants that can perform tasks by connecting foundation models to your data sources, APIs, and business systems.
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
|
|
7
|
-
- [Amazon Bedrock Agents](#amazon-bedrock-agents)
|
|
8
|
-
- [Table of Contents](#table-of-contents)
|
|
9
|
-
- [Key Concepts](#key-concepts)
|
|
10
|
-
- [Agent Components](#agent-components)
|
|
11
|
-
- [When to Use Agents](#when-to-use-agents)
|
|
12
|
-
- [Related Resources](#related-resources)
|
|
13
|
-
- [Quick Start Example](#quick-start-example)
|
|
14
|
-
|
|
15
|
-
## Key Concepts
|
|
16
|
-
|
|
17
|
-
- **Agent**: An AI assistant that uses foundation models to understand user requests and take actions
|
|
18
|
-
- **Action Groups**: Functions your agent can call, defined by OpenAPI schemas and executed by Lambda functions
|
|
19
|
-
- **Knowledge Bases**: Data sources that provide context to your agent
|
|
20
|
-
- **Aliases**: Deployment targets for your agent, pointing to specific versions
|
|
21
|
-
- **Orchestration**: The process of coordinating agent interactions with action groups and knowledge bases
|
|
22
|
-
|
|
23
|
-
## Agent Components
|
|
24
|
-
|
|
25
|
-
```mermaid
|
|
26
|
-
graph TD
|
|
27
|
-
A[Agent] --> B[Foundation Model]
|
|
28
|
-
A --> C[Action Groups]
|
|
29
|
-
A --> D[Knowledge Bases]
|
|
30
|
-
A --> E[Aliases]
|
|
31
|
-
A --> F[Orchestration]
|
|
32
|
-
C --> G[Lambda Functions]
|
|
33
|
-
C --> H[OpenAPI Schema]
|
|
34
|
-
D --> I[Vector Stores]
|
|
35
|
-
D --> J[Data Sources]
|
|
36
|
-
F --> K[Default Orchestration]
|
|
37
|
-
F --> L[Custom Orchestration]
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## When to Use Agents
|
|
41
|
-
|
|
42
|
-
- **Task Automation**: Create assistants that can perform tasks like booking appointments or processing orders
|
|
43
|
-
- **Data-Driven Conversations**: Build agents that can answer questions using your organization's data
|
|
44
|
-
- **Multi-Step Workflows**: Implement complex workflows that require multiple steps and decisions
|
|
45
|
-
- **System Integration**: Connect foundation models to your existing systems and APIs
|
|
46
|
-
|
|
47
|
-
## Related Resources
|
|
48
|
-
|
|
49
|
-
- **Action Groups**: `genai-cdk-constructs://bedrock/agent/actiongroups`
|
|
50
|
-
- **Agent Aliases**: `genai-cdk-constructs://bedrock/agent/alias`
|
|
51
|
-
- **Agent Creation**: `genai-cdk-constructs://bedrock/agent/creation`
|
|
52
|
-
- **Agent Collaboration**: `genai-cdk-constructs://bedrock/agent/collaboration`
|
|
53
|
-
- **Custom Orchestration**: `genai-cdk-constructs://bedrock/agent/custom_orchestration`
|
|
54
|
-
- **Prompt Overrides**: `genai-cdk-constructs://bedrock/agent/prompt_override`
|
|
55
|
-
|
|
56
|
-
## Quick Start Example
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
import { bedrock } from '@cdklabs/generative-ai-cdk-constructs';
|
|
60
|
-
|
|
61
|
-
// Create a basic agent
|
|
62
|
-
const agent = new bedrock.Agent(this, 'Agent', {
|
|
63
|
-
foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_HAIKU_V1_0,
|
|
64
|
-
instruction: 'You are a helpful assistant that answers questions about our company.',
|
|
65
|
-
shouldPrepareAgent: true,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Add a knowledge base
|
|
69
|
-
agent.addKnowledgeBase(knowledgeBase);
|
|
70
|
-
|
|
71
|
-
// Add an action group
|
|
72
|
-
agent.addActionGroup(actionGroup);
|
|
73
|
-
|
|
74
|
-
// Create an alias for deployment
|
|
75
|
-
const agentAlias = new bedrock.AgentAlias(this, 'AgentAlias', {
|
|
76
|
-
aliasName: 'latest',
|
|
77
|
-
agent: agent,
|
|
78
|
-
});
|