Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(ai): enable OpenRouter query expansion (#3499)

cybernaut64046920744dd882
diff --git a/TODOS.md b/TODOS.md
index 9d548b71c1..6afeb95a88 100644
--- a/TODOS.md
+++ b/TODOS.md
@@ -82,17 +82,20 @@ Deferred from the provider-agnostic plumbing wave (#1249/#1250/#1292/#2271/#2209
Plan + review trail at `~/.claude/plans/system-instruction-you-are-working-keen-newell.md`.
The eng-review + Codex outside-voice narrowed the wave to these deferrals:
-- [ ] **P2 — Capability-aware query expansion on OpenAI-compat providers (#2372).**
+- [x] **P2 — Capability-aware query expansion on OpenAI-compat providers (#2372).**
Expansion only runs for recipes that declare an `expansion` touchpoint, and only the
native providers (anthropic/openai/google) do. To make expansion work on
litellm/openrouter/groq/together/deepseek you must ADD expansion touchpoints to those
chat-capable recipes AND add a `generateObject`→`generateText` capability fallback for
backends without strict structured outputs. Feature-shaped; overlaps the general
OpenAI-compat proxy story (`docs/designs/COMMUNITY_IDEAS.md`). Community PR #2373 is a
- starting point. Where: `src/core/ai/gateway.ts:expand`, recipe files, `types.ts` (ExpansionTouchpoint).
-- [ ] **P2 — LiteLLM as a chat/expansion backend.** `litellm-proxy` declares ONLY an
+ starting point. Implemented by #2373 plus the DeepSeek/Groq/Together recipe wave,
+ LiteLLM chat/expansion support, and the OpenRouter expansion touchpoint. Where:
+ `src/core/ai/gateway.ts:expand`, recipe files, `types.ts` (ExpansionTouchpoint).
+- [x] **P2 — LiteLLM as a chat/expansion backend.** `litellm-proxy` declares ONLY an
embedding touchpoint, so `think`/chat on LiteLLM is dead. Add chat (and expansion) so a
- LiteLLM proxy is a full LLM backend, not embedding-only. The general OpenAI-compat proxy story.
+ LiteLLM proxy is a full LLM backend, not embedding-only. Implemented by #2208.
+ The general OpenAI-compat proxy story.
- [ ] **P3 — Per-model embedding dims metadata on `EmbeddingTouchpoint`.** `default_dims`
is recipe-wide, so a recipe (ollama) can't carry different native dims per model. This
wave added the modern ollama model NAMES + a `trust_custom_dims` passthrough (user supplies
diff --git a/src/core/ai/recipes/openrouter.ts b/src/core/ai/recipes/openrouter.ts
index 4e4502aaa3..221041727b 100644
--- a/src/core/ai/recipes/openrouter.ts
+++ b/src/core/ai/recipes/openrouter.ts
@@ -180,6 +180,17 @@ export const openrouter: Recipe = {
// to pre-split batches, NOT per-input. Per-input is enforced upstream.
max_batch_tokens: 300_000,
},
+ // Expansion uses the same routed OpenAI-compatible language-model endpoint
+ // as chat. Keep a small cheap/fast advisory set; the openai-compat tier
+ // still accepts any user-configured OpenRouter provider/model ID.
+ expansion: {
+ models: [
+ 'anthropic/claude-haiku-4.5',
+ 'google/gemini-3-flash-preview',
+ 'deepseek/deepseek-chat',
+ ],
+ price_last_verified: '2026-05-20',
+ },
chat: {
// Curated entry points (verified against OR's catalog 2026-05-20). The
// openai-compat tier does NOT enforce this list at runtime — users can
diff --git a/test/ai/gateway.test.ts b/test/ai/gateway.test.ts
index 10aaceeea6..730cc8b71f 100644
--- a/test/ai/gateway.test.ts
+++ b/test/ai/gateway.test.ts
@@ -114,11 +114,12 @@ describe('gateway.isAvailable (silent-drop regression surface)', () => {
// #1135 — an explicit expansion_model pointed at a chat-capable
// OpenAI-compatible provider used to silently yield no expansion because
// the recipe declared no expansion touchpoint.
- test('expansion available for chat-capable openai-compat providers (deepseek/groq/together)', () => {
+ test('expansion available for chat-capable openai-compat providers (deepseek/groq/together/openrouter)', () => {
const cases: Array<[string, Record<string, string>]> = [
['deepseek:deepseek-chat', { DEEPSEEK_API_KEY: 'fake' }],
['groq:llama-3.1-8b-instant', { GROQ_API_KEY: 'fake' }],
['together:meta-llama/Llama-3.3-70B-Instruct-Turbo', { TOGETHER_API_KEY: 'fake' }],
+ ['openrouter:google/gemini-3-flash-preview', { OPENROUTER_API_KEY: 'fake' }],
];
for (const [model, env] of cases) {
resetGateway();
diff --git a/test/ai/recipe-openrouter.test.ts b/test/ai/recipe-openrouter.test.ts
index 6323c9bd70..1793a49653 100644
--- a/test/ai/recipe-openrouter.test.ts
+++ b/test/ai/recipe-openrouter.test.ts
@@ -65,6 +65,18 @@ describe('recipe: openrouter', () => {
).not.toThrow();
});
+ test('3b. expansion reuses routed chat models and accepts arbitrary provider/model IDs', () => {
+ const r = getRecipe('openrouter')!;
+ expect(r.touchpoints.expansion).toBeDefined();
+ expect(r.touchpoints.expansion!.models.length).toBeGreaterThanOrEqual(3);
+ expect(() =>
+ assertTouchpoint(r, 'expansion', 'some/provider-model'),
+ ).not.toThrow();
+ expect(() =>
+ assertTouchpoint(r, 'expansion', 'meta-llama/llama-future-2030'),
+ ).not.toThrow();
+ });
+
test('4. chat models list — every entry matches provider/model shape (D5 regression)', () => {
// Codex correction: pinning specific slugs creates false confidence (the
// list is advisory; OR's catalog churns). The shape test catches the