Skip to content
v2.277.0

Experimental

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

ToolConfiguration Struct ​

Configuration for tools available to the model.

Example ​

ts
const cmk = new kms.Key(this, 'cmk', {});

const variantChat = bedrock.PromptVariant.chat({
  variantName: 'variant1',
  model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
  messages: [
    bedrock.ChatMessage.user('From now on, you speak Japanese!'),
    bedrock.ChatMessage.assistant('Konnichiwa!'),
    bedrock.ChatMessage.user('From now on, you speak {{language}}!'),
  ],
  system: 'You are a helpful assistant that only speaks the language you`re told.',
  promptVariables: ['language'],
  toolConfiguration: {
    toolChoice: bedrock.ToolChoice.AUTO,
    tools: [
      bedrock.Tool.function({
        name: 'top_song',
        description: 'Get the most popular song played on a radio station.',
        inputSchema: {
          type: 'object',
          properties: {
            sign: {
              type: 'string',
              description: 'The call sign for the radio station for which you want the most popular song. Example calls signs are WZPZ and WKR.',
            },
          },
          required: ['sign'],
        },
      }),
    ],
  },
});

new bedrock.Prompt(this, 'prompt1', {
  promptName: 'prompt-chat',
  description: 'my first chat prompt',
  defaultVariant: variantChat,
  variants: [variantChat],
  kmsKey: cmk,
});
python
cmk = kms.Key(self, "cmk")

variant_chat = bedrock.PromptVariant.chat(
    variant_name="variant1",
    model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
    messages=[
        bedrock.ChatMessage.user("From now on, you speak Japanese!"),
        bedrock.ChatMessage.assistant("Konnichiwa!"),
        bedrock.ChatMessage.user("From now on, you speak {{language}}!")
    ],
    system="You are a helpful assistant that only speaks the language you`re told.",
    prompt_variables=["language"],
    tool_configuration=bedrock.ToolConfiguration(
        tool_choice=bedrock.ToolChoice.AUTO,
        tools=[
            bedrock.Tool.function(
                name="top_song",
                description="Get the most popular song played on a radio station.",
                input_schema={
                    "type": "object",
                    "properties": {
                        "sign": {
                            "type": "string",
                            "description": "The call sign for the radio station for which you want the most popular song. Example calls signs are WZPZ and WKR."
                        }
                    },
                    "required": ["sign"]
                }
            )
        ]
    )
)

bedrock.Prompt(self, "prompt1",
    prompt_name="prompt-chat",
    description="my first chat prompt",
    default_variant=variant_chat,
    variants=[variant_chat],
    kms_key=cmk
)
java
Key cmk = Key.Builder.create(this, "cmk").build();

IPromptVariant variantChat = PromptVariant.chat(ChatPromptVariantProps.builder()
        .variantName("variant1")
        .model(BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0)
        .messages(List.of(ChatMessage.user("From now on, you speak Japanese!"), ChatMessage.assistant("Konnichiwa!"), ChatMessage.user("From now on, you speak {{language}}!")))
        .system("You are a helpful assistant that only speaks the language you`re told.")
        .promptVariables(List.of("language"))
        .toolConfiguration(ToolConfiguration.builder()
                .toolChoice(ToolChoice.AUTO)
                .tools(List.of(Tool.function(FunctionToolProps.builder()
                        .name("top_song")
                        .description("Get the most popular song played on a radio station.")
                        .inputSchema(Map.of(
                                "type", "object",
                                "properties", Map.of(
                                        "sign", Map.of(
                                                "type", "string",
                                                "description", "The call sign for the radio station for which you want the most popular song. Example calls signs are WZPZ and WKR.")),
                                "required", List.of("sign")))
                        .build())))
                .build())
        .build());

Prompt.Builder.create(this, "prompt1")
        .promptName("prompt-chat")
        .description("my first chat prompt")
        .defaultVariant(variantChat)
        .variants(List.of(variantChat))
        .kmsKey(cmk)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.AWS.Bedrock.Alpha
var cmk = new Key(this, "cmk", new KeyProps { });

var variantChat = PromptVariant.Chat(new ChatPromptVariantProps {
    VariantName = "variant1",
    Model = BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
    Messages = new [] { ChatMessage.User("From now on, you speak Japanese!"), ChatMessage.Assistant("Konnichiwa!"), ChatMessage.User("From now on, you speak {{language}}!") },
    System = "You are a helpful assistant that only speaks the language you`re told.",
    PromptVariables = new [] { "language" },
    ToolConfiguration = new ToolConfiguration {
        ToolChoice = ToolChoice.AUTO,
        Tools = new [] { Tool.Function(new FunctionToolProps {
            Name = "top_song",
            Description = "Get the most popular song played on a radio station.",
            InputSchema = new Dictionary<string, object> {
                { "type", "object" },
                { "properties", new Struct {
                    Sign = new Struct {
                        Type = "string",
                        Description = "The call sign for the radio station for which you want the most popular song. Example calls signs are WZPZ and WKR."
                    }
                } },
                { "required", new [] { "sign" } }
            }
        }) }
    }
});

new Prompt(this, "prompt1", new PromptProps {
    PromptName = "prompt-chat",
    Description = "my first chat prompt",
    DefaultVariant = variantChat,
    Variants = new [] { variantChat },
    KmsKey = cmk
});
go
// Install: go get github.com/aws/aws-cdk-go/awsbedrockalpha/v2
cmk := kms.NewKey(this, jsii.String("cmk"), &KeyProps{
})

variantChat := bedrock.PromptVariant_Chat(&ChatPromptVariantProps{
	VariantName: jsii.String("variant1"),
	Model: bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_3_5_SONNET_V1_0(),
	Messages: []ChatMessage{
		bedrock.ChatMessage_User(jsii.String("From now on, you speak Japanese!")),
		bedrock.ChatMessage_Assistant(jsii.String("Konnichiwa!")),
		bedrock.ChatMessage_*User(jsii.String("From now on, you speak {{language}}!")),
	},
	System: jsii.String("You are a helpful assistant that only speaks the language you`re told."),
	PromptVariables: []*string{
		jsii.String("language"),
	},
	ToolConfiguration: &ToolConfiguration{
		ToolChoice: bedrock.ToolChoice_AUTO(),
		Tools: []Tool{
			bedrock.Tool_Function(&FunctionToolProps{
				Name: jsii.String("top_song"),
				Description: jsii.String("Get the most popular song played on a radio station."),
				InputSchema: map[string]interface{}{
					"type": jsii.String("object"),
					"properties": map[string]map[string]*string{
						"sign": map[string]*string{
							"type": jsii.String("string"),
							"description": jsii.String("The call sign for the radio station for which you want the most popular song. Example calls signs are WZPZ and WKR."),
						},
					},
					"required": []*string{
						jsii.String("sign"),
					},
				},
			}),
		},
	},
})

bedrock.NewPrompt(this, jsii.String("prompt1"), &PromptProps{
	PromptName: jsii.String("prompt-chat"),
	Description: jsii.String("my first chat prompt"),
	DefaultVariant: variantChat,
	Variants: []IPromptVariant{
		variantChat,
	},
	KmsKey: cmk,
})

Properties ​

toolChoiceToolChoicetool_choiceToolChoicetoolChoiceToolChoiceToolChoiceToolChoiceToolChoiceToolChoice required #
How the model should choose which tool to use.
toolsTool[]toolstyping.List[Tool]toolsList<Tool>ToolsTool[]Tools*[]Tool required #
The tools available to the model.