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.
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:
- Safety check: Confirms the message does not contain prompt-injection, jailbreak, or instruction-override attempts.
- Language check: Confirms the message is written in English.
- Domain scope check: Confirms the request relates to the BookWorm bookstore domain.
- 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, andDecisionQuestion(BinaryDecisionQuestion,ChoiceDecisionQuestion,ScoreDecisionQuestion). - Typed binding & serialization:
DecisionDefinition<T>,DecisionClientTypedExtensions, and source-generated JSON deserialization viaDecisionSerializationContext. - Provider implementation:
FoundrySystemOneDecisionClientandSystemOneProtocolMapperoverAIProjectClient.Pipelinetargeting Microsoft Foundry’sMicrosoft-Decision-1System 1 endpoint (/providers/microsoft/v1/systemone), evaluatingBinary(noul),Choice, andScorequestions 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(RouterAgentRegistrationandrouter-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): selectsbook-agent,qa-agent, orrating-agent(only when a specific book catalog ID is already present).
- Threshold, HITL disambiguation & error handling: Rejects requests below
ProbabilityThreshold(0.5) foris_safe,is_english, oris_in_scopewith deterministic boundary messages (UnsafeInput,NonEnglish,OutOfScope). When an in-scope request’srouteconfidence is belowRouteConfidenceThreshold(0.6),RoutingDecision.NeedsDisambiguationroutes toRouteDisambiguationPrepExecutorand pauses atRequestPort(RouteDisambiguationPort, emittingdisambiguateRouteviaIExternalRequestEnvelope). Storefront renders the selector viauseRouteDisambiguation,AGUIWorkflowAgentnormalizes plain-text replies toFunctionResultContent, andRouteDisambiguationResolutionExecutorresumes routing to the chosen specialist. HandlesDecisionUnansweredExceptionviaHandlePartialResponse, enforcing answered guardrail checks and defaulting safely toBookwhenrouteis 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
AITooldefinitions asBinaryDecisionQuestions against the recent conversation window (MaxContextMessages, default6) and retains tools meetingProbabilityThreshold(0.5). - Safety & bypass rules: Always preserves
AlwaysIncludedToolNamesandRequiredChatToolModetools; skips evaluation whenToolsis empty orToolModeisNoneChatToolMode; fails open (retains all tools) if the decision call fails or returns no selection. - Operational & test obligations: Requires a
Microsoft-Decision-1deployment in Foundry; covered byDecisionRouterExecutorTestsandWorkflowRegistrationTests.