Reactive Machines

To select an instrument with Amazon Nova Models

In many AI tests, the largest language model (llm) as Amazon Nova is used to answer the user question or model in the model itself. However, as cases of mature use, the power to obtain access to the tools or structures that can be without the modeling fitness framework is very important. This can be API, the operations of the code, or schemas and structures required by your final application. This power has been developed to what is referred to as Use of tools or To call.

In addition to the clean controlling control of how to use the tools used, we have issued the Amazon Nova models selection tool. Instead of depending on the instant engineer, the selection of tools forces a local setting model.

In this post, we discuss the use of tools and a new feature of the selection tool, for example use charges.

Tool Use by Amazon Nova

Showing the idea of ​​using the tool, we can consider the situation where we provide different Amazon tools based on the user question, Amazon Nova will select the appropriate tool and tell you how to use it. For example, if the user asks “What is the weather in Seattle?” Amazon Nova will use the weather tool.

The following drawing is indicating the impression of the example between the Amazon Nova model, its available tools, and external related resources.

The use of tools in the main environment for the designation of the tool and its parameters. Obligation to make foreign performance to apply or developer. After the tool is performed by the app, you can take the results to the last generation model.

Let us examine some examples about many details. The following drawing is indicating the Amazon Nova Model Model to access the weather API, and return the answer to the user.

The following drawing is indicating the action of the Amazon Nova model using the phone to access the calculator tool.

To select an instrument with Amazon Nova

This page toolChoice API parameter allows you to control the device. There are three supported options for this parameter:

  • Any – by choosing the tool AnyThe model will select at least one of the tools available each time:
    {
       "toolChoice": {
            "any": {}
        }
    }

  • Tool – by choosing the tool ToolThe model will always use the requested instrument:
    {
       "toolChoice": {
            "tool": {
                "name": "name_of_tool"
            }
        }
    }

  • Play – to select a tool Auto Is automatic behavior and will leave the selection of tools to achieve model:
    {
       "toolChoice": {
            "auto": {}
        }
    }

A famous plan to develop model consulting skills to use a series of thought. When using the selection of tools for autoAmazon Nova will use a series of thought and the model feedback will include both reasons and tool selected.

This behavior will vary in terms of the application. When tool or any It is selected as selection of tools, Amazon Nova will only remove the tools and not release of the thought.

Use charges

At this stage, we examine different cases of use to the tool activation.

Output / JSON mode

In some cases, you may want Amazon Nova to use a particular tool to answer the user's question, whether Amazon Nova believes that you can give the answer without using the tool. The general charge of the use of this method enables exit / JSON mode. It is usually very important that the llms is returned to formal exit, because this enables the capacity of the river to effectively use and process the results produced. In these cases, employed tools do not need to be the customer service – can be used whenever model is required to hold a pre-defined schema, thus enforcing the Amazon Nova to use the specified tool.

When using the correct compelling tools, you give one tool with a descriptive JSON inputSchema. You specify the tool with {"tool" : {"name" : "Your tool name"}}. The model will transfer tool to install tool, so the tool name and its meaning should be in a model view.

For example, consider the food web site. If you are provided for a container, a website can issue a receptive details, such as the cooktime, ingredients, the new reservation, and the difficulty of the level, to facilitate users' search and sorting skills. See the following model code:

import boto3
import json

