> **Experimental**
>
> `@aws-cdk/aws-bedrock-alpha` is an [**experimental**](https://docs.aws.amazon.com/cdk/api/stability.html) (alpha) package: its API may change in any release, without a major version bump.
# ToolChoice

Defines how the model should choose which tool to use.

Obtainable from: ToolChoice.ANY, ToolChoice.AUTO, ToolChoice.specificTool

- Stability: [Experimental](https://docs.aws.amazon.com/cdk/api/stability.html)
- Source: [`bedrock/prompts/tool-choice.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/@aws-cdk/aws-bedrock-alpha/bedrock/prompts/tool-choice.ts#L80)

## Example

TypeScript:

```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:

```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:

```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();
```

C# / .NET:

```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
});
```

Golang:

```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,
})
```

## Initializer

TypeScript:

```ts
new ToolChoice(any: any, auto: any, tool?: string)
```

Python:

```python
ToolChoice(any: Any, auto: Any, tool: typing.Optional[str] = None)
```

Java:

```java
new ToolChoice(Object any, Object auto, String tool)
```

C# / .NET:

```csharp
new ToolChoice(object any, object auto, string? tool = null)
```

Golang:

```go
NewToolChoice(Any interface{}, Auto interface{}, Tool *string)
```

## Properties

- `any`: any — Configuration for ANY tool choice.

- `ANY`: [ToolChoice](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-alpha.ToolChoice.html) (static) — The model must request at least one tool (no text is generated).

- `auto`: any — Configuration for AUTO tool choice.

- `AUTO`: [ToolChoice](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-alpha.ToolChoice.html) (static) — (Default).

  The Model automatically decides if a tool should be called or whether to generate text instead.

- `tool`: string — The specific tool name if using specific tool choice.

## Methods

- `specificTool(toolName: string): ToolChoice // chainable` (static) — The Model must request the specified tool.

  Only supported by some models like Anthropic Claude 3 models.

  **Parameters**

  - `toolName` — - The name of the specific tool to use.

  **Returns:** A ToolChoice instance configured for the specific tool
