Documentation

Integrate a bounded routing policy.

The downloadable TypeScript example uses the same catalog, pinned model, response validation, and threshold comparison as the public report.

Scope

The router classifies one clear English task into code search, test execution, documentation lookup, code review, or none. It returns a suggestion or handoff and never executes the selected capability.

Current status

The direct-provider adapter, fail-closed live endpoint, and protected manual probe workflow are implemented. The probe is not described as passed until it runs with repository secrets, and live evaluation stays disabled until shared limits and verified cost bounds are configured. The generic TypeScript export is available now; report-linked exports appear only for immutable, approved benchmark versions.

Download the generic TypeScript example

Quickstart: 3-Step Integration

The exported router is fully self-contained with a locked package.json and zero external runtime requirements beyond Node.js and TypeScript:

  1. Download and extract: Extract the downloaded zip archive into your agent project (e.g. src/router/).
  2. Configure credentials: Provide your own TypeSafe Direct API key in your environment:
    export TYPESAFE_API_KEY="ts_..."
  3. Run with verified policy: Call routeTask with your chosen confidence threshold.

Production Usage Example

The router exports a typed function that pins model jev-1.13.0 and guarantees that suggestions meet your exact confidence threshold:

import { routeTask } from "./router";

async function dispatchAgentWork(taskPrompt: string) {
  // Evaluates prompt against the 5 bounded categories with confidence check
  const outcome = await routeTask(taskPrompt, { threshold: 0.80 });

  if (outcome.status === "route") {
    console.log(`Adopted suggestion: ${outcome.choice} (confidence: ${outcome.confidence})`);
    
    switch (outcome.choice) {
      case "code_search":
        // Invoke your symbol search tool
        break;
      case "test_runner":
        // Invoke your test runner
        break;
      case "docs_lookup":
        // Query framework documentation
        break;
      case "code_review":
        // Run code review lint / analysis
        break;
      case "none":
        console.log("Task is explicitly out of router capabilities.");
        break;
    }
  } else {
    // Handoff branch: model confidence was below 0.80 or task was ambiguous
    console.warn(`Safely handed off: ${outcome.reason}`);
    // Escalate to human operator or full System Two reasoning model
  }
}

Handoff and Failure Reason Codes

The router fails closed. When an automated routing suggestion cannot be safely adopted, it returns a structured handoff with a deterministic reason code:

  • CONFIDENCE_BELOW_THRESHOLD: The model predicted a label, but its confidence fell below your operating threshold.
  • AMBIGUOUS_OR_MULTI_INTENT: The request combines multiple distinct tasks (e.g., "run tests and rewrite handler") and requires interactive clarification.
  • UPSTREAM_TIMEOUT: The upstream provider exceeded the 15-second maximum total deadline.
  • UPSTREAM_RATE_LIMIT: Provider returned HTTP 429/529; retried once with exponential backoff before safely handing off.
  • INVALID_UPSTREAM_RESPONSE: The response failed schema validation or probabilities did not sum to 1.0; failed closed without guessing.

Execution Boundaries and Safeguards

The router adheres to strict production security invariants:

  • Input Limit: Each task input is bounded to 4,000 Unicode characters.
  • No Tool Execution: The router returns classification decisions only and is incapable of executing external tools or modifying files.
  • Zero Key Leakage: Your TypeSafe provider key stays strictly on your runtime server and is never passed to browser storage, logs, or share links.

Feedback and failures

A route suggestion is data only and never executes a tool. If the example returns a handoff, inspect its stable reason code before deciding whether to retry. Send reproducible documentation or product feedback to [email protected]; never attach a provider key or private task text.