Skip to main content

What Are Client-Side Tools?

Client-side tools let your agent invoke functions that run locally on the Android device. Register a handler, and the SDK takes care of the rest — when the agent calls the tool, your handler runs and the result is fed back into the conversation automatically.
Client-side tools correspond to Custom Actions configured on your agent in the Chatbase Dashboard. The toolName in the SDK matches the name of the configured action.

tool

interface ChatbaseClientPackage: com.chatbase.sdk
Register a client-side tool handler.
String
required
The tool name. Must match a Custom Action configured on your agent.
suspend (Map<String, Any?>) -> Any
required
A suspend function that receives the parsed input and returns a result.
The agent can now call get_weather during a conversation. The SDK executes your handler and feeds the result back automatically. This loop can repeat up to 10 times per sendMessage call — if the agent requests more, sendMessage throws a ChatbaseException (“Tool loop exceeded maximum iterations”).
Tool results are limited to 20 KB when serialized to JSON. Keep tool outputs concise — return only the data the agent needs.

removeTool

Unregister a previously registered tool handler.
String
required
The tool name to remove.

Tracking Execution

Use the onToolCall and onToolResult callbacks to observe tool execution:

ToolCallInfo

data class ToolCallInfoPackage: com.chatbase.sdk Passed to the onToolCall callback before handler execution.
Parse the JSON input into a Map<String, Any?> for easy access.

ToolResultInfo

data class ToolResultInfoPackage: com.chatbase.sdk Passed to the onToolResult callback after handler execution.
Serialize the output to a JSON string.

Interactive Tools

Since handlers are suspend functions, they can block on user interaction. For example, showing a color picker and waiting for the user’s choice:

Streaming

Streaming callbacks and Kotlin Flow

Error Handling

Handle errors during tool execution