ai-assistant: docs/skills: Add skills router design#887
Open
illume wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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) andEmbeddingRouter(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. |
e47e608 to
0f2463e
Compare
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>
0f2463e to
97d87fd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
docs/skills/skills-router.mddocumenting theSkillRouterandEmbeddingRouterdesigns: 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.