Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
856dd14
feat(guardrails): initial commit
krokoko Jun 19, 2025
f42aff4
Merge branch 'bedrock-guardrails-l2' of https://github.com/krokoko/aw…
krokoko Jun 19, 2025
3b1f847
chore(build): fix build
krokoko Jun 19, 2025
ae7a130
chore(tests): add tests
krokoko Jun 19, 2025
6580f79
fix(readme): fix rosetta issues in readme
krokoko Jun 19, 2025
ea6c80e
fix(readme): fix rosetta issues in code
krokoko Jun 19, 2025
4c7fd9e
Merge branch 'main' into bedrock-guardrails-l2
krokoko Jun 23, 2025
0994932
Merge branch 'main' into bedrock-guardrails-l2
krokoko Jul 3, 2025
ba40945
Merge branch 'main' into bedrock-guardrails-l2
krokoko Jul 14, 2025
9440b0b
Merge branch 'main' into bedrock-guardrails-l2
krokoko Jul 18, 2025
918ca18
Merge branch 'main' into bedrock-guardrails-l2
krokoko Jul 23, 2025
9c2ed8d
Merge branch 'main' into bedrock-guardrails-l2
krokoko Jul 24, 2025
572b95f
Merge branch 'main' into bedrock-guardrails-l2
krokoko Jul 25, 2025
84fc2d8
Merge branch 'main' into bedrock-guardrails-l2
krokoko Jul 28, 2025
25ba8f3
Merge branch 'main' into bedrock-guardrails-l2
krokoko Jul 30, 2025
7237599
chore(guardrails): add tier config feature
krokoko Jul 30, 2025
36ccf95
chore(guardrails): add validation for topics
krokoko Jul 30, 2025
8fb044f
Merge branch 'main' into bedrock-guardrails-l2
krokoko Jul 30, 2025
6ad7428
chore(guardrails): profanity default type for managed words
krokoko Jul 30, 2025
6bf77c6
chore(guardrails): add validation for regex filers
krokoko Jul 30, 2025
b8adef2
chore(guardrails): add validation for blocked messages
krokoko Jul 30, 2025
0cca5cc
chore(guardrails): update doc for denied topics
krokoko Jul 30, 2025
0082773
chore(guardrails): refactor piitype
krokoko Jul 30, 2025
5f33e4c
Merge branch 'main' into bedrock-guardrails-l2
krokoko Jul 30, 2025
f28ef42
chore(guardrails): fix rosetta
krokoko Jul 30, 2025
591ba8a
chore(guardrails): add support for cross region inference
krokoko Jul 30, 2025
2739eb7
chore(guardrails): add guardrail support to agents
krokoko Jul 30, 2025
759a8cd
Merge branch 'main' into bedrock-guardrails-l2
krokoko Jul 31, 2025
aba4845
Merge branch 'main' into bedrock-guardrails-l2
krokoko Aug 11, 2025
0ea6f7d
Merge branch 'main' into bedrock-guardrails-l2
krokoko Aug 15, 2025
5d15166
chore(guardrails): update guardrails
krokoko Aug 15, 2025
9e648c7
chore(guardrails): update readme
krokoko Aug 15, 2025
97dea0f
chore(guardrails): add validation methods
krokoko Aug 15, 2025
38043d2
chore(guardrails): rosetta
krokoko Aug 15, 2025
93db514
Merge branch 'main' into bedrock-guardrails-l2
krokoko Aug 19, 2025
8606cd5
chore(guardrails): add default values for optional props
krokoko Aug 19, 2025
438aa96
Merge branch 'bedrock-guardrails-l2' of https://github.com/krokoko/aw…
krokoko Aug 19, 2025
50c54ef
chore(guardrails): address potential confusion with indexes in valida…
krokoko Aug 19, 2025
576dd09
Merge branch 'main' into bedrock-guardrails-l2
krokoko Aug 19, 2025
a2ae54d
Merge branch 'main' into bedrock-guardrails-l2
mergify[bot] Aug 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
540 changes: 540 additions & 0 deletions packages/@aws-cdk/aws-bedrock-alpha/README.md

Large diffs are not rendered by default.

