Skip to content

Commit

Permalink
Merge pull request #149 from aws-samples/bedrock_agent_update_jan2025
Browse files Browse the repository at this point in the history
chore(bedrock_agent): update sample with latest version
  • Loading branch information
krokoko authored Jan 27, 2025
2 parents a693f9e + 66a2da6 commit eae7b28
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 57 deletions.
59 changes: 45 additions & 14 deletions samples/bedrock-agent/lib/bedrock-agent-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export class BedrockAgentStack extends cdk.Stack {
});

const agent = new bedrock.Agent(this, 'Agent', {
foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_INSTANT_V1_2,
foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
instruction: 'You are a helpful and friendly agent that answers questions about literature.',
knowledgeBases: [kb],
enableUserInput: true,
userInputEnabled: true,
shouldPrepareAgent:true
});

Expand All @@ -79,23 +79,35 @@ export class BedrockAgentStack extends cdk.Stack {
timeout:cdk.Duration.minutes(2)
});

const actionGroup = new AgentActionGroup(this,'MyActionGroup',{
actionGroupName: 'query-library',
const actionGroup = new AgentActionGroup({
name: 'query-library',
description: 'Use these functions to get information about the books in the library.',
actionGroupExecutor: {
lambda: actionGroupFunction
},
actionGroupState: "ENABLED",
apiSchema: bedrock.ApiSchema.fromAsset(path.join(__dirname, 'action-group.yaml')),
executor: bedrock.ActionGroupExecutor.fromlambdaFunction(actionGroupFunction),
enabled: true,
apiSchema: bedrock.ApiSchema.fromLocalAsset(path.join(__dirname, 'action-group.yaml')),
});

agent.addActionGroups([actionGroup])
agent.addActionGroup(actionGroup);

agent.addAlias({
const agentAlias2 = new bedrock.AgentAlias(this, 'myalias2', {
aliasName: 'my-agent-alias',
description:'alias for my agent'

})
agent: agent,
description: 'alias for my agent'
});

// Add NAG suppression for the Agent's role policy
NagSuppressions.addResourceSuppressionsByPath(
this,
`/${this.node.path}/Agent/Role/DefaultPolicy/Resource`,
[
{
id: 'AwsSolutions-IAM5',
reason: 'The Agent requires permissions to invoke the action group Lambda function',
appliesTo: ['Resource::<ActionGroupFunctionFE14D1CB.Arn>:*'],
},
],
true
);

new cdk.CfnOutput(this, 'AgentId', {value: agent.agentId});
new cdk.CfnOutput(this, 'KnowledgeBaseId', {value: kb.knowledgeBaseId});
Expand All @@ -108,10 +120,29 @@ export class BedrockAgentStack extends cdk.Stack {
{
id: 'AwsSolutions-IAM4',
reason: 'ActionGroup Lambda uses the AWSLambdaBasicExecutionRole AWS Managed Policy.',
},
{
id: 'AwsSolutions-L1',
reason: 'Using Python 3.12 as the latest runtime version for Lambda.',
}
],
true,
);
NagSuppressions.addResourceSuppressionsByPath(
this,
`/${this.node.path}/Agent/Role/DefaultPolicy`,
[
{
id: 'AwsSolutions-IAM5',
reason: 'The Lambda function requires broad permissions for logging and invocation.',
appliesTo: [
'Action::lambda:InvokeFunction',
'Action::logs:*'
],
},
],
true,
);
NagSuppressions.addResourceSuppressionsByPath(
this,
`/${this.node.path}/LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a/ServiceRole`,
Expand Down
79 changes: 40 additions & 39 deletions samples/bedrock-agent/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions samples/bedrock-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
"@types/jest": "^27.5.2",
"@types/node": "10.17.27",
"@types/prettier": "2.6.0",
"aws-cdk": "2.162.1",
"aws-cdk": "2.176.0",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"ts-node": "^10.9.1",
"typescript": "~3.9.7"
},
"dependencies": {
"@aws-cdk/aws-lambda-python-alpha": "^2.162.1-alpha.0",
"@cdklabs/generative-ai-cdk-constructs": "^0.1.275",
"aws-cdk-lib": "^2.162.1",
"@aws-cdk/aws-lambda-python-alpha": "^2.176.0-alpha.0",
"@cdklabs/generative-ai-cdk-constructs": "^0.1.290",
"aws-cdk-lib": "^2.176.0",
"cdk-nag": "^2.28.13",
"constructs": "^10.0.0",
"source-map-support": "^0.5.21"
Expand Down

0 comments on commit eae7b28

Please sign in to comment.