Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Agent Router

Give JEV a prompt and a set of AI models. See where it routes the request.

A local developer playground for exploring TypeSafe AI's JEV decision model. Change the routing objective, inspect real Choice distributions, and run a small prompt dataset to explore selection patterns.

This is a routing experiment. It does not execute or evaluate downstream models. The only external AI service called is TypeSafe.

JEV routing playground, awaiting its first request

Run locally

Use Node.js 22.13+ (recommended) and npm. After cloning this repository:

npm install
cp .env.example .env.local
# Set TYPESAFE_API_KEY in .env.local
npm run dev

Open 127.0.0.1:3000. Create your TypeSafe credential using the official quickstart. Never commit .env.local or put the credential in a NEXT_PUBLIC_ variable.

Variable Required Purpose
TYPESAFE_API_KEY Yes, for routing Server-side TypeSafe credential
TYPESAFE_DEFAULT_MODEL No Official JEV model ID; defaults to jev-latest

No OpenAI, Anthropic, Google, xAI, DeepSeek, or Mistral credentials are needed. Without a TypeSafe key you can explore the interface and dataset; routing returns an explicit setup error. It never returns demo decisions.

The dev and production scripts bind to loopback. This is intentionally a local, unauthenticated tool. A public deployment needs its own access and usage controls before exposing a server-funded routing endpoint.

Architecture

Browser: prompt + strategy + candidate IDs
                    │
                    ▼
Next.js POST /api/route
  bounded input → validation → server-only JEV adapter
                    │
                    ▼
TypeSafe systemOne / jev-latest
  shared state + 3 independent Choice questions
                    │
                    ▼
Validated answers → playground / experiment charts

Next.js App Router, strict TypeScript, Tailwind CSS, Lucide icons, and Recharts. No database, accounts, queue, provider SDKs, or persistent prompt storage. Native controls keep the interface small and keyboard-accessible.

How JEV is used

The official TypeSafe skill is installed in .agents/skills/typesafe-ai. Its live documentation and the official @typesafe-ai/sdk 0.6.0 source were checked before implementation.

lib/jev/request.ts builds one systemOne request containing:

  • State: prompt, candidate catalog snapshot, pricing, speed caveats, and assumptions.
  • Model Choice: explicit candidate IDs, descriptions, and the selected routing objective.
  • Task Choice: Coding, Reasoning, Research, Writing, Math, Summarization, Classification, Multilingual, or General.
  • Complexity Choice: Low, Medium, or High with concrete definitions.

All questions see the same state and run independently. Task classification does not secretly select a model. The app never generates explanations on JEV's behalf.

The server pins the API origin to https://api.typesafe.ai, keeps credentials server-side with server-only, disables request-body logging, and validates returned option coverage, numeric bounds, distribution sum (with rounding tolerance), and selected maximum. Invalid responses become errors, never partial invented results.

There is one retry with SDK backoff, a 15-second per-attempt timeout, and a 35-second total cancellation budget. Missing credentials, invalid input, authentication errors, rate limits, overload, connection failures, malformed responses, and timeout states have explicit messages. Raw upstream error bodies and credentials are not returned to the browser.

Probability versus confidence

Choice returns the selected option and a probability for each candidate. Selection probability is the returned probability for the selected candidate. Confidence is TypeSafe's separate statistic derived from the concentration of that distribution. Neither establishes actual downstream answer quality. The UI rounds display values only; exports retain the returned numbers.

Routing objectives

Objective Instructions
Quality Prioritize task suitability and capability.
Balanced Balance suitability, supplied prices, and documented speed positioning.
Cost Favor lower supplied input/output prices while retaining task suitability.
Speed Favor documented low-latency positioning; do not invent missing latency evidence.

There is no hardcoded task-to-model mapping. JEV must choose from the selected candidates (at least two). This is a forced-choice experiment: there is no abstention option, even if no candidate is ideal.

Catalog and evidence

The 16 candidates and provider-source links are centralized in lib/models/catalog.ts, with snapshot version 2026-09-21.r2:

Provider Text-routing candidates
OpenAI GPT-6 Astra; GPT-5.6 Sol, Terra, Luna
Anthropic Claude Fable 5.1, Opus 5, Sonnet 5, Haiku 4.5
Google Gemini 3.8 Flash, 3.5 Flash-Lite, 3.1 Pro (Preview)
xAI Grok 4.6
DeepSeek V4.1 Flash, V4 Pro (0813)
Mistral Medium 3.5, Small 4

