Storefront has been decoupled into micro-frontends with a dedicated commerce app and shared shell.

Read the architecture guide →

ADR-007: Use Microsoft Decision-1 for Chat routing, safety gating, and tool selection

Replaces the generative router agent with a provider-agnostic IDecisionClient backed by Microsoft-Decision-1 for single-pass routing, safety gating, and per-turn tool selection.

November 20, 2026AcceptedArchitecture

1. Context & Problem

Previously, Chat SystemSystemv1.0.0Chat SystemInternal system that hosts BookWorm's conversational workflow and specialist AI agents for customer support and catalog-...Ownerai-capabilities-teamDiagramRepositoryOpen docs relied on a general-purpose generative language model to classify incoming customer messages and route them to Book AgentAgentv1.0.0Book AgentPrimary conversational book discovery and recommendation specialist that grounds catalog answers in read-only MCP lookup...PublishesAnalyzeText, AnonymizeTextOwnerai-capabilities-teamDiagramRepositoryOpen docs, QA AgentAgentv1.0.0QA AgentRead-only customer support and store-policy specialist that answers operational, shipping, returns, account, and billing...PublishesAnalyzeText, AnonymizeTextOwnerai-capabilities-teamDiagramRepositoryOpen docs, or Rating AgentAgentv1.0.0Rating AgentRead-only review intelligence specialist that summarizes customer feedback over A2A gRPC and map-reduce workflows while ...PublishesAnalyzeText, AnonymizeTextOwnercatalog-experience-teamDiagramRepositoryOpen docs, while each specialist agent received its entire list of allowed tools on every conversational turn.

Using a generative conversational model for classification and routing introduces unnecessary latency, higher prompt-token overhead, and fragile output-parsing behavior. It also mixes safety and scope checks with conversational generation, and forces specialist models to process irrelevant tool definitions on turns that only need a subset of capabilities.

2. Business Value

  • Faster responses and lower AI cost: Request screening and routing run in a single fast decision pass instead of a generative model turn, and specialist agents only receive tools relevant to the current turn.
  • Consistent pre-agent guardrails: Safety, language, and bookstore-scope checks are evaluated together before any specialist agent runs, producing predictable boundary responses for invalid requests.
  • Resilient availability: If dynamic tool filtering encounters a temporary outage, the agent safely falls back to its allowed tool list so customer conversations are not blocked.
  • Vendor flexibility: A shared internal decision abstraction keeps chat business logic independent of any specific AI provider’s wire format.

3. How It Works

Single-pass screening and routing

Before any specialist agent is invoked, a dedicated decision model evaluates every incoming customer request across four criteria in a single pass:

  1. Safety check: Confirms the message does not contain prompt-injection, jailbreak, or instruction-override attempts.
  2. Language check: Confirms the message is written in English.
  3. Domain scope check: Confirms the request relates to the BookWorm bookstore domain.
  4. Specialist selection: Chooses between the book specialist (Book AgentAgentv1.0.0Book AgentPrimary conversational book discovery and recommendation specialist that grounds catalog answers in read-only MCP lookup...PublishesAnalyzeText, AnonymizeTextOwnerai-capabilities-teamDiagramRepositoryOpen docs), general Q&A (QA AgentAgentv1.0.0QA AgentRead-only customer support and store-policy specialist that answers operational, shipping, returns, account, and billing...PublishesAnalyzeText, AnonymizeTextOwnerai-capabilities-teamDiagramRepositoryOpen docs), or the ratings specialist (Rating AgentAgentv1.0.0Rating AgentRead-only review intelligence specialist that summarizes customer feedback over A2A gRPC and map-reduce workflows while ...PublishesAnalyzeText, AnonymizeTextOwnercatalog-experience-teamDiagramRepositoryOpen docs, selected only when a specific book identifier is already present).

If any of the safety, language, or scope checks falls below the 50% confidence threshold, the request is stopped immediately with a clear, deterministic boundary message. If all guardrails pass but the selected specialist’s routing confidence falls below 60%, the workflow pauses for human-in-the-loop (HITL) disambiguation so the customer can confirm which specialist should handle the request before resuming. If the decision call returns only a partial answer, any completed guardrail checks are still enforced, and an unanswered route safely defaults to the book specialist.

Dynamic per-turn tool selection

For the book and Q&A specialists, a pre-turn filter reviews the recent conversation window (up to the last six messages by default) and scores each permitted tool for relevance to the current turn. Only tools meeting the confidence threshold—plus any tools marked as always included or required—are passed to the downstream chat model. If no tools are configured, tool use is disabled, or the decision check fails, the filter either skips evaluation or falls back safely by retaining all permitted tools.

