# Build a custom action, step by step

> A complete worked example — a custom action that looks up a real order in your own system, tried before it's saved and used on a live call.

Source: https://docs.cleartalk.ai/docs/tools/building-a-tool

When none of the [ready-made tools](/docs/tools/ready-made-tools) reaches the system you need, a **custom action** connects your agent to your own software. We'll build the order-status lookup from [Ways to use tools](/docs/tools/examples): the caller gives an order number, the agent tells them where it is. Everything here transfers to any other action you want to build.

<Summary
  title="One form, tried before you save"
  items={[
  "Pick Look something up or Send something over.",
  "Name it and say when your agent should use it — that sentence decides when it fires.",
  "Paste the web address, and the connection key if your system needs one.",
  "List what the agent asks for first, run a test, tick what it learns from the reply.",
]}
/>

<Callout title="What you need before you start">
  Somewhere for the action to ask. That's a web address in your own software that returns order details, starting with https\://, plus the key it needs if it has one. If you're not sure whether you have one, that's the question to take to whoever maintains your systems — the rest of this page is the easy part.
</Callout>

## Pick a starting point

Open **Tools** in the sidebar and choose **Add a tool**. Under **Custom actions** there are two starting points:

* **Look something up** — "Check order status, insurance or stock in your own software." Your agent asks your software a question and uses the answer.
* **Send something over** — "Create a ticket, log a lead or book a job in your own software." Your agent sends what it learned.

They're the same form with different defaults. For an order lookup, pick **Look something up**.

## Name it and say when to use it

> **Name:** Order status lookup
>
> **When should your agent use it?** When the caller asks about an existing order — where it is, whether it shipped, or when it will arrive. Needs the caller's order number. Not for placing new orders or for cancellations.

That second field is not documentation — **it's how the AI decides whether to use this action**, so write it as guidance. Notice the shape: *when to use it*, *what it needs*, and *when not to use it*.

<DoDont
  goodTitle="Guidance the AI can act on"
  badTitle="Guidance that won't fire"
  good={[
  "“When the caller asks about an existing order — where it is, whether it shipped, or when it will arrive.”",
  "“Needs the caller's order number.”",
  "“Not for placing new orders or for cancellations.”",
]}
  bad={["“Order tool”", "“Checks orders in the system”", "“Order status API v2 wrapper”"]}
/>

That last line — when *not* to use it — matters more than people expect. It's what stops the agent reaching for this action during a conversation about something else.

## Where it sends the request

**Web address to call** is the address of your software's API — your developer or software provider gives you this, and it must start with https\://. You don't add the order number to it yourself; the details your agent collects are added to the request for you.

If your system needs a key, switch on **My system needs a connection key** and paste it into **Connection key**. It's stored encrypted, sent with every request, and you won't see it again after saving. Change the web address to a different site later and you'll be asked for the key again, so it never goes somewhere it wasn't meant for.

## What your agent asks for first

The details the action needs from the caller. For this one, exactly one: choose **Add a detail**, call it *Order number*, and set its kind to **Text**, **Number** or **Yes or no**. Tick **Must have** when the action can't run without it — the agent will ask for it in its own words if the caller hasn't said it yet.

On a lookup, each detail goes into the web address; on a send, into the body of the request.

Keep the list short. Every detail is something the agent has to extract or ask for, and each one is a chance to stall the conversation.

## Try it

The **Try it** panel beside the form sends a real test to your system with sample answers you type in. Choose **Run test** and you get a plain-English answer — *Your system answered in 1 second*, or what went wrong and what to check — with the request and the reply under **Show technical details**.

<Callout type="warn" title="Send something over sends for real">
  A test of a **Send something over** action asks first — &#x2A;*Send a real request?** — because whatever your system does with it, like creating a record, really happens.
</Callout>

## What your agent learns from the reply

Your system will return more than the conversation needs. After a test, the fields of the reply are listed under **What your agent learns from the reply** — tick the ones the agent should know:

| Tick                       | Because the agent needs to |
| -------------------------- | -------------------------- |
| the order's status         | say whether it shipped     |
| the estimated arrival date | say when it arrives        |
| the tracking link          | offer to text it           |

Now the agent can say them out loud — "It shipped Tuesday, arriving Thursday" — and a pathway can branch on them. Tick nothing and your agent gets the whole reply.

## Advanced

**Advanced** holds the method, headers, request body, reply paths and wait time. Most actions never need it. Choose **Write the request myself** to edit the web address and body directly, putting a detail where it belongs with `{{input.order_number}}`.

Two settings here matter more than they look:

* **What your agent says while it waits (optional).** Set something natural — "Let me pull that up for you." Without it, the caller hears silence while the request runs, and silence on a phone call reads as a dropped connection. Then choose **How your agent says it**:

  * **Let the agent say it (matches the caller's language)** — your line is a guide, and the agent says its own version of it in whatever language the caller is speaking, even if they switch mid-call. This is the default for new tools.
  * **Use these exact words** — the agent says your line word for word. A caller speaking Spanish still hears your English line, so pick this only when the wording itself matters.

  Tools made before this choice existed use exact words until you switch them.
* **Wait time (ms).** How long to wait for your system before giving up. Keep your system fast instead of raising this: every second is a second of silence on a live call.

Choose **Save tool** when you're done. Tools made with the earlier six-step builder still open in it when you edit them.

## Put it to work

**On an agent:** open the agent's **Tools** section, choose **Add a tool**, tick it in the **Add tools** popup and save the agent. Then mention it in the Agent Instructions, so the agent knows this is something it can do.

**In a Pathway:** add a **Custom Tool** step and choose it. Now branch on what came back — this is where a tool becomes genuinely powerful:

* the status is shipped → give the delivery date, offer to text the tracking link
* the status is delayed → apologise, offer a callback
* nothing found → check they have the right number, then transfer to a person

Always build that last path. Records go missing and systems go down; the agent needs somewhere to go that isn't silence.

## Test it before a customer does

Put the action in a pathway and write a test for each outcome — an order that exists, one that doesn't, one that's delayed. A simulated caller will find a vague detail or a missing branch in seconds. See [Testing your pathway](/docs/pathways/testing).

## When it doesn't fire

Nearly always one of three things, in this order of likelihood:

1. **"When should your agent use it?" is too vague.** The agent didn't recognise the situation. Make it more specific about *when* to use the action.
2. **Another tool overlaps.** Two tools with similar guidance confuse the choice — sharpen both, or merge them.
3. **A detail can't be filled.** The agent has no way to get what you asked for. Either the conversation needs to collect it earlier, or it shouldn't be a **Must have**.
