Function: buildPolicyAwareFallbackChain()
buildPolicyAwareFallbackChain(
tier,excludeProvider?):FallbackProviderEntry[]
Defined in: packages/agentos/src/api/generateText.ts:863
Build a policy-tier-aware fallback chain. Used by callers that pass
policyTier: 'mature' | 'private-adult' so refusals from the
primary model (typically gpt-4o, Claude, Gemini — all of which
moderate explicit content) re-route to an uncensored OpenRouter
model instead of hard-failing the request.
Chain order for mature / private-adult:
nousresearch/hermes-3-llama-3.1-405bon OpenRouter — leads the uncensored leaderboard for instruction-following + long- context comprehension. Same model the wilds-ai companion-pipeline uses for identity generation on mature+ companions; battle-tested on real workloads.anthropic/claude-sonnet-4on OpenRouter — Claude refuses hard NSFW but is markedly more permissive than gpt-4o for narrative analysis of explicit fiction (extracting characters from a CAI-export with mild adult content, etc.). Acts as the headroom band when Hermes 3 is rate-limited or down.- The standard buildFallbackChain suffix — keeps availability fallback on top of the policy fallback so a mature request that hits a Hermes 3 outage AND a Sonnet outage still has gpt-4o-mini etc. to fall back to (which will refuse on the explicit case but at least surfaces a moderation error rather than a network error).
For safe / standard tiers, this is identical to
buildFallbackChain — no uncensored prefix needed. Callers
that don't pass a tier should keep using the original builder.
Auto-built fallbacks always require their own env keys; missing keys silently drop the entry rather than throwing, so a partial deploy still produces a usable (shorter) chain.
Parameters
tier
Caller's intended content tier. Mature/private-adult triggers the uncensored prefix; safe/standard returns the availability-only chain.
"safe" | "standard" | "mature" | "private-adult" | undefined
excludeProvider?
string
Provider to omit (typically the primary that already failed). Mirrors buildFallbackChain.
Returns
Ordered fallback entries: uncensored prefix (when tier warrants it) + availability suffix.