4. Trade-offs & Lessons Learned

  • Per-turn filtering cost vs. leaner prompts: Dynamic tool selection adds one decision call per agent turn when tools are present, trading a small evaluation step for smaller, cleaner prompts sent to the conversational model. Fail-open behavior preserves availability during transient decision-service issues.
  • Deployment and contract obligations: The chat service requires the decision model to be deployed and available. Question prompts, candidate descriptions, and the 0.5 probability threshold form part of the system’s behavioral contract and must be covered by automated tests.
  • Alternatives considered:
    • Keep a generative router model: Keeps all orchestration on one model family, but incurs higher latency and token cost and relies on prompt-engineered structured output parsing.
    • Always pass all allow-listed tools on every turn: Simpler to operate, but forces the generative model to process every tool schema even on purely informational turns.
    • Call the vendor decision endpoint directly from Chat: Avoids creating a shared decision abstraction, but couples chat code to vendor-specific wire formats, duplicates telemetry, and prevents reuse across other services.

5. Technical Reference

1. Decision abstractions and Foundry System 1 client (BookWorm.Chassis.AI.Decisions)

  • Core abstractions: IDecisionClient, DecisionRequest, DecisionResponse, DecisionOptions, and DecisionQuestion (BinaryDecisionQuestion, ChoiceDecisionQuestion, ScoreDecisionQuestion).
  • Typed binding & serialization: DecisionDefinition<T>, DecisionClientTypedExtensions, and source-generated JSON deserialization via DecisionSerializationContext.
  • Provider implementation: FoundrySystemOneDecisionClient and SystemOneProtocolMapper over AIProjectClient.Pipeline targeting Microsoft Foundry’s Microsoft-Decision-1 System 1 endpoint (/providers/microsoft/v1/systemone), evaluating Binary (noul), Choice, and Score questions with calibrated probabilities in a single pass.
  • Observability: OpenTelemetry tracing via BookWorm.Chassis.AI.Decisions / decision.systemone.

2. Single-pass routing and safety gating (ChatRoutingDecisionService & DecisionRouterExecutor)

  • Retired components: Legacy generative router-agent (RouterAgentRegistration and router-agent.yaml) removed.
  • Evaluated questions (RoutingDefinition / ChatRoutingResult):
    • is_safe (BinaryProbability): prompt-injection, jailbreak, or instruction-override check.
    • is_english (BinaryProbability): English language check.
    • is_in_scope (BinaryProbability): BookWorm bookstore domain scope check.
    • route (Choice): selects book-agent, qa-agent, or rating-agent (only when a specific book catalog ID is already present).
  • Threshold, HITL disambiguation & error handling: Rejects requests below ProbabilityThreshold (0.5) for is_safe, is_english, or is_in_scope with deterministic boundary messages (UnsafeInput, NonEnglish, OutOfScope). When an in-scope request’s route confidence is below RouteConfidenceThreshold (0.6), RoutingDecision.NeedsDisambiguation routes to RouteDisambiguationPrepExecutor and pauses at RequestPort (RouteDisambiguationPort, emitting disambiguateRoute via IExternalRequestEnvelope). Storefront renders the selector via useRouteDisambiguation, AGUIWorkflowAgent normalizes plain-text replies to FunctionResultContent, and RouteDisambiguationResolutionExecutor resumes routing to the chosen specialist. Handles DecisionUnansweredException via HandlePartialResponse, enforcing answered guardrail checks and defaulting safely to Book when route is unanswered.

3. Dynamic per-turn tool selection (DecisionToolSelectionMiddleware)

  • Registration: .UseDecisionToolSelection(sp) on Book AgentAgentv1.0.0Book AgentPrimary conversational book discovery and recommendation specialist that grounds catalog answers in read-only MCP lookup...PublishesAnalyzeText, AnonymizeTextOwnerai-capabilities-teamDiagramRepositoryOpen docs and QA AgentAgentv1.0.0QA AgentRead-only customer support and store-policy specialist that answers operational, shipping, returns, account, and billing...PublishesAnalyzeText, AnonymizeTextOwnerai-capabilities-teamDiagramRepositoryOpen docs chat-client pipelines.
  • Filtering behavior: Evaluates candidate AITool definitions as BinaryDecisionQuestions against the recent conversation window (MaxContextMessages, default 6) and retains tools meeting ProbabilityThreshold (0.5).
  • Safety & bypass rules: Always preserves AlwaysIncludedToolNames and RequiredChatToolMode tools; skips evaluation when Tools is empty or ToolMode is NoneChatToolMode; fails open (retains all tools) if the decision call fails or returns no selection.
  • Operational & test obligations: Requires a Microsoft-Decision-1 deployment in Foundry; covered by DecisionRouterExecutorTests and WorkflowRegistrationTests.