Skip to content

feat(routing): add a TypeSafe-backed classifier router #723

Description

@pst2154

Summary

Explore and implement a TypeSafe System One routing option for Switchyard. TypeSafe would make a typed Choice over configured target labels, while Switchyard remains responsible for executing the selected target.

Motivation

The existing LLM-classifier path uses a generative model for the routing decision. A small live smoke comparison found that TypeSafe made the same 10/10 clear routing decisions with materially lower observed decision latency:

Router Correct Mean Median Observed p95
TypeSafe jev-latest 10/10 281 ms 278 ms 375 ms
azure/openai/gpt-5.6-sol 10/10 1,653 ms 1,575 ms 2,576 ms

This is exploratory evidence, not a production-quality accuracy result. The cases were deliberately separable and each request ran once.

Proposed behavior

  • Send normalized request state to TypeSafe as one typed Choice.
  • Define each configured target with a stable label and semantic criterion.
  • Route high-confidence choices to the selected target.
  • Route low-confidence choices and TypeSafe service failures to a configured capable fallback.
  • Load the TypeSafe credential from an environment variable; never place it in TOML or logs.
  • Preserve the full returned probability distribution for telemetry and later threshold calibration.

Architecture question

switchyard-libsy is intentionally I/O-free, while TypeSafe is an external HTTP judgment service. The implementation should preserve that boundary. Likely options are a generic external-decision step served by the runner, or a runner-owned classifier provider that returns a routing decision to libsy. Direct HTTP calls from a libsy algorithm would violate the current architecture.

Acceptance criteria

  • Agree on the I/O boundary and configuration shape.
  • Add a TypeSafe-backed routing implementation with environment-based authentication.
  • Validate target labels, fallback target, and confidence threshold.
  • Fail open to the configured capable target on low confidence or service failure.
  • Add mocked contract, configuration, fallback, and server integration tests.
  • Record decision latency, selected label, confidence, and failure/fallback reason without logging secrets.
  • Evaluate on representative labeled Switchyard traffic before making production quality claims.
  • Document setup and operational behavior.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions