Blog

Routing is a database decision, not a prompt trick

How Chatwork Router picks one of six agents for every message, why the first layer is boring on purpose, and what gets logged.

9 November 2026 · Chatwork team

The easy way to build a “multi-agent” support bot is one long prompt: “You are Concierge, Support, Sales and Billing; decide which hat to wear.” It works in demos. In production you cannot tell why a billing question got a sales pitch, you cannot turn one hat off for one customer, and the behaviour changes every time the model is updated.

Chatwork Router is our answer, and it is deliberately unglamorous.

Layer one is a scoring function you can read

Every agent file lists keywords with weights, in Arabic and English, plus a small boost per channel. Text is normalised (diacritics and tatweel stripped, letter variants folded), Arabic keywords match as substrings because of how prefixes work, Latin ones on word boundaries so “pay” never matches “payload”. The score is the capped sum of matched weights. The best agent above its threshold wins; otherwise Concierge does.

That is the whole first layer. It runs in about a millisecond, it runs without a database, and it runs identically in your browser: the playground on /agents ships the same algorithm in TypeScript, and a shared fixture file keeps the two implementations honest.

Layer two is pgvector, not a bigger prompt

With PostgreSQL, each agent’s intent sentences (“Where is my order?”, “وين طلبي؟”) are embedded once. A message is embedded once too, and the same vector serves two queries: the best cosine similarity per agent, and the top knowledge chunks for the agent that wins. Final score: 0.55 semantic + 0.45 lexical. If the embeddings provider is down, the first layer carries on and the decision records that it did.

Guard-rails are data

Guardian, the escalation agent, has always_handoff: true. When it wins, the conversation goes to a human even if the model forgot the tag. A tenant can disable Sales for a quarter, or pin Support for a launch, with one API call and no redeploy. The default agent cannot be disabled; there is always someone at the door.

Everything is logged, nothing is kept that should not be

Each decision writes the agent, the reason, the score, the layers used, the top candidates with their matched keywords and the latency. It does not write the message; it writes its hash. That is enough to answer “why did this go to Billing?” and to notice that a keyword is too greedy, without turning the routing log into a second copy of your customers’ conversations.

Why “mandatory”

Every AI reply goes through Chatwork Router. There is no path where a model free-wheels across roles. What is optional is the infrastructure: without a database you get the first layer on the bundled registry, and the trace says so. The product never guesses silently about which agent is speaking.