Client side tools in the Android SDK

Register a ClientTool so your agent can run code inside your Android app, such as opening a screen or reading a value from the device.

Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.

A client tool is a function in your app that the agent can call during a conversation. The agent decides when to call it, the SDK runs your code, and the result goes back to the agent so it can continue its answer. Use client tools for things only the app can do: open an order screen, read the current cart, or turn on a setting.

How a call flows

  1. The customer sends a message and the agent decides a tool is needed.
  2. The stream delivers a ToolCall event with the tool name and arguments.
  3. The SDK finds your registered ClientTool and runs its handler.
  4. The SDK sends the handler result back to the agent.
  5. The agent writes the rest of the answer, using the result.

The same flow exists on the web as client side custom actions, and in the REST API as client actions.

Register a tool

val openOrder = ClientTool(
    name = "open_order_screen",
    description = "Open the order details screen for an order id.",
    parameters = buildJsonObject {
        put("type", "object")
        putJsonObject("properties") {
            putJsonObject("orderId") { put("type", "string") }
        }
        putJsonArray("required") { add("orderId") }
    },
    handler = { args ->
        val id = args["orderId"]?.jsonPrimitive?.content
            ?: return@ClientTool buildJsonObject { put("opened", false) }
        navigator.openOrder(id)
        buildJsonObject { put("opened", true) }
    },
)

octo.registerTool(openOrder)
Field Description
name A stable identifier, lowercase with underscores.
description A plain sentence that tells the agent when to use the tool.
parameters A JSON Schema object that describes the arguments.
handler A suspend lambda that receives the arguments as a JsonObject and returns a JsonObject.

Register tools once, right after you create the client. Registering a second tool with the same name replaces the first.

Write good handlers

  • Return quickly. Long work blocks the answer. If you must wait for a user action, return a result that says so.
  • Return small JSON. Include only facts the agent can use, such as { "opened": true }.
  • Throw nothing. Catch errors inside the handler and return { "error": "..." }, so the agent can explain the problem to the customer.
  • Check permissions in the handler. The agent chooses when to call a tool, so treat arguments as untrusted input.

Warning: Never expose a tool that changes money or personal data without a confirmation step in your own UI. The agent can call any tool you register.

Test it

Ask the agent a question that should trigger the tool, then watch for the ToolCall event in your stream. Set up the matching behavior under the agent's Actions tab, and try the full conversation in the Playground before you ship the app.

Something unclear or missing? Tell us and we will fix the page.