home / skills / jawwad-ali / claude-code-skills / knowledge-router

knowledge-router skill

/.claude/skills/knowledge-router

This skill decides when to route questions between curated skills and Context7 to optimize documentation lookups for frameworks, libraries, and APIs.

npx playbooks add skill jawwad-ali/claude-code-skills --skill knowledge-router

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
8.8 KB
---
name: Knowledge Router
description: This skill should be used internally to decide when to use curated skills versus Context7 MCP for documentation lookups. Use this when handling technical questions about frameworks, libraries, or APIs to determine the optimal knowledge retrieval strategy.
version: 1.0.0
---

# Knowledge Router: Skill + Context7 Hybrid System

This meta-skill provides decision logic for routing knowledge requests between curated skills and Context7 MCP server.

## Decision Framework

```
┌─────────────────────────────────────────────────────────────────┐
│                      QUERY ANALYSIS                              │
└─────────────────────────────┬───────────────────────────────────┘
                              │
                              ▼
                   ┌─────────────────────┐
                   │  Check Query Type   │
                   └──────────┬──────────┘
                              │
        ┌─────────────────────┼─────────────────────┐
        │                     │                     │
        ▼                     ▼                     ▼
  ┌───────────┐        ┌───────────┐        ┌───────────┐
  │  PATTERN  │        │  LOOKUP   │        │  HYBRID   │
  │  REQUEST  │        │  REQUEST  │        │  REQUEST  │
  └─────┬─────┘        └─────┬─────┘        └─────┬─────┘
        │                    │                    │
        ▼                    ▼                    ▼
   Use SKILL            Use CONTEXT7         Use BOTH
   (curated)            (dynamic)            (layered)
```

## Query Classification

### Type 1: PATTERN REQUESTS → Use Skill First

**Indicators:**
- "How do I..." / "Create a..." / "Implement..."
- "Best practice for..." / "Recommended way to..."
- "Add X to my project" / "Set up X"
- Common tasks (CRUD, auth, routing, etc.)

**Examples:**
```
"How do I add authentication to FastAPI?" → SKILL
"Create a REST endpoint" → SKILL
"Best practice for error handling" → SKILL
"Set up database connection" → SKILL
```

**Action:** Load relevant skill, use curated patterns.

---

### Type 2: LOOKUP REQUESTS → Use Context7 First

**Indicators:**
- "What is the syntax for..." / "What are the parameters..."
- "Does X support Y?" / "Can I do X with Y?"
- Specific version questions ("in FastAPI 0.100+")
- Error messages (pasted stack traces)
- "Latest" / "New" / "Updated" / "Deprecated"
- Obscure/advanced features

**Examples:**
```
"What parameters does HTTPException accept?" → CONTEXT7
"Does FastAPI support HTTP/2?" → CONTEXT7
"Error: ValidationError for field X" → CONTEXT7
"What's new in Pydantic v2?" → CONTEXT7
"How do I use the new Annotated syntax?" → CONTEXT7
```

**Action:** Query Context7 directly for authoritative docs.

---

### Type 3: HYBRID REQUESTS → Skill + Context7

**Indicators:**
- Complex implementations needing patterns + details
- "Complete example of..." / "Production-ready..."
- Integrations between multiple libraries
- Debugging (need pattern context + error lookup)

**Examples:**
```
"Production-ready JWT auth with refresh tokens" → HYBRID
"Integrate FastAPI with Celery" → HYBRID
"Debug this authentication error [paste]" → HYBRID
"Complete WebSocket chat implementation" → HYBRID
```

**Action:**
1. Load skill for architectural pattern
2. Query Context7 for specific implementation details
3. Synthesize unified response

---

## Routing Decision Matrix

| Signal | Route To | Reason |
|--------|----------|--------|
| Common task keywords | Skill | Pre-validated patterns |
| Error message pasted | Context7 | Search for specific error |
| "Latest", "new", "v2" | Context7 | Need current docs |
| "Best practice", "recommended" | Skill | Curated opinions |
| Specific parameter questions | Context7 | API reference |
| Architecture questions | Skill | Curated structures |
| Third-party integration | Context7 first | May not be in skill |
| "Why does X..." | Hybrid | Pattern + explanation |
| Debugging request | Hybrid | Context + specific error |

---

## Execution Protocol

### When Using SKILL Only

```
1. Identify the relevant skill (fastapi, nextjs, etc.)
2. Load SKILL.md into context
3. Generate response using curated patterns
4. If skill indicates "ESCALATE" for topic → switch to Hybrid
```

### When Using CONTEXT7 Only

```
1. Resolve library ID:
   mcp__context7__resolve-library-id(
     libraryName: "fastapi",
     query: "user's specific question"
   )

2. Query documentation:
   mcp__context7__query-docs(
     libraryId: "/websites/fastapi_tiangolo",
     query: "specific topic from user question"
   )

3. Synthesize response from fetched docs
```

### When Using HYBRID (Recommended for Complex Tasks)

```
1. Load relevant skill for architectural context
2. Generate initial structure using skill patterns
3. Identify gaps or specific details needed
4. Query Context7 for those specifics:
   mcp__context7__query-docs(libraryId, "specific detail needed")
5. Merge skill patterns with Context7 details
6. Return unified, comprehensive response
```

---

## Available Skills & Their Coverage