tool_config = {
    "toolChoice": {
        "name": { "tool" : "extract_recipe"}
    },
    "tools": [
        {
            "toolSpec": {
                "name": "extract_recipe",
                "description": "Extract recipe for cooking instructions",
                "inputSchema": {
                    "json": {
                        "type": "object",
                        "properties": {
                            "recipe": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Name of the recipe"
                                    },
                                    "description": {
                                        "type": "string",
                                        "description": "Brief description of the dish"
                                    },
                                    "prep_time": {
                                        "type": "integer",
                                        "description": "Preparation time in minutes"
                                    },
                                    "cook_time": {
                                        "type": "integer",
                                        "description": "Cooking time in minutes"
                                    },
                                    "servings": {
                                        "type": "integer",
                                        "description": "Number of servings"
                                    },
                                    "difficulty": {
                                        "type": "string",
                                        "enum": ["easy", "medium", "hard"],
                                        "description": "Difficulty level of the recipe"
                                    },
                                    "ingredients": {
                                        "type": "array",
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "item": {
                                                    "type": "string",
                                                    "description": "Name of ingredient"
                                                },
                                                "amount": {
                                                    "type": "number",
                                                    "description": "Quantity of ingredient"
                                                },
                                                "unit": {
                                                    "type": "string",
                                                    "description": "Unit of measurement"
                                                }
                                            },
                                            "required": ["item", "amount", "unit"]
                                        }
                                    },
                                    "instructions": {
                                        "type": "array",
                                        "items": {
                                            "type": "string",
                                            "description": "Step-by-step cooking instructions"
                                        }
                                    },
                                    "tags": {
                                        "type": "array",
                                        "items": {
                                            "type": "string",
                                            "description": "Categories or labels for the recipe"
                                        }
                                    }
                                },
                                "required": ["name", "ingredients", "instructions"]
                            }
                        },
                        "required": ["recipe"]
                    }
                }
            }
        }
    ]
}

messages = [{
    "role": "user",
    "content": [
        {"text": input_text},
    ]
}]

inf_params = {"topP": 1, "temperature": 1}

client = boto3.client("bedrock-runtime", region_name="us-east-1")

response = client.converse(
    modelId="us.amazon.nova-micro-v1:0",
    messages=messages,
    toolConfig=tool_config,
    inferenceConfig=inf_params,
    additionalModelRequestFields= {"inferenceConfig": { "topK": 1 } }
)
print(json.dumps(response['output']['message']['content'][0][], indent=2))

We can provide a detailed proposal as text entry:

Legend has it that this decadent chocolate lava cake was born out of a baking mistake in New York's Any Kitchen back in 1987, when chef John Doe pulled a chocolate sponge cake out of the oven too early, only to discover that the dessert world would never be the same. Today I'm sharing my foolproof version, refined over countless dinner parties. Picture a delicate chocolate cake that, when pierced with a fork, releases a stream of warm, velvety chocolate sauce – it's pure theater at the table. While it looks like a restaurant-worthy masterpiece, the beauty lies in its simplicity: just six ingredients (good quality dark chocolate, unsalted butter, eggs, sugar, flour, and a pinch of salt) transform into individual cakes in under 15 minutes. The secret? Precise timing is everything. Pull them from the oven a minute too late, and you'll miss that magical molten center; too early, and they'll be raw. But hit that sweet spot at exactly 12 minutes, when the edges are set but the center still wobbles slightly, and you've achieved dessert perfection. I love serving these straight from the oven, dusted with powdered sugar and topped with a small scoop of vanilla bean ice cream that slowly melts into the warm cake. The contrast of temperatures and textures – warm and cold, crisp and gooey – makes this simple dessert absolutely unforgettable.

We can force Amazon Nova to use a tool extract_recipewhich will produce a JSS systematic effect that sticks to the pre-defined schema provided as a SCHEMA Tool:

 {
  "toolUseId": "tooluse_4YT_DYwGQlicsNYMbWFGPA",
  "name": "extract_recipe",
  "input": {
    "recipe": {
      "name": "Decadent Chocolate Lava Cake",
      "description": "A delicate chocolate cake that releases a stream of warm, velvety chocolate sauce when pierced with a fork. It's pure theater at the table.",
      "difficulty": "medium",
      "ingredients": [
        {
          "item": "good quality dark chocolate",
          "amount": 125,
          "unit": "g"
        },
        {
          "item": "unsalted butter",
          "amount": 125,
          "unit": "g"
        },
        {
          "item": "eggs",
          "amount": 4,
          "unit": ""
        },
        {
          "item": "sugar",
          "amount": 100,
          "unit": "g"
        },
        {
          "item": "flour",
          "amount": 50,
          "unit": "g"
        },
        {
          "item": "salt",
          "amount": 0.5,
          "unit": "pinch"
        }
      ],
      "instructions": [
        "Preheat the oven to 200u00b0C (400u00b0F).",
        "Melt the chocolate and butter together in a heatproof bowl over a saucepan of simmering water.",
        "In a separate bowl, whisk the eggs and sugar until pale and creamy.",
        "Fold the melted chocolate mixture into the egg and sugar mixture.",
        "Sift the flour and salt into the mixture and gently fold until just combined.",
        "Divide the mixture among six ramekins and bake for 12 minutes.",
        "Serve straight from the oven, dusted with powdered sugar and topped with a small scoop of vanilla bean ice cream."
      ],
      "prep_time": 10,
      "cook_time": 12,
      "servings": 6,
      "tags": [
        "dessert",
        "chocolate",
        "cake"
      ]
    }
  }
}

