A guide to integrating and utilizing tools with NeosantaraAI models for enhanced capabilities.
function_calling
capabilities are suitable for tool use. For complex tools and ambiguous queries, models like nusantara-base
, gpt-4o-mini
, gemini-1.5-pro
, or command-r-plus
are recommended as they handle tool selection and parameter inference more robustly.
For more straightforward tools, models like bahasa-llm
or gemini-1.5-flash
can be effective.
tools
top-level parameter of your API request. Each tool definition includes:
Parameter | Description |
---|---|
type | Must be "function" . |
function | An object defining the function’s metadata, including its name, description, and parameters. |
name | (within function ): The name of the tool. Must match the regex ^[a-zA-Z0-9_-]{1,64}$ . |
description | (within function ): A detailed plaintext description of what the tool does, when it should be used, and how it behaves. This is crucial for the model to understand the tool’s purpose. |
parameters | (within function ): A JSON Schema object defining the expected parameters for the tool. This schema describes the input the tool expects. |
Example Simple Tool Definition
get_weather
, expects an input object with a required location
string and an optional unit
string that must be either “celsius” or “fahrenheit”.Example of a Good Tool Description
Example Poor Tool Description
ticker
parameter means. The poor description is too brief and leaves the model with many open questions about the tool’s behavior and usage.
tool_choice
field.
The tool_choice
parameter offers four possible options:
auto
: (Default when tools
are provided) Allows the model to decide whether to call any provided tools or not.any
: Tells the model that it must use one of the provided tools, but doesn’t force a particular tool.{"type": "function", "function": {"name": "your_tool_name"}}
: Allows you to force the model to always use a particular tool.none
: Prevents the model from using any tools. (Default when no tools
are provided).tool_choice: "auto"
(the default) and add explicit instructions in a user message. For example: "What's the weather like in London? Use the get_weather tool in your response."
record_summary
tool with a particular schema to extract structured data from text or images.
When using tools for JSON output:
tool_choice
to {"type": "function", "function": {"name": "your_tool_name"}}
to instruct the model to explicitly use that tool.function
’s parameters
define the exact JSON schema the model should adhere to.get_weather
and get_time
tools are available.tool_calls
for get_weather(location='Jakarta, ID')
and get_time(timezone='Asia/Jakarta')
.tool_calls
and feed the results back to the model.
finish_reason
of tool_calls
and one or more tool_calls
content blocks within the assistant’s message. These blocks include:
id
: A unique identifier for this particular tool call. This will be used to match up the tool results later.type
: Always "function"
.function
: An object containing the name of the tool (name
) and the arguments (arguments
) to be passed to it as a JSON string.Example API Response with `tool_calls` Content Block
name
, id
, and arguments
(parsing the JSON string) from the tool_calls
block.role
of tool
, and a content
block containing the result of your tool’s execution. This message must also include the tool_call_id
to link it back to the original tool request.
tool_call_id
: The id
of the tool_calls
request this is a result for.content
: The result of the tool, as a string. For complex results, it’s often a JSON string.is_error
(optional): Set to true
if the tool execution resulted in an error. NeosantaraAI will then incorporate this error into its response."role": "tool"
) must always immediately follow their corresponding assistant
message that contained the tool_calls
. You cannot include any other messages between them.tool
messages must be provided in a single messages
array in the subsequent API call.Example of Successful Tool Result
Example of Tool Result with Error
content
along with "is_error": true
:assistant
’s tool_calls
message must be sent in a single tool
message (each result in its own content block if there were multiple parallel calls with tool_call_id
and content
).
2. Weak Prompting
While models generally attempt parallel calls, you can use stronger language in your prompts to encourage it, for example: “Please use parallel tool calls to get the weather for Jakarta and Bandung at the same time.”
3. Model-Specific Behavior
Different models may have varying propensities for parallel tool use. Experiment with different models to find one that suits your needs.
description
values in your tool definitions.
If a tool request is invalid or missing parameters, NeosantaraAI will typically retry 2-3 times with corrections before apologizing to the user. You can also return an error in the tool
message by setting "is_error": true
in its content.
tools
parameter and tool call/result messages).usage
metrics.