Skip to main content
Different kinds of work suit different models and prompts. This example reads a user’s message and says which kind of work it needs, so your router can send it to the right place. Use it when a session starts, and again when a turn looks like a different job.

How it works

The context is JSON with one key, message, holding the user’s message. The keys are yours to choose. One single decision, session, asks what kind of work the request needs, with five outcomes: Its policy has abstain_below at 0.4. If no outcome reaches a probability of 0.4, the action is abstain.

Try it

Open this recipe in the playground to run it without an account. The message there asks to make a paragraph shorter and more confident. To run it from your code, set SQWISH_API_KEY as in the quickstart, then send this request:

Act on the answer

If the first message is too short to tell, policy.action is abstain: send it to your default route. Either way, pass the user’s original message on. The decision only picks where it goes.

Adapt it to your data

  • Your routes. Merge outcomes your router treats alike, or add one of your own with a description that says what it covers and where it ends.
  • System prompts. When the session has one, send it under its own key, such as system_prompt, next to message. It is often what marks a session as chat.
  • Many messages. Send one request per message, so one user’s request can’t change the answer for another’s.

What to watch

  • Requests that mix two kinds of work, such as code pasted in for a summary. A request that contains code isn’t always a coding job.
  • Long conversations. It was measured on opening messages, not on later turns.
  • Outcomes you add or merge. Check them on your own traffic before you route by them.

How well it works

Measured with kettei-core on 492 examples from a public dataset, it chose the right answer 88.8% of the time. Always picking the most common answer scores 55.7%. Your own data will differ, so measure it on examples of yours before you rely on it (improve a decision).
  • Dataset: No Robots (CC BY-NC 4.0).
  • Sample: 492 rows, 492 measured decisions.
  • Decisions measured: session.
  • Wording: tuned.
Always picking the most common answer has an accuracy of 0.5569, and guessing by how common each answer is has a log loss of 1.2393.These are past results on one dataset, not a promise of accuracy on yours.

Next steps