Client actions
Let an agent ask your app to run an action, such as looking up an order, then return the result with the tool result endpoint so the agent can continue.
Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.
A client action is an action that your app carries out, not Askocto. The agent decides when it is needed, asks your app to run it and waits for the result. Use client actions for things only your app can do, such as reading the cart in the browser, checking a session or calling an internal system.
On the website widget you register a handler with registerAction, see Client-side custom actions. The mobile SDKs offer the same idea as ClientTool, see the iOS client-side tools and Android client-side tools. This page covers the REST flow.
How the flow works
- You send a message with Chat with an agent.
- The agent decides that a client action is needed. Instead of a final answer, you get a tool call with an ID, a name and arguments.
- Your app runs the action.
- You send the outcome with Submit a tool result.
- The agent continues and returns its answer to the customer.
Receive a tool call
Without streaming, the chat response has a toolCalls array and the message content is empty:
{
"conversationId": "conv_5n2p8w",
"message": {
"id": "msg_7c1k9s",
"role": "assistant",
"content": "",
"sources": []
},
"toolCalls": [
{
"toolCallId": "call_6t2x9a",
"name": "getOrderStatus",
"arguments": { "orderNumber": "1042" }
}
],
"usage": { "credits": 1 }
}
With "stream": true, the same data arrives as a tool.call event, see Streaming.
Return the result
Send the conversationId and the toolCallId back with your result:
curl -X POST https://api.askocto.co/v2/agents/agt_8f3k2m/chat/tool-results \
-H "Authorization: Bearer $OCTO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"conversationId": "conv_5n2p8w",
"toolCallId": "call_6t2x9a",
"result": { "status": "shipped", "expectedDelivery": "2026-03-18" }
}'
The response is the next assistant message, in the same shape as a chat response. It may hold another tool call, so loop until toolCalls is missing or empty.
A complete loop
const base = "https://api.askocto.co/v2/agents/agt_8f3k2m/chat"
const headers = {
Authorization: `Bearer ${process.env.OCTO_API_KEY}`,
"Content-Type": "application/json",
}
const handlers = {
getOrderStatus: async ({ orderNumber }) => ({ status: "shipped", orderNumber }),
}
let response = await fetch(base, {
method: "POST",
headers,
body: JSON.stringify({ messages: [{ role: "user", content: "Where is order 1042?" }] }),
})
let reply = await response.json()
while (reply.toolCalls?.length) {
const call = reply.toolCalls[0]
const result = await handlers[call.name](call.arguments)
response = await fetch(`${base}/tool-results`, {
method: "POST",
headers,
body: JSON.stringify({
conversationId: reply.conversationId,
toolCallId: call.toolCallId,
result,
}),
})
reply = await response.json()
}
console.log(reply.message.content)
Good practice
- Treat
argumentsas untrusted input. Validate them before you use them. - Return only what the agent needs. Do not include secrets or internal IDs.
- If your app cannot run the action, send
"error": "Order lookup timed out."instead of aresult, so the agent can tell the customer what happened. - Answer every tool call. The conversation waits for the result.