SchemaDefinition Struct
Schema definition for tool input/output.
| Source | aws-bedrockagentcore/lib/gateway/targets/schema/tool-schema.ts |
|---|---|
| Type last changed |
Example
ts
// Create a gateway first
const gateway = new agentcore.Gateway(this, "MyGateway", {
gatewayName: "my-gateway",
});
const lambdaFunction = new lambda.Function(this, "MyFunction", {
runtime: lambda.Runtime.NODEJS_22_X,
handler: "index.handler",
code: lambda.Code.fromInline(`
exports.handler = async (event) => {
return {
statusCode: 200,
body: JSON.stringify({ message: 'Hello from Lambda!' })
};
};
`),
});
const lambdaTarget = gateway.addLambdaTarget("MyLambdaTarget", {
gatewayTargetName: "my-lambda-target",
description: "Lambda function target",
lambdaFunction: lambdaFunction,
toolSchema: agentcore.ToolSchema.fromInline([
{
name: "hello_world",
description: "A simple hello world tool",
inputSchema: {
type: agentcore.SchemaDefinitionType.OBJECT,
properties: {
name: {
type: agentcore.SchemaDefinitionType.STRING,
description: "The name to greet",
},
},
required: ["name"],
},
},
]),
});
python
# Create a gateway first
gateway = agentcore.Gateway(self, "MyGateway",
gateway_name="my-gateway"
)
lambda_function = lambda_.Function(self, "MyFunction",
runtime=lambda_.Runtime.NODEJS_22_X,
handler="index.handler",
code=lambda_.Code.from_inline("""
exports.handler = async (event) => {
return {
statusCode: 200,
body: JSON.stringify({ message: 'Hello from Lambda!' })
};
};
""")
)
lambda_target = gateway.add_lambda_target("MyLambdaTarget",
gateway_target_name="my-lambda-target",
description="Lambda function target",
lambda_function=lambda_function,
tool_schema=agentcore.ToolSchema.from_inline([agentcore.ToolDefinition(
name="hello_world",
description="A simple hello world tool",
input_schema=agentcore.SchemaDefinition(
type=agentcore.SchemaDefinitionType.OBJECT,
properties={
"name": agentcore.SchemaDefinition(
type=agentcore.SchemaDefinitionType.STRING,
description="The name to greet"
)
},
required=["name"]
)
)
])
)
java
// Create a gateway first
Gateway gateway = Gateway.Builder.create(this, "MyGateway")
.gatewayName("my-gateway")
.build();
Function lambdaFunction = Function.Builder.create(this, "MyFunction")
.runtime(Runtime.NODEJS_22_X)
.handler("index.handler")
.code(Code.fromInline("\n exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify({ message: 'Hello from Lambda!' })\n };\n };\n "))
.build();
GatewayTarget lambdaTarget = gateway.addLambdaTarget("MyLambdaTarget", AddLambdaTargetOptions.builder()
.gatewayTargetName("my-lambda-target")
.description("Lambda function target")
.lambdaFunction(lambdaFunction)
.toolSchema(ToolSchema.fromInline(List.of(ToolDefinition.builder()
.name("hello_world")
.description("A simple hello world tool")
.inputSchema(SchemaDefinition.builder()
.type(SchemaDefinitionType.OBJECT)
.properties(Map.of(
"name", SchemaDefinition.builder()
.type(SchemaDefinitionType.STRING)
.description("The name to greet")
.build()))
.required(List.of("name"))
.build())
.build())))
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
// Create a gateway first
var gateway = new Gateway(this, "MyGateway", new GatewayProps {
GatewayName = "my-gateway"
});
var lambdaFunction = new Function(this, "MyFunction", new FunctionProps {
Runtime = Runtime.NODEJS_22_X,
Handler = "index.handler",
Code = Code.FromInline(@"
exports.handler = async (event) => {
return {
statusCode: 200,
body: JSON.stringify({ message: 'Hello from Lambda!' })
};
};
")
});
var lambdaTarget = gateway.AddLambdaTarget("MyLambdaTarget", new AddLambdaTargetOptions {
GatewayTargetName = "my-lambda-target",
Description = "Lambda function target",
LambdaFunction = lambdaFunction,
ToolSchema = ToolSchema.FromInline(new [] { new ToolDefinition {
Name = "hello_world",
Description = "A simple hello world tool",
InputSchema = new SchemaDefinition {
Type = SchemaDefinitionType.OBJECT,
Properties = new Dictionary<string, SchemaDefinition> {
{ "name", new SchemaDefinition {
Type = SchemaDefinitionType.STRING,
Description = "The name to greet"
} }
},
Required = new [] { "name" }
}
} })
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Create a gateway first
gateway := agentcore.NewGateway(this, jsii.String("MyGateway"), &GatewayProps{
GatewayName: jsii.String("my-gateway"),
})
lambdaFunction := lambda.NewFunction(this, jsii.String("MyFunction"), &FunctionProps{
Runtime: lambda.Runtime_NODEJS_22_X(),
Handler: jsii.String("index.handler"),
Code: lambda.Code_FromInline(jsii.String(`
exports.handler = async (event) => {
return {
statusCode: 200,
body: JSON.stringify({ message: 'Hello from Lambda!' })
};
};
`)),
})
lambdaTarget := gateway.AddLambdaTarget(jsii.String("MyLambdaTarget"), &AddLambdaTargetOptions{
GatewayTargetName: jsii.String("my-lambda-target"),
Description: jsii.String("Lambda function target"),
LambdaFunction: lambdaFunction,
ToolSchema: agentcore.ToolSchema_FromInline([]ToolDefinition{
&ToolDefinition{
Name: jsii.String("hello_world"),
Description: jsii.String("A simple hello world tool"),
InputSchema: &SchemaDefinition{
Type: agentcore.SchemaDefinitionType_OBJECT(),
Properties: map[string]SchemaDefinition{
"name": &SchemaDefinition{
"type": agentcore.SchemaDefinitionType_STRING(),
"description": jsii.String("The name to greet"),
},
},
Required: []*string{
jsii.String("name"),
},
},
},
}),
})
Properties
descriptionoptionalstringdescriptionoptionalstrdescriptionoptionalStringDescriptionoptionalstringDescriptionoptional*string #The description of the schema definition.
Default: No description
This description provides information about the purpose and usage of the schema.
itemsoptionalSchemaDefinitionitemsoptionalSchemaDefinitionitemsoptionalSchemaDefinitionItemsoptionalSchemaDefinitionItemsoptionalSchemaDefinition #The items in the schema definition.
Default: No items definition
This field is used for array types to define the structure of the array elements.
propertiesoptional{ [key: string]: SchemaDefinition }propertiesoptionaltyping.Mapping[str, SchemaDefinition]propertiesoptionalMap<String, SchemaDefinition>PropertiesoptionalIDictionary<string, SchemaDefinition>Propertiesoptional*map[string]SchemaDefinition #The properties of the schema definition.
Default: No properties
These properties define the fields in the schema.
requiredoptionalstring[]requiredoptionaltyping.List[str]requiredoptionalList<String>Requiredoptionalstring[]Requiredoptional*[]*string #The required fields in the schema definition.
Default: No required fields
These fields must be provided when using the schema.
typeSchemaDefinitionTypetypeSchemaDefinitionTypetypeSchemaDefinitionTypeTypeSchemaDefinitionTypeTypeSchemaDefinitionType required #The type of the schema definition.
This field specifies the data type of the schema.