Skip to content

ai-assistant: docs/skills: Add skills router design#887

Open
illume wants to merge 1 commit into
headlamp-k8s:mainfrom
illume:docs/ai-assistant-skills-router
Open

ai-assistant: docs/skills: Add skills router design#887
illume wants to merge 1 commit into
headlamp-k8s:mainfrom
illume:docs/ai-assistant-skills-router

Conversation

@illume

@illume illume commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Adds docs/skills/skills-router.md documenting the SkillRouter and EmbeddingRouter designs: keyword-overlap matching, semantic similarity via LangChain embeddings, configurable size budgets, and fallback behaviour.

Assisted by Copilot.

Part of the ai-assistant skills documentation series.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new documentation page describing a proposed “skills router” architecture for selecting a subset of skills per user query (keyword overlap vs embedding similarity), including configuration concepts, intended LangChain pipeline integration, and references.

Changes:

  • Adds SkillRouter (keyword) and EmbeddingRouter (embedding similarity) design explanation and selection flow.
  • Documents proposed configuration knobs (max skills, min score, size budget) and routing phases (index/query).
  • Includes an integration diagram, setup snippets, and reference links for related docs/projects.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

**Pros:** Zero latency, no external API calls, no additional cost.
**Cons:** Misses semantic similarity (e.g., "pod networking issues" won't match a skill tagged "CNI troubleshooting" unless the words overlap).

**Source:** [`ai-common/src/skills/SkillRouter.ts`](../../packages/ai-common/src/skills/SkillRouter.ts)
- **Provider-agnostic.** The router accepts any LangChain [`Embeddings`](https://js.langchain.com/docs/concepts/embedding_models/) instance — OpenAI, Ollama, Azure, Cohere, etc. The caller configures the provider; the router just calls `embedDocuments()` and `embedQuery()`.
- **Automatic fallback.** If embedding fails (model unavailable, rate-limited, network error), the router falls back to keyword-based routing. Skill routing errors never block the main LLM call.

**Source:** [`ai-common/src/skills/EmbeddingRouter.ts`](../../packages/ai-common/src/skills/EmbeddingRouter.ts)
Comment on lines +64 to +67
## LLM pipeline integration

The routing is wired into the LangChain pipeline through `SkillManager` and `LangChainManager`:

└── LLM call with system prompt + chat history + user message
```

The `LangChainManager` stores the routed skills text in a transient `currentSkillsPromptText` field per request. This avoids threading the skills text through every internal method (`handleDirectToolCallingRequest`, `handleLocalModelRequest`, etc.).
Comment on lines +93 to +95
### Setup code

```typescript
Comment on lines +107 to +110
const embeddings = new OpenAIEmbeddings({
apiKey: 'sk-...',
model: 'text-embedding-3-small',
});
similarity = (a · b) / (‖a‖ × ‖b‖)
```

For normalized embedding vectors (as produced by most providers), results are in [0, 1] where 1 means identical meaning and 0 means unrelated. The `minScore` threshold (default 0.1) filters out low-relevance matches.
Comment on lines +182 to +186
### Internal documentation

- [Skills system proposal](./skills-proposal.md) — architecture decisions, industry survey, and security considerations for the skills system.
- [Skills STRIDE threat model](./skills-stride-threat-model.md) — security threat analysis for skill loading, routing, and prompt injection.

Comment on lines +152 to +156
## Cache invalidation

- Skills are cached for 1 hour (configurable via `cacheTtlMs`).
- Changing skill sources in the config automatically invalidates the cache.
- Calling `skillManager.invalidateCache()` clears both the skill cache and the embedding index, forcing a full reload and re-indexing on the next query.
@illume illume force-pushed the docs/ai-assistant-skills-router branch 2 times, most recently from e47e608 to 0f2463e Compare July 8, 2026 11:52
Documents the skill routing layer used to select which skills to inject
into each query.

- `SkillRouter`: keyword-overlap scoring between the query tokens and skill
  triggers/descriptions. Applies a configurable size budget to cap the total
  token cost of injected skill content.
- `EmbeddingRouter`: extends `SkillRouter` with semantic similarity via a
  pluggable LangChain Embeddings instance. Falls back to keyword routing when
  embeddings are unavailable.

Documents the scoring algorithm, configuration options (score threshold, max
size budget, embedding model), and the routing pipeline from raw query to the
formatted skill block appended to the system prompt.

Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Co-authored-by: Ashu Ghildiyal <aghildiyal@microsoft.com>
Signed-off-by: Ashu Ghildiyal <aghildiyal@microsoft.com>
@illume illume force-pushed the docs/ai-assistant-skills-router branch from 0f2463e to 97d87fd Compare July 8, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants