Skip to content
v2.278.0

Experimental

@aws-cdk/aws-bedrock-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

InlineApiSchema Class ​

Class to define an API Schema from an inline string.

The schema can be provided directly as a string in either JSON or YAML format.

Example ​

ts
const inlineSchema = bedrock.ApiSchema.fromInline(`
openapi: 3.0.3
info:
  title: Library API
  version: 1.0.0
paths:
  /search:
    get:
      summary: Search for books
      operationId: searchBooks
      parameters:
        - name: query
          in: query
          required: true
          schema:
            type: string
`);

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: inlineSchema,
});

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
inline_schema = bedrock.ApiSchema.from_inline("""
    openapi: 3.0.3
    info:
      title: Library API
      version: 1.0.0
    paths:
      /search:
        get:
          summary: Search for books
          operationId: searchBooks
          parameters:
            - name: query
              in: query
              required: true
              schema:
                type: string
    """)

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=inline_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
InlineApiSchema inlineSchema = ApiSchema.fromInline("\nopenapi: 3.0.3\ninfo:\n  title: Library API\n  version: 1.0.0\npaths:\n  /search:\n    get:\n      summary: Search for books\n      operationId: searchBooks\n      parameters:\n        - name: query\n          in: query\n          required: true\n          schema:\n            type: string\n");

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(inlineSchema)
        .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 inlineSchema = ApiSchema.FromInline(@"
openapi: 3.0.3
info:
  title: Library API
  version: 1.0.0
paths:
  /search:
    get:
      summary: Search for books
      operationId: searchBooks
      parameters:
        - name: query
          in: query
          required: true
          schema:
            type: string
");

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 = inlineSchema
});

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
inlineSchema := bedrock.ApiSchema_FromInline(jsii.String(`
openapi: 3.0.3
info:
  title: Library API
  version: 1.0.0
paths:
  /search:
    get:
      summary: Search for books
      operationId: searchBooks
      parameters:
        - name: query
          in: query
          required: true
          schema:
            type: string
`))

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: inlineSchema,
})

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)

Initializer ​

ts
new InlineApiSchema(schema: string)
python
InlineApiSchema(schema: str)
java
new InlineApiSchema(String schema)
csharp
new InlineApiSchema(string schema)
go
NewInlineApiSchema(Schema *string)

Properties ​

inlineSchemamay be undefinedstringinline_schemamay be undefinedstrinlineSchemamay be undefinedStringInlineSchemamay be undefinedstringInlineSchemamay be undefined*string #
The inline OpenAPI schema definition as a string, if using an inline schema.

Can be in JSON or YAML format.

s3Filemay be undefinedLocations3_filemay be undefinedLocations3Filemay be undefinedLocationS3Filemay be undefinedLocationS3Filemay be undefinedLocation #
The S3 location of the API schema file, if using an S3-based schema.

Contains the bucket name and object key information.

Methods ​

fromInline(schema: string): InlineApiSchema // chainable@staticmethod def from_inline(schema: str) -> InlineApiSchemapublic static InlineApiSchema fromInline(String schema)public static InlineApiSchema FromInline(string schema)func FromInline(Schema *string) InlineApiSchema static #
Creates an API Schema from an inline string.
1 parameter

Parameters

  • schemaschemaschemaschemaSchema — - the JSON or YAML payload defining the OpenAPI schema for the action group.
fromLocalAsset(path: string): AssetApiSchema@staticmethod def from_local_asset(path: str) -> AssetApiSchemapublic static AssetApiSchema fromLocalAsset(String path)public static AssetApiSchema FromLocalAsset(string path)func FromLocalAsset(Path *string) AssetApiSchema static #
Creates an API Schema from a local file.
1 parameter

Parameters

  • pathpathpathpathPath — - the path to the local file containing the OpenAPI schema for the action group.
fromS3File(bucket: IBucketRef, objectKey: string): S3ApiSchema@staticmethod def from_s3_file(bucket: IBucketRef, object_key: str) -> S3ApiSchemapublic static S3ApiSchema fromS3File(IBucketRef bucket, String objectKey)public static S3ApiSchema FromS3File(IBucketRef bucket, string objectKey)func FromS3File(Bucket IBucketRef, ObjectKey *string) S3ApiSchema static #
Creates an API Schema from an S3 File.
2 parameters

Parameters

  • bucketbucketbucketbucketBucket — - the bucket containing the local file containing the OpenAPI schema for the action group.
  • objectKeyobject_keyobjectKeyobjectKeyObjectKey — - object key in the bucket.