Skip to main content
A cheap bot can finish many conversations, but some need a person or a stronger model. This example checks the bot’s next reply and says whether to send it or hand the conversation on. Use it at the end of your cheap path, before you pay for the expensive one.

How it works

The context is JSON with the conversation so far and the reply the bot wants to send next, bot_next_reply. The keys are yours to choose. One decision, route, asks whether the bot can safely finish the conversation with that reply. It has two outcomes: handle means the reply resolves the issue, and escalate means a person or a stronger model should take over. A policy turns those into one of your two actions, keep or hand_off, using what each mistake costs: Keeping a conversation that should have gone up costs ten times as much as a needless hand-off. So policy.action is hand_off whenever the probability of escalate is above 1 in 11.

Try it

Open this recipe in the playground to run it without an account. The customer there was charged £1,200 instead of £120 and will dispute it with the bank today. The bot’s next reply says refunds take 5 to 7 working days. To run it from your code, set SQWISH_API_KEY as in the quickstart, then send this request:

Act on the answer

The outcomes are handle and escalate, but your code acts on policy.action, which is keep or hand_off:
policy.expected_costs shows what each action was expected to cost.

Adapt it to your data

  • Your costs. Set them from your own numbers: what a missed hand-off costs you, against the price of a person’s time or a bigger model’s call. Only how they compare matters: 10 and 1 act the same as 100 and 10 (weigh what mistakes cost).
  • Your conversations. Send your own conversation in the same shape, with the reply your bot is about to send.
  • Many conversations. Send one request per conversation.

What to watch

Track two numbers:
  • Missed hand-offs: conversations the bot kept that a person later had to take over. These cost you most. If there are too many, raise the cost of keep when the answer is escalate.
  • The hand-off rate: the share of conversations passed on. This is what you spend on people or the bigger model. If it is too high, lower the cost of keep when the answer is escalate, or raise the cost of hand_off when the answer is handle.

How well it works

This recipe hasn’t been measured on a public dataset. Its sample shows the format: measure it on your own examples before you rely on it.
To measure it, start with conversations a person took over: they show the hand-offs it should catch.

Next steps