|
| 1 | +# A3M Engineering Spec (Canonical) |
| 2 | + |
| 3 | +This is the canonical engineering behavior spec for A3M Router. |
| 4 | +Marketing and launch content are non-canonical; if there is a conflict, this file wins. |
| 5 | + |
| 6 | +## Core Routing Contract |
| 7 | + |
| 8 | +- Input: `routeQuery(prompt: string, available_models?: string[], budget_multiplier?: number)` |
| 9 | +- Output: |
| 10 | + - `primary_model` |
| 11 | + - `fallback_models` |
| 12 | + - `confidence` |
| 13 | + - `estimated_cost` |
| 14 | + - `estimated_latency_ms` |
| 15 | + - `features` (complexity + flags + domain) |
| 16 | + - `provider_type` |
| 17 | + |
| 18 | +## Reliability Components |
| 19 | + |
| 20 | +- Retry handling: |
| 21 | + - `ProviderRetryHandler` supports transient retries, backoff+jitter, and rate-limit handling. |
| 22 | +- Health management: |
| 23 | + - `ProviderHealthManager` maintains rolling health and circuit breaker states. |
| 24 | + - Circuit breaker opens after configured consecutive failures. |
| 25 | +- Fallback chain: |
| 26 | + - Health-sorted fallback ordering with unavailable providers pushed down. |
| 27 | + |
| 28 | +## Guardrails |
| 29 | + |
| 30 | +- Input and output checks implemented in `src/security/guardrails.ts`. |
| 31 | +- Includes prompt injection scoring, PII detection/redaction, and output validation hooks. |
| 32 | + |
| 33 | +## Cost/Budget |
| 34 | + |
| 35 | +- Budget enforcement and spend tracking: |
| 36 | + - `src/cost/budgetEnforcer.ts` |
| 37 | + - `src/cost/costTracker.ts` |
| 38 | + |
| 39 | +## Proxy Server |
| 40 | + |
| 41 | +- OpenAI-compatible endpoints implemented in `src/server/proxyServer.ts`. |
| 42 | +- Expected behavior: |
| 43 | + - Model resolution through mapper + router |
| 44 | + - Provider call with fallback behavior |
| 45 | + - Usage/cost logging for requests |
| 46 | + |
| 47 | +## Validation Gates (Required) |
| 48 | + |
| 49 | +- Node test suite: `npm test` |
| 50 | +- Python tests: `npm run test:py` |
| 51 | +- Routing eval: `npm run eval:routing` |
| 52 | +- Golden routing regression: `npm run eval:golden` |
| 53 | +- Fault injection reliability: `npm run eval:faults` |
| 54 | + |
| 55 | +All gates above must pass for release readiness. |
0 commit comments