
Tool calling transforms your AI agents from simple chatbots into powerful assistants that can interact with real-world systems. With tool calling, you can build agents that fetch live weather data, query databases, execute API calls, and deliver accurate, data-driven responses, all through the Vultr Serverless Inference endpoint.
Vultr Serverless Inference removes the complexity of infrastructure management. You don't deploy servers, handle cold starts, or write custom API wrappers. You simply define your tools, connect to Vultr's Serverless Inference endpoint, and start building intelligent, function-aware applications.
Follow this guide to implement tool calling with the kimi-k2-instruct model hosted on Vultr Serverless Inference. You will learn how to define function schemas, send tool-enabled requests, execute functions with real data, and return the results to generate contextual, natural-language responses.
Before you begin, you need to:
In this section, you send a tool-enabled request to the Vultr Serverless Inference API using cURL. This helps you test tool definitions, verify model behavior, and confirm that tool calls function as expected before integrating them into your application.
The example below defines a simple get_horoscope function. You first send a request that triggers a tool call, then send another request that returns the executed result to complete the interaction.
Export your Vultr Inference API key.
Send a user message and define the tool schema.
In the above curl request:
kimi-k2-instruct supports tool calling and can invoke defined functions automatically."user" indicates the message comes from the end user."What is my horoscope? I am an Aquarius.""function" for function-based tools."get_horoscope") used when the model issues a tool call."object"."string"), and purpose ("An astrological sign like Taurus or Aquarius").sign field must be present for this function."none": disables tool calls."auto": lets the model decide when to call tools (default)."required": forces at least one tool call.Output:
The response shows that the model successfully recognized the defined tool and generated a structured tool call instead of a final message. It identifies the function to execute (get_horoscope) and includes the parsed argument ("sign": "Aquarius"). The finish_reason value "tool_calls" indicates that the model has paused its response, waiting for your application to run the specified function and return the result in a follow-up request before completing the conversation.
Send a response back with a static value to demonstrate a function call.
In the above request:
"assistant", representing the model's tool call request. This message includes the function name (get_horoscope) and its arguments."id" uniquely identifies this call for linking the response."tool", indicating that this message contains the function's execution result."id" from the assistant's tool call, ensuring the model correctly associates the response with the right tool call."auto", allowing the model to decide whether additional tool calls are required or to finalize the conversation.This request defines a static tool response to simulate a completed function call. The model interprets the returned data and generates a natural-language reply, even though no actual function execution occurs.
Output:
The model receives the tool output, integrates it into its reasoning, and produces a complete natural-language response. The finish_reason value "stop" indicates that the model has successfully completed the conversation without requiring further tool calls.
In this section, you perform the same tool-calling workflow using Python. This approach is ideal for integrating tool calling into real-world applications, where the model’s tool requests are handled programmatically. This example script demonstrates how to define a local function, detect a tool call from the model, execute the function, and send the result back to the model for a final, natural-language response.
This script uses a real-time weather API call. You can replace the mock logic or extend the script to support multiple tools and data sources.
Download the sample script.
The script performs the following steps:
get_weather(city) fetches real weather data for a given city."What's the weather like in New Delhi?").Create a Python environment and activate it.
Install the required dependencies.
Export your Vultr Inference API key as an environment variable.
Execute the Python script.
When you run the script, it prompts you to enter a city name.
Output:
The script automatically retrieves real-time weather data for the entered city, processes it through the model using Vultr Serverless Inference, and returns a conversational natural-language response describing the weather conditions.
You have successfully implemented tool calling using Vultr Serverless Inference with the kimi-k2-instruct model. You defined custom tool schemas, sent requests that triggered model-initiated function calls, and returned structured outputs for contextual responses. Using both cURL and Python, you simulated and executed real function calls including fetching live weather data.
0 Comments
Be the first to comment and share your perspective with the community.