Sentence

Another common situation requires Amazon Nova that you have chosen tool from available options even if the current user's one. One instance for this is the election of the end of the API end. In this case, we do not know how a tool will use, and we allow the model to choose between the available.

For the selection of tools for anyYou can be sure that the model will always use at least one of the tools available. As a result, we offer a tool that can be used when API does not work. Another example can be to provide a tool that allows the specific questions.

In this example, it provides model for two different apis, with an informal API tool to choose based on the user question:

import boto3
import json

tool_config = {
    "toolChoice": {
        "any": {}
    },
    "tools": [
         {
            "toolSpec": {
                "name": "get_all_products",
                "description": "API to retrieve multiple products with filtering and pagination options",
                "inputSchema": {
                    "json": {
                        "type": "object",
                        "properties": {
                            "sort_by": {
                                "type": "string",
                                "description": "Field to sort results by. One of: price, name, created_date, popularity",
                                "default": "created_date"
                            },
                            "sort_order": {
                                "type": "string",
                                "description": "Order of sorting (ascending or descending). One of: asc, desc",
                                "default": "desc"
                            },
                        },
                        "required": []
                    }
                }
            }
        },
        {
            "toolSpec": {
                "name": "get_products_by_id",
                "description": "API to retrieve retail products based on search criteria",
                "inputSchema": {
                    "json": {
                        "type": "object",
                        "properties": {
                            "product_id": {
                                "type": "string",
                                "description": "Unique identifier of the product"
                            },
                        },
                        "required": ["product_id"]
                    }
                }
            }
        },
        {
            "toolSpec": {
                "name": "unsupported_api",
                "description": "API to use when the user query does not relate to the other available APIs",
                "inputSchema": {
                    "json": {
                        "type": "object",
                        "properties": {
                            "reasoning": {
                                "type": "string",
                                "description": "The reasoning for why the user query did not have a valid API available"
                            },
                        },
                        "required": ["reasoning"]
                    }
                }
            }
        }
    ]
}


messages = [{
    "role": "user",
    "content": [
        {"text": input_text},
    ]
}]

inf_params = {"topP": 1, "temperature": 1}

client = boto3.client("bedrock-runtime", region_name="us-east-1")

response = client.converse(
    modelId="us.amazon.nova-micro-v1:0",
    messages=messages,
    toolConfig=tool_config,
    inferenceConfig=inf_params,
    additionalModelRequestFields= {"inferenceConfig": { "topK": 1 } }
)

print(json.dumps(response['output']['message']['content'][0], indent=2))

User installation of “You can get all products available?” will issue the following:

{
  "toolUse": {
    "toolUseId": "tooluse_YCNbT0GwSAyjIYOuWnDhkw",
    "name": "get_all_products",
    "input": {}
  }
}

And “can you get my most recent orders?” will issue the following:

{
  "toolUse": {
    "toolUseId": "tooluse_jpiZnrVcQDS1sAa-qPwIQw",
    "name": "unsupported_api",
    "input": {
      "reasoning": "The available tools do not support retrieving user orders. The user's request is for personal order information, which is not covered by the provided APIs."
    }
  }
}

Discuss search