| Skill | Covers (Tier 1) | Escalate to Context7 For |
|-------|-----------------|--------------------------|
| `fastapi` | Routes, Pydantic, Auth, DI, Middleware | WebSocket scaling, GraphQL, specific drivers |
| `fastapi-hybrid` | Same + built-in escalation triggers | Auto-escalates per topic |
| `nextjs-app-router` | Pages, Layouts, RSC, Server Actions | Specific Next.js config, edge runtime |

---

## Context7 Library Quick Reference

| Technology | Library ID | Best For |
|------------|------------|----------|
| FastAPI | `/websites/fastapi_tiangolo` | Full docs, tutorials |
| FastAPI (GitHub) | `/fastapi/fastapi` | Source-level details |
| Pydantic | `/pydantic/pydantic` | Validation, v2 migration |
| SQLAlchemy | `/sqlalchemy/sqlalchemy` | ORM, async patterns |
| Starlette | `/encode/starlette` | Low-level ASGI details |
| Next.js | `/vercel/next.js` | App router, RSC |
| React | `/facebook/react` | Hooks, patterns |

---

## Response Quality Checklist

Before finalizing a response, verify:

- [ ] **Pattern provided** - Not just API reference, but how to use it
- [ ] **Code is complete** - Imports included, runnable example
- [ ] **Follows conventions** - Matches project structure if known
- [ ] **Error handling shown** - Not just happy path
- [ ] **Version appropriate** - Correct syntax for current versions
- [ ] **Escalation noted** - If topic has nuances, mention where to find more

---

## Example Routing Decisions

### Example 1: "Add JWT authentication to my FastAPI app"

**Analysis:**
- Task: Implementation pattern request
- Complexity: Medium (common task)
- Specificity: General

**Route:** SKILL (fastapi)
- Load fastapi skill
- Provide JWT pattern from curated examples
- Note: If user needs OAuth2 scopes or specific providers, offer to query Context7

---

### Example 2: "What's the difference between Depends and Security in FastAPI?"

**Analysis:**
- Task: Conceptual/API explanation
- Complexity: Low
- Specificity: Specific to FastAPI internals

**Route:** CONTEXT7
- Query: `mcp__context7__query-docs("/websites/fastapi_tiangolo", "Depends vs Security dependency injection")`
- Return explanation from official docs

---

### Example 3: "Build a production-ready chat application with FastAPI WebSockets"

**Analysis:**
- Task: Complex implementation
- Complexity: High
- Specificity: Needs architecture + details

**Route:** HYBRID
1. Load fastapi skill → Get basic WebSocket pattern
2. Query Context7 → "websocket connection manager broadcast rooms"
3. Query Context7 → "websocket authentication"
4. Synthesize → Complete chat architecture with all details

---

## Token Efficiency Guidelines

| Scenario | Strategy | Estimated Tokens |
|----------|----------|------------------|
| Single question, common topic | Skill only | ~2,000 (skill load) |
| Single question, specific lookup | Context7 only | ~1,500 (one query) |
| Multi-turn, same topic | Skill (amortized) | ~2,000 total |
| Complex implementation | Hybrid | ~3,500 (skill + 1-2 queries) |
| Debugging session | Hybrid | ~4,000 (skill + error lookups) |

**Optimization:** For multi-turn conversations on the same technology, load the skill once and only query Context7 for specific gaps.

Overview

This skill routes technical documentation and pattern requests between curated skills and the Context7 MCP documentation service. It decides whether to answer from a validated pattern, fetch authoritative docs, or combine both for complex tasks to produce accurate, practical guidance. Use it to optimize retrieval strategy for frameworks, libraries, and APIs.

How this skill works

The router analyzes the user's query to classify it as a pattern request, a lookup request, or a hybrid need. For common implementation tasks it selects a curated skill; for precise API/syntax/version questions it queries Context7; for complex integrations or debugging it loads a skill for architecture and then fetches specific docs from Context7 to fill gaps. It then synthesizes the best response based on that route.

When to use it

  • Answering common implementation or best-practice questions (CRUD, auth, routing).
  • Resolving exact API signatures, version changes, deprecated features, or pasted error messages.
  • Handling complex integrations that need both architecture patterns and precise API details.
  • Debugging sessions where pattern context plus specific error lookups are required.
  • Multi-turn conversations about the same technology where efficiency matters.

Best practices

  • Classify queries by intent keywords (e.g., "how do I", "what parameters", "latest").
  • Prefer curated skill for patterns and opinions; prefer Context7 for up-to-date, authoritative references.
  • For complex tasks, use the hybrid flow: generate pattern first, then query Context7 for missing specifics.
  • Load the relevant curated skill once for multi-turn flows to save tokens and maintain context.
  • When uncertain, escalate to hybrid rather than relying solely on one source.

Example use cases

  • "How do I add JWT authentication to FastAPI?" → use curated FastAPI skill for pattern and code samples.
  • "What parameters does HTTPException accept in FastAPI 0.100+?" → query Context7 for exact API reference.
  • "Build a production WebSocket chat with FastAPI and Redis" → hybrid: skill for architecture, Context7 for connection and scaling details.
  • Debugging: paste a stack trace → Context7 to find matching docs or issue tracker entries, then synthesize fix with skill patterns.
  • Integrations: combine pattern from one skill with Context7 docs for third-party library edge cases.

FAQ

How do you decide between skill and Context7?

Decisions use query signals: pattern keywords steer to skills; version, error, and API-precision steer to Context7; mixed signals trigger hybrid routing.

What if a curated skill is outdated?

The router will escalate to hybrid or Context7 when it detects version-specific or deprecated features, ensuring authoritative, current details.