Experimental
@aws-cdk/aws-bedrock-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.
FunctionSchema Class
Represents a function schema for a Bedrock Agent Action Group.
Example
ts
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')),
});
// Define a function schema with parameters
const functionSchema = new bedrock.FunctionSchema({
functions: [
{
name: 'searchBooks',
description: 'Search for books in the library catalog',
parameters: {
'query': {
type: bedrock.ParameterType.STRING,
required: true,
description: 'The search query string',
},
'maxResults': {
type: bedrock.ParameterType.INTEGER,
required: false,
description: 'Maximum number of results to return',
},
'includeOutOfPrint': {
type: bedrock.ParameterType.BOOLEAN,
required: false,
description: 'Whether to include out-of-print books',
}
},
requireConfirmation: bedrock.RequireConfirmation.DISABLED,
},
{
name: 'getBookDetails',
description: 'Get detailed information about a specific book',
parameters: {
'bookId': {
type: bedrock.ParameterType.STRING,
required: true,
description: 'The unique identifier of the book',
}
},
requireConfirmation: bedrock.RequireConfirmation.ENABLED,
}
]
});
// Create an action group using the function schema
const actionGroup = new bedrock.AgentActionGroup({
name: 'library-functions',
description: 'Functions for interacting with the library catalog',
executor: bedrock.ActionGroupExecutor.fromLambda(actionGroupFunction),
functionSchema: functionSchema,
enabled: true,
});
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.',
actionGroups: [actionGroup],
});
python
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"))
)
# Define a function schema with parameters
function_schema = bedrock.FunctionSchema(
functions=[bedrock.FunctionProps(
name="searchBooks",
description="Search for books in the library catalog",
parameters={
"query": bedrock.FunctionParameterProps(
type=bedrock.ParameterType.STRING,
required=True,
description="The search query string"
),
"maxResults": bedrock.FunctionParameterProps(
type=bedrock.ParameterType.INTEGER,
required=False,
description="Maximum number of results to return"
),
"includeOutOfPrint": bedrock.FunctionParameterProps(
type=bedrock.ParameterType.BOOLEAN,
required=False,
description="Whether to include out-of-print books"
)
},
require_confirmation=bedrock.RequireConfirmation.DISABLED
), bedrock.FunctionProps(
name="getBookDetails",
description="Get detailed information about a specific book",
parameters={
"bookId": bedrock.FunctionParameterProps(
type=bedrock.ParameterType.STRING,
required=True,
description="The unique identifier of the book"
)
},
require_confirmation=bedrock.RequireConfirmation.ENABLED
)
]
)
# Create an action group using the function schema
action_group = bedrock.AgentActionGroup(
name="library-functions",
description="Functions for interacting with the library catalog",
executor=bedrock.ActionGroupExecutor.from_lambda(action_group_function),
function_schema=function_schema,
enabled=True
)
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.",
action_groups=[action_group]
)
java
Function actionGroupFunction = Function.Builder.create(this, "ActionGroupFunction")
.runtime(Runtime.PYTHON_3_12)
.handler("index.handler")
.code(Code.fromAsset(join(__dirname, "../lambda/action-group")))
.build();
// Define a function schema with parameters
FunctionSchema functionSchema = FunctionSchema.Builder.create()
.functions(List.of(FunctionProps.builder()
.name("searchBooks")
.description("Search for books in the library catalog")
.parameters(Map.of(
"query", FunctionParameterProps.builder()
.type(ParameterType.STRING)
.required(true)
.description("The search query string")
.build(),
"maxResults", FunctionParameterProps.builder()
.type(ParameterType.INTEGER)
.required(false)
.description("Maximum number of results to return")
.build(),
"includeOutOfPrint", FunctionParameterProps.builder()
.type(ParameterType.BOOLEAN)
.required(false)
.description("Whether to include out-of-print books")
.build()))
.requireConfirmation(RequireConfirmation.DISABLED)
.build(), FunctionProps.builder()
.name("getBookDetails")
.description("Get detailed information about a specific book")
.parameters(Map.of(
"bookId", FunctionParameterProps.builder()
.type(ParameterType.STRING)
.required(true)
.description("The unique identifier of the book")
.build()))
.requireConfirmation(RequireConfirmation.ENABLED)
.build()))
.build();
// Create an action group using the function schema
AgentActionGroup actionGroup = AgentActionGroup.Builder.create()
.name("library-functions")
.description("Functions for interacting with the library catalog")
.executor(ActionGroupExecutor.fromLambda(actionGroupFunction))
.functionSchema(functionSchema)
.enabled(true)
.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.")
.actionGroups(List.of(actionGroup))
.build();
csharp
// Install: dotnet add package Amazon.CDK.AWS.Bedrock.Alpha
var actionGroupFunction = new Function(this, "ActionGroupFunction", new FunctionProps {
Runtime = Runtime.PYTHON_3_12,
Handler = "index.handler",
Code = Code.FromAsset(Join(__dirname, "../lambda/action-group"))
});
// Define a function schema with parameters
var functionSchema = new FunctionSchema(new FunctionSchemaProps {
Functions = new [] { new FunctionProps {
Name = "searchBooks",
Description = "Search for books in the library catalog",
Parameters = new Dictionary<string, FunctionParameterProps> {
{ "query", new FunctionParameterProps {
Type = ParameterType.STRING,
Required = true,
Description = "The search query string"
} },
{ "maxResults", new FunctionParameterProps {
Type = ParameterType.INTEGER,
Required = false,
Description = "Maximum number of results to return"
} },
{ "includeOutOfPrint", new FunctionParameterProps {
Type = ParameterType.BOOLEAN,
Required = false,
Description = "Whether to include out-of-print books"
} }
},
RequireConfirmation = RequireConfirmation.DISABLED
}, new FunctionProps {
Name = "getBookDetails",
Description = "Get detailed information about a specific book",
Parameters = new Dictionary<string, FunctionParameterProps> {
{ "bookId", new FunctionParameterProps {
Type = ParameterType.STRING,
Required = true,
Description = "The unique identifier of the book"
} }
},
RequireConfirmation = RequireConfirmation.ENABLED
} }
});
// Create an action group using the function schema
var actionGroup = new AgentActionGroup(new AgentActionGroupProps {
Name = "library-functions",
Description = "Functions for interacting with the library catalog",
Executor = ActionGroupExecutor.FromLambda(actionGroupFunction),
FunctionSchema = functionSchema,
Enabled = true
});
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.",
ActionGroups = new [] { actionGroup }
});
go
// Install: go get github.com/aws/aws-cdk-go/awsbedrockalpha/v2
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"))),
})
// Define a function schema with parameters
functionSchema := bedrock.NewFunctionSchema(&FunctionSchemaProps{
Functions: []FunctionProps{
&FunctionProps{
Name: jsii.String("searchBooks"),
Description: jsii.String("Search for books in the library catalog"),
Parameters: map[string]FunctionParameterProps{
"query": &FunctionParameterProps{
"type": bedrock.ParameterType_STRING,
"required": jsii.Boolean(true),
"description": jsii.String("The search query string"),
},
"maxResults": &FunctionParameterProps{
"type": bedrock.ParameterType_INTEGER,
"required": jsii.Boolean(false),
"description": jsii.String("Maximum number of results to return"),
},
"includeOutOfPrint": &FunctionParameterProps{
"type": bedrock.ParameterType_BOOLEAN,
"required": jsii.Boolean(false),
"description": jsii.String("Whether to include out-of-print books"),
},
},
RequireConfirmation: bedrock.RequireConfirmation_DISABLED,
},
&FunctionProps{
Name: jsii.String("getBookDetails"),
Description: jsii.String("Get detailed information about a specific book"),
Parameters: map[string]FunctionParameterProps{
"bookId": &FunctionParameterProps{
"type": bedrock.ParameterType_STRING,
"required": jsii.Boolean(true),
"description": jsii.String("The unique identifier of the book"),
},
},
RequireConfirmation: bedrock.RequireConfirmation_ENABLED,
},
},
})
// Create an action group using the function schema
actionGroup := bedrock.NewAgentActionGroup(&AgentActionGroupProps{
Name: jsii.String("library-functions"),
Description: jsii.String("Functions for interacting with the library catalog"),
Executor: bedrock.ActionGroupExecutor_FromLambda(actionGroupFunction),
FunctionSchema: functionSchema,
Enabled: jsii.Boolean(true),
})
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."),
ActionGroups: []AgentActionGroup{
actionGroup,
},
})
Initializer
ts
new FunctionSchema(props: FunctionSchemaProps)
python
FunctionSchema(props: FunctionSchemaProps)
java
new FunctionSchema(FunctionSchemaProps props)
csharp
new FunctionSchema(FunctionSchemaProps props)
go
NewFunctionSchema(Props FunctionSchemaProps)