API · Connect your systems

Tools

A tool is something the avatar's AI can do through your server: look up an order, check a calendar, book a slot, save a lead. You describe it; during the call the AI decides when it's needed, fills in the values from the conversation, and we call your server with them.

What the visitor experiences

What happens
Visitor“Where's my order A4512?”
Avatar, at once“Let me check that for you!” (the holding line)
Behind the scenesWe POST {"values": {"order_id": "A4512"}, …} to your server. It answers {"data": {"status": "shipped", "arrives": "Friday"}}.
Avatar“Your order A4512 shipped on Tuesday with DHL and arrives Friday.”

The pause after the holding line is your server's time plus a fraction of a second. If your server doesn't answer in time, the avatar says it couldn't get the information right now. It never guesses.

Create a tool

POST/v1/agent/{agent_id}/tools
curl -X POST https://talk.selviaai.com/v1/agent/7/tools \
  -H "Authorization: Bearer $SELVIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "check_order",
    "description": "Look up where a customer order is and when it arrives. Use it when the visitor asks about an order and has told you its number (order_id: a letter and 4 to 6 digits, like A4512). Do not use it for returns.",
    "parameters": {
      "type": "object",
      "properties": {"order_id": {"type": "string"}},
      "required": ["order_id"]
    },
    "type": "wait",
    "url": "https://shop.example.com/selvia/tools/check-order",
    "headers": {"Authorization": "Bearer YOUR_OWN_TOKEN"},
    "timeout_s": 5
  }'
FieldRule
nameLowercase letters, digits and _, starting with a letter, at most 64. Unique per agent. Pick a name that says what it does: the AI sees it.
titleOptional. A readable name for people, like “Look up order”: at most 80 characters, one line. The console shows it; the AI never sees it. Each value in parameters can have its own title too (“Order ID”).
descriptionWhen to use it, in plain words, at most 1,000 characters. The most important field: read the next section.
parametersThe values the AI must collect, as a flat JSON Schema object: up to 10 properties of type string, number, integer or boolean, each with an optional enum (up to 20 choices), and a required list. The AI sees each value's name, whether it is required, its enum choices and its description (up to 200 characters). A title per value is for people only. Leave it out for a tool that needs no values.
typewait (default), async or silent. Read “Three types”.
urlYour endpoint. https:// only, a public address. See Your endpoint.
headersUp to 10 of your own headers, such as an API key for your server. Stored encrypted, never shown again (lists show a short hint).
timeout_swait: 1 to 15 s, default 5. async and silent: 1 to 30 s, default 10.
on_callWhat the avatar says while your server works. Read “The holding line”.
on_resolveWhat the AI does with your result. Read “Three types”.
enabledfalse keeps the tool but hides it from the AI.

The first tool or hook you add to an agent comes back with the agent's signing secret (whsec_…), shown that once. Store it on your server to verify our calls.

Write a description the AI can follow

The AI decides from the name, the description and the parameters alone. Write the description like a short brief to a new colleague: what it does, when to use it, and when not to.

WeakStrong
“Orders API.”“Look up where a customer order is and when it arrives. Use it when the visitor asks about an order and has told you its number (order_id: a letter and 4 to 6 digits, like A4512). Do not use it for returns.”
“Book.”“Book a fitting appointment. Use it only after the visitor has chosen a day and a time and said yes to booking. Ask for anything missing first.”
“Save lead.”“Save the visitor's name and phone number when they ask to be called back.”
  • •Required values are asked for. If the visitor hasn't given a required value, the AI asks for it instead of calling. Mark as required everything you can't act without.
  • •Name values plainly and describe each one. The AI sees each value's name, whether it is required, its enum choices and its description, cut at 200 characters. Use clear names (order_id, not oid), say in the value's description what it looks like (“the order number, a letter and 4 to 6 digits, like A4512”), and use enum when only some values are valid. Every description is read before every reply, so keep each one short.
  • •Keep the list short. Every tool is read before every reply. A handful of clearly different tools works best; past about 10, replies get slower and the AI chooses less well.
  • •Test with real phrasing. Talk to the avatar the way your customers will, including the indirect ways (“did my sandals leave yet?”), and adjust the description until it calls the tool when it should, and only then.

Three types

waitasyncsilent
The avatar saysA holding line (“let me check…”), then the answer with your resultThat it has asked and will let them know, then the conversation goes onIts normal reply. Nothing about the tool
Your server is calledWhile the visitor waitsIn the backgroundIn the background
Your resultAnswered at once (on_resolve: answer, the only choice)next_turn (default): used in the next reply. next_pause: the avatar brings it up at the next quiet moment. ignoreignore (default) or next_turn
If it failsThe avatar says it couldn't get it right nowThe AI is told on the next reply that it didn't go throughThe AI is told on the next reply
Use it forLook-ups and actions whose result the visitor is waiting for: order status, availability, bookingSlower jobs: checking with a warehouse, a quote that takes a whileThings the visitor doesn't need to hear about: saving a lead, logging interest, tagging the call

One tool per reply. If the AI needs two things, it calls one, answers, and calls the next on a later reply.

The holding line

on_call sets what the avatar says while a wait or async tool runs:

  • •{"mode": "ai"} (default): the AI says it in its own words, in the visitor's language.
  • •{"mode": "text", "text": {…}}: your own line per language (up to 300 characters each). The visitor's language is used; if you didn't write one for it, the agent's main language, then your first line.
  • •{"mode": "none"}: say nothing. Only for tools that answer in well under a second.

Your own holding line

"on_call": { "mode": "text", "text": { "en": "One moment, I'm checking.", "es": "Un momento, lo compruebo." } }

What your server receives and answers

The request body

{
  "type": "tool",
  "name": "check_order",
  "tool": "check_order",
  "values": { "order_id": "A4512" },
  "turn_id": 4,
  "session_id": "8d137734-f23f-4f1b-8480-0a57b8463ebb",
  "external_user_id": "u_88",
  "agent_id": 7,
  "language": "en",
  "call_id": "c_3fa43d6961bebdc4",
  "sent_at": "2026-11-27T17:46:34Z"
}

values holds what the AI collected, shaped by your parameters. The headers, the signature and the other fields are on Your endpoint.

Your answer (status 200, a JSON object)

{ "data": { "order_id": "A4512", "status": "shipped", "shipped_on": "Tuesday", "carrier": "DHL", "arrives": "Friday" } }

Put what the AI needs to answer in data: any JSON, at most 8,000 characters reach the AI. Leave out what it shouldn't say. You can also return messages, like a mid-call message.

⚠ Your result is used for one reply, then forgotten

The AI sees your data for the reply that answers the visitor, then has no recollection of it: only what it said aloud stays in the conversation. If it said “arrives Friday” and the visitor later asks for the tracking number, the AI no longer has it and will call the tool again, or say it doesn't know. To keep the result for the rest of the call, add a call-scope message to your answer:

Keep the result for the whole call

{
  "data": { "order_id": "A4512", "status": "shipped", "arrives": "Friday", "tracking": "DHL 4471 2290" },
  "messages": [
    { "text": "Order A4512: shipped Tuesday with DHL, tracking DHL 4471 2290, arrives Friday.", "scope": "call" }
  ]
}

Say your own words

For a wait tool, an exact next_pause message in your answer is said word for word right after the holding line, in place of the AI's answer. Use it when the wording matters: a confirmation number, a legal sentence. Write it in the language of the call.

Your exact words

{
  "messages": [
    { "text": "Your return is booked. The number is R-2291, and a free label is in your inbox.",
      "when": "next_pause", "exact": true }
  ]
}

Safety and duplicates

⚠ A tool can occasionally be called twice for one request

If the visitor interrupts and says the same thing again, or a reply is withdrawn and written again, the AI can call the same tool twice, with a new call_id each time. Make every tool that changes something safe to repeat: key the action on your own id (the order number, the slot, the visitor's id) and, if it already happened, answer with the existing result instead of doing it again. The X-Selvia-Delivery header only identifies our own network retry of the same call.

⚠ Values are the visitor's words: check permissions on your side

The AI fills values from what the visitor said, and a visitor can say anything: another customer's order number, “I'm the manager”. Before you show or change anything, check it belongs to this visitor, using an id you control: the external_user_id you started the session with (sent with your key or a signed token), or the session_id. Never trust a name or number spoken in the call to decide who someone is.

⚠ The AI decides when to call

The AI may skip a tool when the visitor asks indirectly, or call it on a hint. Clear descriptions and required values cut both. For something that must happen on certain words every time, use a hook. For actions with consequences (cancelling, paying), describe that the AI must confirm with the visitor first, and check again on your server.

Slow jobs

A wait tool can take up to 15 seconds, but a visitor waiting in silence for more than a few seconds feels broken. For anything slow:

  • •Make it an async tool, and set on_resolve to next_pause so the avatar tells the visitor as soon as your result arrives (within 30 s); or
  • •Answer at once ({"data": {"status": "started"}}), do the work, and when it's done post a next_pause message to POST /v1/sessions/{session_id}/context using the session_id from the request. This has no time limit while the call runs.

Test, list, change, delete

POST/v1/agent/{agent_id}/tools/{name}/test

Calls your endpoint once from our server, signed like a live call, with "test": true and session_id: null in the body. Send {"values": {"order_id": "A4512"}}; required values you leave out are filled with samples. The answer shows your server's status, time and answer, and what a live call would skip or cut. Don't carry out real actions on a test call. At most 10 tests a minute per agent.

RouteDoes
GET /v1/agent/{agent_id}/toolsEvery tool of the agent (header values hidden), and whether it has a signing secret.
GET /v1/agent/{agent_id}/tools/{name}One tool.
PATCH /v1/agent/{agent_id}/tools/{name}Change any field but the name. Sending headers replaces them all; {} removes them. Changing type resets on_call, on_resolve and timeout_s unless you send them too.
DELETE /v1/agent/{agent_id}/tools/{name}?confirm=trueDelete it.
Tools belong to the agent: they are available in every conversation with it, whether it was started through the API, the website widget, a direct link or a QR code. Changes apply to calls that start afterwards. Up to 50 tools per agent (but read “Keep the list short”). Conversation sessions only.