Experimental
@aws-cdk/aws-bedrock-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.
ActionGroupExecutor Class
Defines how fulfillment of the action group is handled after the necessary information has been elicited from the user.
Valid executors are:
- Lambda function
- Return Control
| Stability | Experimental |
|---|---|
| Source | bedrock/agents/api-executor.ts |
Example
ts
const bucket = s3.Bucket.fromBucketName(this, 'ExistingBucket', 'my-schema-bucket');
const s3Schema = bedrock.ApiSchema.fromS3File(bucket, 'schemas/action-group.yaml');
const actionGroupFunction = new lambda.Function(this, 'ActionGroupFunction', {
runtime: lambda.Runtime.PYTHON_3_12,
handler: 'index.handler',
code: lambda.Code.fromAsset(path.join(__dirname, '../lambda/action-group')),
});
const actionGroup = new bedrock.AgentActionGroup({
name: 'query-library',
description: 'Use these functions to get information about the books in the library.',
executor: bedrock.ActionGroupExecutor.fromLambda(actionGroupFunction),
enabled: true,
apiSchema: s3Schema,
});
const agent = new bedrock.Agent(this, 'Agent', {
foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
instruction: 'You are a helpful and friendly agent that answers questions about literature.',
});
agent.addActionGroup(actionGroup);
python
bucket = s3.Bucket.from_bucket_name(self, "ExistingBucket", "my-schema-bucket")
s3_schema = bedrock.ApiSchema.from_s3_file(bucket, "schemas/action-group.yaml")
action_group_function = lambda_.Function(self, "ActionGroupFunction",
runtime=lambda_.Runtime.PYTHON_3_12,
handler="index.handler",
code=lambda_.Code.from_asset(path.join(__dirname, "../lambda/action-group"))
)
action_group = bedrock.AgentActionGroup(
name="query-library",
description="Use these functions to get information about the books in the library.",
executor=bedrock.ActionGroupExecutor.from_lambda(action_group_function),
enabled=True,
api_schema=s3_schema
)
agent = bedrock.Agent(self, "Agent",
foundation_model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
instruction="You are a helpful and friendly agent that answers questions about literature."
)
agent.add_action_group(action_group)
java
IBucket bucket = Bucket.fromBucketName(this, "ExistingBucket", "my-schema-bucket");
S3ApiSchema s3Schema = ApiSchema.fromS3File(bucket, "schemas/action-group.yaml");
Function actionGroupFunction = Function.Builder.create(this, "ActionGroupFunction")
.runtime(Runtime.PYTHON_3_12)
.handler("index.handler")
.code(Code.fromAsset(join(__dirname, "../lambda/action-group")))
.build();
AgentActionGroup actionGroup = AgentActionGroup.Builder.create()
.name("query-library")
.description("Use these functions to get information about the books in the library.")
.executor(ActionGroupExecutor.fromLambda(actionGroupFunction))
.enabled(true)
.apiSchema(s3Schema)
.build();
Agent agent = Agent.Builder.create(this, "Agent")
.foundationModel(BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0)
.instruction("You are a helpful and friendly agent that answers questions about literature.")
.build();
agent.addActionGroup(actionGroup);
csharp
// Install: dotnet add package Amazon.CDK.AWS.Bedrock.Alpha
var bucket = Bucket.FromBucketName(this, "ExistingBucket", "my-schema-bucket");
var s3Schema = ApiSchema.FromS3File(bucket, "schemas/action-group.yaml");
var actionGroupFunction = new Function(this, "ActionGroupFunction", new FunctionProps {
Runtime = Runtime.PYTHON_3_12,
Handler = "index.handler",
Code = Code.FromAsset(Join(__dirname, "../lambda/action-group"))
});
var actionGroup = new AgentActionGroup(new AgentActionGroupProps {
Name = "query-library",
Description = "Use these functions to get information about the books in the library.",
Executor = ActionGroupExecutor.FromLambda(actionGroupFunction),
Enabled = true,
ApiSchema = s3Schema
});
var agent = new Agent(this, "Agent", new AgentProps {
FoundationModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
Instruction = "You are a helpful and friendly agent that answers questions about literature."
});
agent.AddActionGroup(actionGroup);
go
// Install: go get github.com/aws/aws-cdk-go/awsbedrockalpha/v2
bucket := s3.Bucket_FromBucketName(this, jsii.String("ExistingBucket"), jsii.String("my-schema-bucket"))
s3Schema := bedrock.ApiSchema_FromS3File(bucket, jsii.String("schemas/action-group.yaml"))
actionGroupFunction := lambda.NewFunction(this, jsii.String("ActionGroupFunction"), &FunctionProps{
Runtime: lambda.Runtime_PYTHON_3_12(),
Handler: jsii.String("index.handler"),
Code: lambda.Code_FromAsset(path.join(__dirname, jsii.String("../lambda/action-group"))),
})
actionGroup := bedrock.NewAgentActionGroup(&AgentActionGroupProps{
Name: jsii.String("query-library"),
Description: jsii.String("Use these functions to get information about the books in the library."),
Executor: bedrock.ActionGroupExecutor_FromLambda(actionGroupFunction),
Enabled: jsii.Boolean(true),
ApiSchema: s3Schema,
})
agent := bedrock.NewAgent(this, jsii.String("Agent"), &AgentProps{
FoundationModel: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_HAIKU_V1_0(),
Instruction: jsii.String("You are a helpful and friendly agent that answers questions about literature."),
})
agent.AddActionGroup(actionGroup)
Properties
customControlmay be undefinedCustomControlcustom_controlmay be undefinedCustomControlcustomControlmay be undefinedCustomControlCustomControlmay be undefinedCustomControlCustomControlmay be undefinedCustomControl #The custom control type for the action group executor.
Currently only supports 'RETURN_CONTROL' which returns results directly in the InvokeAgent response.
lambdaFunctionmay be undefinedIFunctionlambda_functionmay be undefinedIFunctionlambdaFunctionmay be undefinedIFunctionLambdaFunctionmay be undefinedIFunctionLambdaFunctionmay be undefinedIFunction #The Lambda function that will be called by the action group.
Contains the business logic for handling the action group's invocation.
RETURN_CONTROLActionGroupExecutorRETURN_CONTROLActionGroupExecutorRETURN_CONTROLActionGroupExecutorRETURN_CONTROLActionGroupExecutorRETURN_CONTROLActionGroupExecutor static #Returns the action group invocation results directly in the InvokeAgent response.
The information and parameters can be sent to your own systems to yield results.
Methods
fromLambda(lambdaFunction: IFunction): ActionGroupExecutor // chainable@staticmethod def from_lambda(lambda_function: IFunction) -> ActionGroupExecutorpublic static ActionGroupExecutor fromLambda(IFunction lambdaFunction)public static ActionGroupExecutor FromLambda(IFunction lambdaFunction)func FromLambda(LambdaFunction IFunction) ActionGroupExecutor static #Defines an action group with a Lambda function containing the business logic.
1 parameter
Parameters
lambdaFunctionlambda_functionlambdaFunctionlambdaFunctionLambdaFunction— - Lambda function to be called by the action group.