Skip to content

Commit 9a19677

Browse files
authored
fix(agent): fix enable user input bug (#642)
* fix(agent): fix enable user input bug
1 parent 9a527b5 commit 9a19677

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

src/cdk-lib/bedrock/agent.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,13 @@ export class Agent extends Construct {
380380
* A list of action groups associated with the agent
381381
* @private
382382
*/
383-
public actionGroups: bedrock.CfnAgent.AgentActionGroupProperty[]=[];
383+
public actionGroups: bedrock.CfnAgent.AgentActionGroupProperty[] = [];
384384
/**
385385
* A list of KnowledgeBases associated with the agent.
386386
*
387387
* @default - No knowledge base is used.
388388
*/
389-
public knowledgeBases: bedrock.CfnAgent.AgentKnowledgeBaseProperty []=[];
389+
public knowledgeBases: bedrock.CfnAgent.AgentKnowledgeBaseProperty[] = [];
390390

391391

392392
constructor(scope: Construct, id: string, props: AgentProps) {
@@ -488,14 +488,12 @@ export class Agent extends Construct {
488488
this.addActionGroups(props.actionGroups);
489489
}
490490
// To allow your agent to request the user for additional information
491-
// when trying to complete a task , add this action group
492-
if (props.enableUserInput) {
493-
this.addActionGroup(new AgentActionGroup(this, 'userInputEnabledActionGroup', {
494-
actionGroupName: 'UserInputAction',
495-
parentActionGroupSignature: 'AMAZON.UserInput',
496-
actionGroupState: 'ENABLED',
497-
}));
498-
}
491+
// when trying to complete a task, add this action group
492+
this.addActionGroup(new AgentActionGroup(this, 'userInputEnabledActionGroup', {
493+
actionGroupName: 'UserInputAction',
494+
parentActionGroupSignature: 'AMAZON.UserInput',
495+
actionGroupState: props.enableUserInput ? 'ENABLED' : 'DISABLED',
496+
}));
499497
}
500498

501499

@@ -516,7 +514,7 @@ export class Agent extends Construct {
516514
/**
517515
* Add knowledge bases to the agent.
518516
*/
519-
public addKnowledgeBases(knowledgeBases: KnowledgeBase []) {
517+
public addKnowledgeBases(knowledgeBases: KnowledgeBase[]) {
520518
for (const kb of knowledgeBases) {
521519
this.addKnowledgeBase(kb);
522520
}
@@ -679,7 +677,7 @@ export function validateInferenceConfiguration(inferenceConfiguration: Inference
679677
*
680678
* @internal This is an internal core function and should not be called directly.
681679
*/
682-
export function validatePromptOverrideConfiguration(promptOverrideConfiguration: PromptOverrideConfiguration|undefined) {
680+
export function validatePromptOverrideConfiguration(promptOverrideConfiguration: PromptOverrideConfiguration | undefined) {
683681
if (!promptOverrideConfiguration) {
684682
return;
685683
}

test/cdk-lib/bedrock/agent.test.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ describe('Agent with guardrails through addGuardrail', () => {
123123
promptConfigurations: [preprocessingPrompt, orchestrationPrompt],
124124
},
125125
aliasName: 'prod',
126+
enableUserInput: true,
126127
});
127128

128129
agent.addActionGroups([actiongroup]);
@@ -238,12 +239,12 @@ describe('Agent with guardrails through addGuardrail', () => {
238239
template.resourceCountIs('AWS::Bedrock::KnowledgeBase', 1);
239240
template.hasResourceProperties('AWS::Bedrock::KnowledgeBase', {
240241
KnowledgeBaseConfiguration: {
241-
Type: Match.stringLikeRegexp ('VECTOR'),
242+
Type: Match.stringLikeRegexp('VECTOR'),
242243
},
243-
Name: Match.stringLikeRegexp ('KBteststack'),
244+
Name: Match.stringLikeRegexp('KBteststack'),
244245
RoleArn: {
245246
'Fn::GetAtt':
246-
[Match.stringLikeRegexp('KBRole'), 'Arn'],
247+
[Match.stringLikeRegexp('KBRole'), 'Arn'],
247248

248249
},
249250

@@ -256,6 +257,12 @@ describe('Agent with guardrails through addGuardrail', () => {
256257
template.hasResourceProperties('AWS::Bedrock::Agent', {
257258

258259
ActionGroups: [
260+
{
261+
ActionGroupName: 'UserInputAction',
262+
ActionGroupState: 'ENABLED',
263+
ParentActionGroupSignature: 'AMAZON.UserInput',
264+
SkipResourceInUseCheckOnDelete: false,
265+
},
259266
{
260267
ActionGroupExecutor: {
261268
Lambda: {
@@ -508,12 +515,12 @@ describe('Agent with guardrails through constructor', () => {
508515
template.resourceCountIs('AWS::Bedrock::KnowledgeBase', 1);
509516
template.hasResourceProperties('AWS::Bedrock::KnowledgeBase', {
510517
KnowledgeBaseConfiguration: {
511-
Type: Match.stringLikeRegexp ('VECTOR'),
518+
Type: Match.stringLikeRegexp('VECTOR'),
512519
},
513-
Name: Match.stringLikeRegexp ('KBteststack'),
520+
Name: Match.stringLikeRegexp('KBteststack'),
514521
RoleArn: {
515522
'Fn::GetAtt':
516-
[Match.stringLikeRegexp('KBRole'), 'Arn'],
523+
[Match.stringLikeRegexp('KBRole'), 'Arn'],
517524

518525
},
519526

@@ -526,6 +533,12 @@ describe('Agent with guardrails through constructor', () => {
526533
template.hasResourceProperties('AWS::Bedrock::Agent', {
527534

528535
ActionGroups: [
536+
{
537+
ActionGroupName: 'UserInputAction',
538+
ActionGroupState: 'DISABLED',
539+
ParentActionGroupSignature: 'AMAZON.UserInput',
540+
SkipResourceInUseCheckOnDelete: false,
541+
},
529542
{
530543
ActionGroupExecutor: {
531544
Lambda: {
@@ -765,12 +778,12 @@ describe('Agent without guardrails', () => {
765778
template.resourceCountIs('AWS::Bedrock::KnowledgeBase', 1);
766779
template.hasResourceProperties('AWS::Bedrock::KnowledgeBase', {
767780
KnowledgeBaseConfiguration: {
768-
Type: Match.stringLikeRegexp ('VECTOR'),
781+
Type: Match.stringLikeRegexp('VECTOR'),
769782
},
770-
Name: Match.stringLikeRegexp ('KBteststack'),
783+
Name: Match.stringLikeRegexp('KBteststack'),
771784
RoleArn: {
772785
'Fn::GetAtt':
773-
[Match.stringLikeRegexp('KBRole'), 'Arn'],
786+
[Match.stringLikeRegexp('KBRole'), 'Arn'],
774787

775788
},
776789

@@ -783,6 +796,12 @@ describe('Agent without guardrails', () => {
783796
template.hasResourceProperties('AWS::Bedrock::Agent', {
784797

785798
ActionGroups: [
799+
{
800+
ActionGroupName: 'UserInputAction',
801+
ActionGroupState: 'DISABLED',
802+
ParentActionGroupSignature: 'AMAZON.UserInput',
803+
SkipResourceInUseCheckOnDelete: false,
804+
},
786805
{
787806
ActionGroupExecutor: {
788807
Lambda: {

0 commit comments

Comments
 (0)