63 changes: 60 additions & 3 deletions packages/@aws-cdk/aws-bedrock-alpha/bedrock/agents/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { AgentCollaborator } from './agent-collaborator';
import { AgentCollaboration } from './agent-collaboration';
import { PromptOverrideConfiguration } from './prompt-override';
import { AssetApiSchema, S3ApiSchema } from './api-schema';
import { IGuardrail } from '../guardrails/guardrails';
import * as validation from './validation-helpers';
import { IBedrockInvokable } from '.././models';
import { Memory } from './memory';
Expand Down Expand Up @@ -178,7 +179,6 @@ export abstract class AgentBase extends Resource implements IAgent {
/**
* Properties for creating a CDK managed Bedrock Agent.
* TODO: Knowledge bases configuration will be added in a future update
* TODO: Guardrails configuration will be added in a future update
* TODO: Inference profile configuration will be added in a future update
*
*/
Expand Down Expand Up @@ -241,7 +241,11 @@ export interface AgentProps {
* @default - Only default action groups (UserInput and CodeInterpreter) are added
*/
readonly actionGroups?: AgentActionGroup[];

/**
* The guardrail that will be associated with the agent.
* @default - No guardrail is provided.
*/
readonly guardrail?: IGuardrail;
/**
* Overrides some prompt templates in different parts of an agent sequence configuration.
*
Expand Down Expand Up @@ -408,7 +412,10 @@ export class Agent extends AgentBase implements IAgent {
* action groups associated with the ageny
*/
public readonly actionGroups: AgentActionGroup[] = [];

/**
* The guardrail that will be associated with the agent.
*/
public guardrail?: IGuardrail;
// ------------------------------------------------------
// CDK-only attributes
// ------------------------------------------------------
Expand Down Expand Up @@ -519,6 +526,10 @@ export class Agent extends AgentBase implements IAgent {
});
}

if (props.guardrail) {
this.addGuardrail(props.guardrail);
}

// Grant permissions for custom orchestration if provided
if (this.customOrchestrationExecutor?.lambdaFunction) {
this.customOrchestrationExecutor.lambdaFunction.grantInvoke(this.role);
Expand All @@ -540,6 +551,7 @@ export class Agent extends AgentBase implements IAgent {
customerEncryptionKeyArn: props.kmsKey?.keyArn,
description: props.description,
foundationModel: this.foundationModel.invokableArn,
guardrailConfiguration: Lazy.any({ produce: () => this.renderGuardrail() }),
idleSessionTtlInSeconds: this.idleSessionTTL.toSeconds(),
instruction: props.instruction,
memoryConfiguration: props.memory?._render(),
Expand Down Expand Up @@ -581,6 +593,19 @@ export class Agent extends AgentBase implements IAgent {
// HELPER METHODS - addX()
// ------------------------------------------------------

/**
* Add guardrail to the agent.
*/
@MethodMetadata()
public addGuardrail(guardrail: IGuardrail) {
// Do some checks
validation.throwIfInvalid(this.validateGuardrail, guardrail);
// Add it to the construct
this.guardrail = guardrail;
// Handle permissions
guardrail.grantApply(this.role);
}

/**
* Adds an action group to the agent and configures necessary permissions.
*
Expand Down Expand Up @@ -662,6 +687,20 @@ export class Agent extends AgentBase implements IAgent {
// Lazy Renderers
// ------------------------------------------------------

/**
* Render the guardrail configuration.
*
* @internal This is an internal core function and should not be called directly.
*/
private renderGuardrail(): bedrock.CfnAgent.GuardrailConfigurationProperty | undefined {
return this.guardrail
? {
guardrailIdentifier: this.guardrail.guardrailId,
guardrailVersion: this.guardrail.guardrailVersion,
}
: undefined;
}

/**
* Render the action groups
*
Expand Down Expand Up @@ -715,6 +754,24 @@ export class Agent extends AgentBase implements IAgent {
// ------------------------------------------------------
// Validators
// ------------------------------------------------------
/**
* Checks if the Guardrail is valid
*
* @param guardrail - The guardrail to validate
* @returns Array of validation error messages, empty if valid
*/
private validateGuardrail = (guardrail: IGuardrail) => {
let errors: string[] = [];
if (this.guardrail) {
errors.push(
`Cannot add Guardrail ${guardrail.guardrailId}. ` +
`Guardrail ${this.guardrail.guardrailId} has already been specified for this agent.`,
);
}
errors.push(...validation.validateFieldPattern(guardrail.guardrailVersion, 'version', /^(([0-9]{1,8})|(DRAFT))$/));
return errors;
};

/**
* Check if the action group is valid
*
Expand Down
Loading
Loading