The last option of tool selection option auto. This is the default behavior, so it is compatible with the choice of tool choices at all.

Using this tool selection will allow the option to use the tool or to extract the text. If the model selects a tool, there will be the toolbar and the text block. If the model responds with no tool, only a block is returned. In the following example, we want to allow model to respond to the user or to drive the tool if necessary:

import boto3
import json

tool_config = {
    "toolChoice": {
        "auto": {}
    },
    "tools": [
         {
            "toolSpec": {
                "name": "search",
                "description": "API that provides access to the internet",
                "inputSchema": {
                    "json": {
                        "type": "object",
                        "properties": {
                            "query": {
                                "type": "string",
                                "description": "Query to search by",
                            },
                        },
                        "required": ["query"]
                    }
                }
            }
        }
    ]
}

messages = [{
    "role": "user",
    "content": [
        {"text": input_text},
    ]
}]

system = [{
    "text": "ou are a helpful chatbot. You can use a tool if necessary or respond to the user query"
}]

inf_params = {"topP": 1, "temperature": 1}

client = boto3.client("bedrock-runtime", region_name="us-east-1")

response = client.converse(
    modelId="us.amazon.nova-micro-v1:0",
    messages=messages,
    toolConfig=tool_config,
    inferenceConfig=inf_params,
    additionalModelRequestFields= {"inferenceConfig": { "topK": 1 } }
)


if (response["stopReason"] == "tool_use"):
    tool_use = next(
        block["toolUse"]
        for block in response["output"]["message"]["content"]
            if "toolUse" in block
    )
   print(json.dumps(tool_use, indent=2))
 else:
    pattern = r'.*?\n\n|.*?'
    text_response = response["output"]["message"]["content"][0]["text"]
    stripped_text = re.sub(pattern, '', text_response, flags=re.DOTALL)
    
    print(stripped_text)

User installation of “What weather is in San Francisco?” It can lead to a tool call:

{
  "toolUseId": "tooluse_IwtBnbuuSoynn1qFiGtmHA",
  "name": "search",
  "input": {
    "query": "what is the weather in san francisco"
  }
}

When asked the model a direct question such as “How many months per year?” You will respond with the text's response to the user:

There are 12 months in a year.

Consideration

There are a few of the best ways to use the tool calling Nova models. The first is to use Greed is greed parameters. With the Amazon Nova model, you need to put the temperature, at the top of P, and top k 1. You can view examples of previous code for how you can set this. Using Coffin Times for Coubleng that force models to produce decent answers and improve the quality of payment of the tool.

The second consideration is JSON Schema that you use for the tools. During the writing, Amazon Nova Models support a limited set of Jon Schemas, so may not be taken as the model expected. Normal fields will be $def including $ref fields. Make sure your schema has higher top fields set: type (must object), propertiesbeside required.

Finally, to find a big impact on the success of a tool for driving tool, you must improve the configuration of your tools. Definitions and words should be clear. If there are nuances where one tool should be called over another, make sure it is directly listed in the tool of tools.

Store

Using the tool to select the tool to drive work is a disabled way to control how the model urges tools. Instead of depending on the instant engineer, the selection of tools forces a local setting model. However, there is difficulties to call the tool; For more information, refer to tools for tools (call call) with Amazon Nova, Tools Tools, Calls for Problem Tools.

Check out the Amazon Nova models can improve your charges for AI today.


About the authors

Jean farmer Is the construction of the AI ​​solutions made from the Amazon Artificial General Intelligence (Agi) a group, special to Agentic applications. Based on Seattle, Washington, works in the communication of the independent AI and practical business systems, helps sharing the future of AGI in Amazon.

Sharon Li Is the construction of the AI ​​/ ML solutions on cutting technology in cutting, Sharon is advanced in developing and fining new AI solutions on the AWS Cloud.

Lulu Wong Ai ux designer in Amazon Artificial General Intelligence (Agi) team. Back in computer science, learning design, and user experience, binding technical and creative backgrounds AIs, and creating AI products readily available to users.

Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button