AgentSkillsCN

Knowledge Router

在内部决策时,应根据需求选择使用精选技能,还是借助 Context7 MCP 进行文档查询。当您解答有关框架、库或 API 的技术问题时,可利用此技能来确定最优化的知识检索策略。

SKILL.md
--- frontmatter
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

code
┌─────────────────────────────────────────────────────────────────┐
│                      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:

code
"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:

code
"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:

code
"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

SignalRoute ToReason
Common task keywordsSkillPre-validated patterns
Error message pastedContext7Search for specific error
"Latest", "new", "v2"Context7Need current docs
"Best practice", "recommended"SkillCurated opinions
Specific parameter questionsContext7API reference
Architecture questionsSkillCurated structures
Third-party integrationContext7 firstMay not be in skill
"Why does X..."HybridPattern + explanation
Debugging requestHybridContext + specific error

Execution Protocol

When Using SKILL Only

code
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

code
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)

code
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

SkillCovers (Tier 1)Escalate to Context7 For
fastapiRoutes, Pydantic, Auth, DI, MiddlewareWebSocket scaling, GraphQL, specific drivers
fastapi-hybridSame + built-in escalation triggersAuto-escalates per topic
nextjs-app-routerPages, Layouts, RSC, Server ActionsSpecific Next.js config, edge runtime

Context7 Library Quick Reference

TechnologyLibrary IDBest For
FastAPI/websites/fastapi_tiangoloFull docs, tutorials
FastAPI (GitHub)/fastapi/fastapiSource-level details
Pydantic/pydantic/pydanticValidation, v2 migration
SQLAlchemy/sqlalchemy/sqlalchemyORM, async patterns
Starlette/encode/starletteLow-level ASGI details
Next.js/vercel/next.jsApp router, RSC
React/facebook/reactHooks, 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

ScenarioStrategyEstimated Tokens
Single question, common topicSkill only~2,000 (skill load)
Single question, specific lookupContext7 only~1,500 (one query)
Multi-turn, same topicSkill (amortized)~2,000 total
Complex implementationHybrid~3,500 (skill + 1-2 queries)
Debugging sessionHybrid~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.