These were checked against official provider catalogs. Current economical tiers such as Haiku 4.5 and Small 4 remain useful candidates even though their version numbers are lower. Pro Preview is explicitly labeled. The catalog covers mainstream text workloads; image/audio-only models, duplicate aliases, and legacy generations are excluded. Descriptions are concise provider-documented characteristics, not independent evaluations. Provider frequencies aggregate multiple candidates; unequal candidate counts can influence those frequencies.

Prices are USD per million standard text input/output tokens. Cache discounts, batches, tools, regional uplifts, and long-context surcharges are excluded unless noted. DeepSeek uses peak cache-miss prices for a consistent snapshot. Gemini pricing is linked to Google's pricing table. Every entry has its own source and pricing note, also visible on the methodology page.

Speed metadata remains qualitative: Anthropic documents relative latency within the Claude lineup, and xAI describes Grok 4.6 as its fastest Grok model. Neither claim establishes a cross-provider ordering. Other candidates have unknown comparable latency; unknown does not mean slow. This makes the Speed objective an experiment with incomplete qualitative evidence, not a measured latency optimizer. Gemini 3.8 Flash pricing uses the published rates through December 2026, with the announced 2027 increase recorded in its pricing note. Update descriptions, prices, and evidence together when revising the catalog version.

Routing lab methodology

  • 27 hand-authored prompts, three in each of nine categories, live in data/prompts/index.ts.
  • Select categories, objectives, and candidates. One prompt × objective pair makes one JEV request, with three judgments that use tokens.
  • The browser runs requests sequentially through the same server route. Stop cancels the in-flight request and prevents new ones; a request already received by TypeSafe may still incur usage.
  • Individual failures are recorded and the run continues. Credential, authentication, rate-limit, and overload failures stop the run with completed results preserved.
  • Model/provider frequencies count selections. Category charts show shares of successful selections by editorial dataset category, not JEV's independently inferred task category.
  • Objective tabs filter the current run. Average selection probability and latency exclude failures. Latency measures the server's JEV call including retries, not browser round-trip time or downstream inference.
  • Export JSON before navigating away or rerunning. Exports include run configuration, catalog entries, prompt text, failures, returned JEV version, full distributions, token usage, and timestamps. State stays in page memory; refresh, navigation, or a new run clears it.

There are no expected “correct” routing labels. Repeated runs, counterbalanced choice ordering, broader datasets, and controlled catalog revisions would be needed for stronger conclusions about routing stability. Prompt wording, candidate order, metadata, and moving JEV aliases are potential confounders. Pin TYPESAFE_DEFAULT_MODEL to an official version for reproducibility.

Verification

Local validation completed: production build, TypeScript, lint, formatting, eight API/contract tests, and browser checks at four viewport widths. Live JEV verification is pending a TypeSafe credential. No live routing results are included or claimed.

npm run typecheck
npm run lint
npm test
npm run build
npm run test:live  # makes one real, billable TypeSafe request

The live test loads .env.local, runs the same server adapter, validates all three Choice answers, and prints the actual response. No credential is printed. Without a key it exits unsuccessfully with setup guidance.

Unit tests cover invalid requests, exact candidate subsets, Choice validation, and aggregation that excludes failures. Synthetic numbers occur only inside unit-test fixtures; they are never available as application results or fallbacks.

With the dev server running and Google Chrome installed, npm run test:browser checks navigation, prompt controls, missing-key behavior when applicable, lab interruption, and responsive overflow at 390, 768, 1024, and 1440 pixels. It captures the README screenshot and writes additional captures to ignored test-results/. This check does not submit live requests when a credential is configured.

Development and production builds use Next.js's supported webpack compiler for compatibility with environments that restrict Turbopack worker ports.

npm run format
npm run format:check
npm run start # after npm run build

Project structure

app/
  page.tsx                 Playground
  experiments/page.tsx     Routing lab
  about/page.tsx           Methodology and catalog evidence
  api/route/route.ts        Validated server endpoint
components/                Console UI, decisions, experiment charts
lib/
  jev/                     Official SDK adapter and question construction
  models/catalog.ts        Candidates, evidence, prices, catalog version
  routing/                 Strategies, contracts, client request, aggregation
data/prompts/              Curated workload dataset
scripts/smoke.ts            Live integration verification
tests/                     Isolated contract and aggregation tests
.agents/skills/typesafe-ai/ Official TypeSafe skill

Official references

Built to explore routing decisions, not to crown a model benchmark winner.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages