Skip to content

Comments

feat: add Astrai intelligent router to summarization fallback chain#115

Open
beee003 wants to merge 1 commit intokoala73:mainfrom
beee003:feat/astrai-router-provider
Open

feat: add Astrai intelligent router to summarization fallback chain#115
beee003 wants to merge 1 commit intokoala73:mainfrom
beee003:feat/astrai-router-provider

Conversation

@beee003
Copy link

@beee003 beee003 commented Feb 19, 2026

Summary

  • Adds Astrai as a new LLM provider in the summarization fallback chain
  • New chain: Groq → Astrai → OpenRouter → Browser T5 (was Groq → OpenRouter → Browser T5)
  • Astrai is an AI inference router that auto-selects the optimal model/provider per request based on cost, latency, and task complexity
  • Uses strategy: "cheapest" since summarization is lightweight — routes to the most cost-effective model that meets quality requirements
  • Uses model: "auto" so Astrai picks the best model for each request (e.g., Groq Llama for simple summaries, Claude for complex analysis)

Why this fits WorldMonitor

WorldMonitor already has a smart fallback chain (Groq → OpenRouter → Browser T5). Astrai slots in naturally as a second cloud fallback that routes across all providers (OpenAI, Anthropic, Groq, DeepInfra, etc.) from a single API key. When Groq is rate-limited (14.4K/day), Astrai can find the cheapest alternative across all providers instead of falling through to OpenRouter's 50/day free tier.

Changes

File Change
api/astrai-summarize.js New Vercel Edge Function — OpenAI-compatible endpoint with Redis caching (shared cache keys with Groq/OpenRouter)
src/services/summarization.ts Add tryAstrai() + wire into all fallback paths (normal, beta warm, beta cold, translation)
src/services/runtime-config.ts Add ASTRAI_API_KEY secret, aiAstrai feature toggle, feature definition

Configuration

Set ASTRAI_API_KEY as a Vercel environment variable (or desktop keychain secret). The feature toggle aiAstrai is enabled by default and appears in the Runtime Config panel.

# Vercel
vercel env add ASTRAI_API_KEY

Design decisions

  • Shared cache keys — Astrai uses the same summary:v3:... cache format as Groq/OpenRouter, so a cached response from any provider serves all three
  • strategy: "cheapest" — Summarization tasks are lightweight (150 max tokens), so cost optimization makes sense over quality optimization
  • Graceful skip — If ASTRAI_API_KEY is not set, the endpoint returns { fallback: true, skipped: true } and the chain continues to OpenRouter

Test plan

  • Verify existing Groq → OpenRouter → Browser T5 chain still works when ASTRAI_API_KEY is not set
  • Test with ASTRAI_API_KEY set — Astrai should handle requests when Groq fails
  • Verify shared Redis cache works (a Groq-cached result should serve Astrai requests and vice versa)
  • Test translation mode includes Astrai fallback
  • Verify aiAstrai toggle appears in Runtime Config panel and can be disabled
  • Beta mode paths include Astrai in fallback

🤖 Generated with Claude Code

…chain

Adds Astrai (AI inference router) as a provider in the summarization
fallback chain: Groq → Astrai → OpenRouter → Browser T5. Astrai
auto-selects the optimal model/provider per request based on cost,
latency, and task complexity.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Feb 19, 2026

@beemaya003 is attempting to deploy a commit to the eliehabib projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 22b5563c61

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +66 to +70
const data = await response.json();
const provider = data.cached ? 'cache' : 'astrai';
console.log(`[Summarization] ${provider === 'cache' ? 'Redis cache hit' : 'Astrai success'}:`, data.model);
return {
summary: data.summary,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Treat Astrai fallback payloads as failed attempts

api/astrai-summarize.js returns HTTP 200 with {fallback: true, skipped: true, summary: null} when ASTRAI_API_KEY is not configured (see the early return around lines 90-95), but this branch accepts any 2xx as success and returns data.summary without checking fallback/summary. That makes generateSummary stop at Astrai with a null summary when Groq fails (e.g., rate limiting) and Astrai is unconfigured, instead of continuing to OpenRouter/Browser fallback.

Useful? React with 👍 / 👎.

Comment on lines +302 to +304
if (response.ok) {
const data = await response.json();
return data.summary;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Continue translation fallback after Astrai skip response

This translation path returns data.summary for any HTTP-200 Astrai response, but the Astrai endpoint uses HTTP 200 for "skipped" fallback responses when the key is missing. In that case data.summary is null, and returning it exits translateText before the OpenRouter step, so translations fail whenever Groq fails and Astrai is enabled but not configured.

Useful? React with 👍 / 👎.

@koala73 koala73 added enhancement New feature or request area: AI/intel AI analysis, intelligence findings, summarization labels Feb 19, 2026
@SebastienMelki SebastienMelki added the claude Generated with Claude Code label Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: AI/intel AI analysis, intelligence findings, summarization claude Generated with Claude Code enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants