Client Tools
Let AI assistants call tools executed by your application (such as querying systems accessible only on an internal network). Learn how to declare client tools in the conversation API, identify model c
Client tools let AI assistants call tools that run in your application. You declare a list of tools each time you call the conversation API. When the model decides it needs a tool, MaiAgent returns which tool to call and what arguments to pass instead of executing it itself. Your application executes the tool locally and sends the result back to the conversation. The model then uses the result to continue answering or call the next tool.
Use client tools for actions only your application can perform, such as querying systems accessible only on your company's internal network, using a browser extension to interact with the currently open page, or accessing resources on a user's device through an app.
Use Case
An engineer at an e-commerce company integrates an AI assistant into the company's internal customer service console. The order system is accessible only on the internal network. A customer service representative enters “A customer asks when order A1024 will arrive” in the console. When calling the conversation API, the console also declares an order lookup tool. The model returns which order to look up. The console retrieves the shipping status on the internal network and sends it back to the same conversation. The model uses this information to write a reply for the customer. The order system does not need to be exposed externally, and the console sends only the data the model needs.
Requirements
Client tools are available to all organizations without a separate application. For the model to call them, both conditions must be met:
The AI assistant's response mode is set to Agent mode.
The model used by the AI assistant supports tool calling.
Workflow
Declare Tools
{
"conversation": "<Conversation ID; optional for the first message>",
"isStreaming": false,
"message": {
"content": "A customer asks when order A1024 will arrive.",
"clientTools": [
{
"name": "get_order",
"description": "Look up an order's shipping status and estimated delivery date by order number",
"inputSchema": {
"type": "object",
"properties": {
"order": { "type": "string", "description": "Order number" }
},
"required": ["order"]
}
}
]
}
}name
string
Tool name. Only alphanumeric characters, underscores _, and hyphens - are allowed. Length must be 1–64 characters, and names must be unique within a request.
description
string
A description of the tool's purpose. The model uses it to decide when to use the tool, so write it clearly.
inputSchema
object
JSON Schema for the tool's arguments. Must not exceed 4,000 characters when serialized.
Tool Call Request Format
When the model requests a tool call, contentPayload.items includes an item like the following. There may be multiple items at once:
type
string
Always client_tool_call.
toolCallId
string | null
Call identifier generated by the model.
name
string
Name of the tool to execute, matching the name you declared.
input
object
Arguments supplied by the model, corresponding to the inputSchema you declared.
startTimestamp
string | null
Time the call started.
Non-Streaming and Streaming Differences
Non-streaming (
isStreaming: false): Tool call items are incontentPayload.itemsin the response body (done: true).Streaming (
isStreaming: true): Tool call items are sent as separate events. Each event hasdoneset tofalse, an emptycontentstring, andclient_tool_callincontentPayload.items. The finaldone: trueevent does not repeat these items, so collect them during streaming.
Return Execution Results
There is currently no dedicated endpoint for submitting tool results. Send the next regular message in the same conversation, putting the result in message.content:
Multiple tool calls at once: Execute all of them, then combine each tool's results into a single message.
Include the tool name and
toolCallId: The backend does not usetoolCallIdfor matching, but including it in the result text helps the model identify which call the result belongs to.Execution failure or user rejection: Explain this in text as well, such as “get_order failed: order not found” or “The user declined this operation.” The model adjusts its answer or uses another approach accordingly.
Result length: Returned content counts toward the model's input. For large amounts of data, extract the required portions first.
Call Multiple Tools Across Turns
Each cycle of “the model requests a call → you return the result” is one turn. The model can call tools over multiple turns until its response no longer contains client_tool_call and instead returns the final text. Set a turn limit in your application to prevent an infinite loop if something goes wrong.
Frequently Asked Questions
Last updated
Was this helpful?