---
title: Route customer requests
summary: How the Chat workflow validates requests and chooses a BookWorm specialist.
version: 1.0.0
type: guides
order: 1
badges:
  - content: Guide
    backgroundColor: teal
    textColor: teal
---

**Audience & Outcome:** This guide is for AI engineers and backend developers working on [[service|chat-api]]. You will learn how incoming conversational messages are validated, classified, disambiguated, and routed across BookWorm's specialist agents.

[[service|chat-api]] routes every interactive message through a deterministic three-layer workflow rather than an open-ended LLM router. The pipeline validates and truncates input first, evaluates safety, language, scope, and specialist intent with `Microsoft-Decision-1`, pauses for human-in-the-loop (HITL) disambiguation when confidence is low, and coordinates bounded handoffs across [[agent|book-agent]], [[agent|qa-agent]], and [[agent|rating-agent]].

## Context and motivation

Customer chat messages span distinct domains—book discovery, store policies, and review analysis—alongside empty, non-English, off-topic, or prompt-injection inputs. Sending unscreened messages straight to a general LLM router wastes inference budget, increases latency, and makes routing behavior nondeterministic.

By separating deterministic input hygiene, calibrated classification, explicit low-confidence confirmation, and scoped specialist sub-workflows, BookWorm rejects invalid traffic early and keeps routing observable and testable.

## How it works

The visual below traces a customer message through input validation, `Microsoft-Decision-1` routing, HITL disambiguation, specialist handoffs, and final response formatting.

<MermaidFileLoader file="mermaids/01-route-customer-requests-diagram-1.mmd" />

### Three-layer routing pipeline

<Steps>
<Step title="Layer 1: Input validation and resume normalization">

**Disambiguation resume normalization:** If an unanswered disambiguation prompt exists and the user replies in plain text (`1`/`book`, `2`/`qa`/`support`/`policy`, `3`/`rating`/`review`), the workflow normalizes the reply into a structured tool result so both rich UI clients and plain-text clients resume cleanly.

**Deterministic hygiene & safety:** Tool-result resume turns bypass text validation. For user text turns, the pipeline trims whitespace, rejects empty prompts, screens for prompt-injection and XSS markers, and applies governance prompt-safety policies. Accepted prompts longer than `2,000` characters are truncated to `1,900` characters.

</Step>
<Step title="Layer 2: Classification and HITL disambiguation">

The decision router evaluates four structured questions in order via `Microsoft-Decision-1`:

| Decision check                       | Threshold / rule       | Outcome when triggered                                      |
| :----------------------------------- | :--------------------- | :---------------------------------------------------------- |
| **`is_safe`**                        | `P(is_safe) < 0.5`     | Short-circuits with an unsafe-input rejection               |
| **`is_english`**                     | `P(is_english) < 0.5`  | Short-circuits with an English-only notice                  |
| **`is_in_scope`**                    | `P(is_in_scope) < 0.5` | Short-circuits with an out-of-scope bookstore notice        |
| **`route` (`Book`, `QA`, `Rating`)** | Confidence `< 0.6`     | Pauses for user disambiguation between Book, QA, and Rating |
| **`route` (`Book`, `QA`, `Rating`)** | Confidence `>= 0.6`    | Forwards directly to the selected specialist                |

:::note
If `Microsoft-Decision-1` returns a partial response, omitted binary guardrails default to `1.0` and an unanswered route choice defaults to [[agent|book-agent]] so transient partial responses degrade predictably.
:::

</Step>
<Step title="Layer 3: Response formatting">

If the assistant turn carries a pending client-side UI tool call with empty text, the formatter preserves the tool call without overwriting it. Otherwise, it strips any leaked system markers, collapses excessive blank lines, ensures terminal punctuation, and falls back to a safe rephrase message if no usable text remains.

</Step>
</Steps>

### Specialist selection and handoffs

| Customer intent                                                                      | Initial specialist      | Follow-up handoff behavior                                                                                                    |
| :----------------------------------------------------------------------------------- | :---------------------- | :---------------------------------------------------------------------------------------------------------------------------- |
| Book search, recommendations, catalog details, or review questions without a book ID | [[agent\|book-agent]]   | Hands off to [[agent\|rating-agent]] once a single book ID is resolved, or to [[agent\|qa-agent]] for store-policy follow-ups |
| Store policies, shipping, returns, refunds, accounts, orders, or billing             | [[agent\|qa-agent]]     | Hands off book-specific portions of mixed requests to [[agent\|book-agent]]; never claims live account or order lookup        |
| Review summaries or rating analysis when a book catalog ID is already present        | [[agent\|rating-agent]] | Calls [[service\|rating-api]] over A2A gRPC; terminal specialist (cannot search the catalog or hand back)                     |

<AccordionGroup>
<Accordion title="Design trade-offs and alternatives considered">

| Decision                                                      | Benefits                                                                                 | Costs and limits                                                            |
| :------------------------------------------------------------ | :--------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------- |
| **Use `Microsoft-Decision-1` instead of an LLM router agent** | Produces calibrated probabilities at lower latency and cost than full chat completions   | Requires maintaining explicit binary/choice questions and thresholds        |
| **Separate Layer 1 validation from Layer 2 semantic routing** | Blocks empty messages, injections, and oversized payloads before any model call          | Truncating prompts over `2,000` characters can clip a trailing book UUID    |
| **Pause for disambiguation when route confidence `< 0.6`**    | Prevents misrouting ambiguous requests to the wrong specialist                           | Adds one interactive turn before answering ambiguous prompts                |
| **Keep [[agent\|rating-agent]] terminal and ID-gated**        | Avoids duplicating [[service\|mcp-server]] catalog search inside [[service\|rating-api]] | Title-only review requests always route through [[agent\|book-agent]] first |

**Rejected alternatives:**

- **Single LLM supervisor agent:** Lacks calibrated probability distributions for a deterministic `< 0.6` HITL threshold and increases per-turn latency.
- **Per-specialist rejection:** Duplicating safety, language, and scope prompts across three specialists increases drift and wastes tool invocations.

</Accordion>
</AccordionGroup>

## Related documentation

- [[flow|agent-orchestration]] — End-to-end orchestration flow for [[service|chat-api]].
- [[adr|adr-007-system-one-decision-model-routing-and-tool-selection]] — Decision record for `Microsoft-Decision-1` routing.
- [[adr|adr-001-chat-agent-orchestration-boundary]] — Orchestration boundary within [[system|chat-system]].
