Files
daveadmin 8a11001bff Add AWS Bedrock three-tier gateway routing (LiteLLM via Colin)
Routes AI tools across three tiers based on task complexity:
- Azure GPT-4o-mini always: redact, translate, timeline-basic, search-legal (mechanical tasks)
- Claude Haiku 4.5 (Bedrock): ask, summarize, timeline-deep, citations (Norwegian nuance)
- Claude Sonnet 4.6 (Bedrock): korrespond, legal-analysis, deep-research, barnevernet-analyze,
  discrepancy-find, advocate (public-facing legal output)

No AWS credentials in app — credentials live in LiteLLM on Colin (same as nova-lite).
Rollback: DBN_BEDROCK_ENABLED=false in .env, no code push needed.

Includes extended thinking support for Pro deep-research via chatWithThinking().
Claude Opus 4.7 constant added for future premium tier (needs litellm_config.yaml entry).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-25 15:22:48 +02:00

66 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/bootstrap.php';
require_once __DIR__ . '/AzureOpenAiGateway.php';
require_once __DIR__ . '/DbnBedrockGateway.php';
require_once __DIR__ . '/DbnBedrockModelRouter.php';
/**
* Single choke point for LLM gateway selection.
* When DBN_BEDROCK_ENABLED=false (default), always returns Azure — zero risk.
* When true, routes through LiteLLM on Colin (same path nova-lite already uses).
* AWS credentials live only in LiteLLM config — no keys needed in .env here.
* Rollback: flip DBN_BEDROCK_ENABLED=false in .env — no code push needed.
*/
final class DbnGatewayFactory
{
public static function bedrockEnabled(): bool
{
return dbnToolsEnv('DBN_BEDROCK_ENABLED', 'false') === 'true';
}
/**
* Returns a Bedrock gateway configured for the given LiteLLM model name,
* or the default from DBN_BEDROCK_CHAT_MODEL. Falls back to Azure when disabled.
*/
public static function make(?string $modelName = null): DbnAzureOpenAiGateway|DbnBedrockGateway
{
if (!self::bedrockEnabled()) {
return new DbnAzureOpenAiGateway();
}
return new DbnBedrockGateway([
'chat_model_name' => $modelName
?? (string)dbnToolsEnv('DBN_BEDROCK_CHAT_MODEL', DbnBedrockModelRouter::LITELLM_SONNET),
]);
}
/**
* Returns a gateway pre-configured with the best model for the given tool and tier.
*
* Three-tier routing:
* - Azure-pinned tools (redact, translate, timeline, search-legal) → always Azure, Bedrock flag ignored.
* - Haiku tools (ask, summarize, timeline-deep, citations) → Haiku when Bedrock on, Azure when off.
* - Sonnet tools (korrespond, legal-analysis, deep-research, etc.) → Sonnet when on, Azure when off.
*/
public static function makeForTool(
string $tool,
string $tier = 'free'
): DbnAzureOpenAiGateway|DbnBedrockGateway {
$route = DbnBedrockModelRouter::routeForTool($tool, $tier);
// Azure-pinned tools bypass the Bedrock flag entirely
if ($route['gateway'] === 'azure') {
return new DbnAzureOpenAiGateway();
}
// Bedrock tools fall back to Azure when disabled
if (!self::bedrockEnabled()) {
return new DbnAzureOpenAiGateway();
}
return self::make($route['model']);
}
}