Agentic AI Guide

How to build AI agents that leverage CodeWiki MCP — featuring proven VS Code custom agent definitions and lessons learned.

Overview

CodeWiki MCP turns any LLM agent into a codebase-aware assistant. This guide covers two approaches:

  1. VS Code Custom Agents — Production-tested .agent.md definitions that ship with this project, using a master orchestrator + specialist subagent pattern.
  2. Generic Agent Integration — System prompts and MCP client configs for any LLM framework (Claude Desktop, custom Python agents, etc.).

VS Code Custom Agents

This project ships with 6 production-tested agent definitions in .github/agents/ that work with GitHub Copilot's custom agent system. The architecture uses a master orchestrator that routes requests to 5 specialist subagents.

Architecture Diagram

flowchart LR
    User(["👤 @codewiki"]) --> Master["🎯 CodeWiki Master\n(orchestrator + tool broker)"]

    Master -->|"general questions"| Researcher["🔍 Researcher\n(general exploration)"]
    Master -->|"code-level questions"| Reviewer["📝 Code Review\n(module/function analysis)"]
    Master -->|"design questions"| Architect["🏗️ Architecture Explorer\n(system design)"]
    Master -->|"multi-repo questions"| Comparison["⚖️ Comparison\n(side-by-side analysis)"]
    Master -->|"build from multiple repos"| Synthesizer["🧬 Synthesizer\n(combine & integrate)"]

    MCP["🔌 codewiki-mcp/*\n(5 MCP tools)"] -.->|"exposed via master"| Master
    Skill["📚 SKILL.md\n(domain knowledge)"] -.->|"read on-demand"| Researcher
    Skill -.->|"read on-demand"| Reviewer
    Skill -.->|"read on-demand"| Architect
    Skill -.->|"read on-demand"| Comparison
    Skill -.->|"read on-demand"| Synthesizer

    style Master fill:#6c63ff,stroke:#5a52d5,color:#fff
    style Researcher fill:#1e293b,stroke:#6c63ff,color:#e2e8f0
    style Reviewer fill:#1e293b,stroke:#6c63ff,color:#e2e8f0
    style Architect fill:#1e293b,stroke:#6c63ff,color:#e2e8f0
    style Comparison fill:#1e293b,stroke:#6c63ff,color:#e2e8f0
    style Synthesizer fill:#1e293b,stroke:#6c63ff,color:#e2e8f0
    style MCP fill:#1e293b,stroke:#f59e0b,color:#e2e8f0
    style Skill fill:#1e293b,stroke:#10b981,color:#e2e8f0
    style User fill:#0f172a,stroke:#6c63ff,color:#e2e8f0
      

Master tools: read, agent, codewiki-mcp/* (orchestrator + tool broker)
Subagent tools: read + codewiki-mcp/* (all 5 tools, including NOT_INDEXED handling)
Synthesizer model: GPT-5.3-Codex (needs strong reasoning for multi-repo integration design)
Skills: .github/skills/codewiki-usage/SKILL.md (loaded on-demand via read)

⚠️ Model Warning:

Do not use free or low-tier models (e.g., GPT-5 mini) for the master agent. These models produce inconsistent routing and truncated results — they frequently summarize subagent output instead of presenting it in full, misroute requests, or skip delegation entirely. Use a 1× credit model like GPT-5.3-Codex for reliable orchestration. Subagents can still use cheaper models since their task is more focused.

Key Design Decisions

DecisionRationale
Master is an orchestrator + tool broker The master declares codewiki-mcp/* in its tools list so that MCP tools are exposed to subagents when spawned. The master itself still acts as a router — it delegates via the agent tool and does not call CodeWiki tools directly. Without codewiki-mcp/* on the master, subagents would have no access to the MCP server.
Master uses a capable model (1× credit) Free/low-tier models (GPT-5 mini, GPT-4.1 nano) produce inconsistent routing — truncated results, skipped delegation, brief summaries instead of full output. A 1× credit model like GPT-5.3-Codex ensures reliable orchestration.
Subagents handle everything Each subagent has all 5 codewiki_* tools and handles NOT_INDEXED errors independently. They call codewiki_request_indexing themselves and report back. No pre-checking needed by the master.
user-invokable: false on subagents Prevents users from bypassing the orchestrator. Only the master is directly invokable via @codewiki.
Server name consistency The server name in .vscode/mcp.json (codewiki-mcp) must exactly match the tool prefix in agent files (codewiki-mcp/codewiki_*).
Synthesizer uses a capable model The Synthesizer is the most cognitively demanding subagent — it holds context from 3+ repos simultaneously while doing creative integration design. It uses GPT-5.3-Codex (1× credit) instead of GPT-5 mini to ensure quality architecture blueprints.

1. Master Orchestrator — codewiki.agent.md

The entry point. Users invoke @codewiki in VS Code Chat, and this agent routes to the right specialist. It declares codewiki-mcp/* in its tools list to expose MCP tools to subagents.

YAML Frontmatter

---
name: CodeWiki
description: Master agent that routes your request to the right CodeWiki specialist
argument-hint: Any question about open-source repos, e.g., "Explain React's architecture"
model: GPT-5.3-Codex
tools:
  [read, agent, codewiki-mcp/*]
agents:
  [CodeWiki Researcher, CodeWiki Code Review, CodeWiki Architecture Explorer, CodeWiki Comparison, CodeWiki Synthesizer]
---

Why codewiki-mcp/* on the master? The master must declare MCP tools so they are available when spawning subagents. Without this, subagents cannot access the CodeWiki MCP server.
Why GPT-5.3-Codex? Free/low-tier models produce inconsistent routing and result truncation. A 1× credit model ensures reliable delegation and full result presentation.

Routing Rules

User IntentSubagentSignal Words
General explorationCodeWiki Researcher"what is", "explain", "tell me about", "overview"
Code analysisCodeWiki Code Review"review", "analyse", "module", "function", "code"
System designCodeWiki Architecture Explorer"architecture", "design", "structure", "hierarchy"
Multi-repo comparisonCodeWiki Comparison"compare", "vs", "difference", "or"
Multi-repo synthesisCodeWiki Synthesizer"combine", "merge", "build using", "take X from A and Y from B"
Unindexed repoSubagent handles itSubagent calls codewiki_request_indexing and reports back

Master Workflow

1. CLASSIFY the user's intent from their message
2. DELEGATE immediately to the chosen subagent via the `agent` tool:
   - Include the repo URL (owner/repo format) or a bare keyword
     like "vue" — tools auto-resolve keywords to owner/repo
   - Include the specific question to answer
   - Subagents are stateless and have their own tools — they will
     fetch data and handle errors (including NOT_INDEXED) independently
3. PRESENT THE FULL RESULT: Show the complete subagent response —
   tables, citations, code snippets, everything. Do NOT replace it
   with a brief summary like "Done" or "Comparison delivered".
   Optionally add follow-up suggestions AFTER the full content.
4. MULTI-STEP: For complex requests spanning specialties,
   run subagents sequentially

Example delegation prompt:
  "Research facebook/prophet — explain its main features.
   Repo: facebook/prophet"

2. Specialist Subagents

All 5 specialists share the same tool access (read + codewiki-mcp/*) but differ in their persona, workflow, and output format. All have user-invokable: false. The Synthesizer uses GPT-5.3-Codex for stronger reasoning; the other 4 use GPT-5 mini.

2a. CodeWiki Researcher

File: codewiki-researcher.agent.md — General-purpose exploration and documentation lookup.

---
name: CodeWiki Researcher
description: Explores open-source codebases using Google CodeWiki
model: GPT-5 mini
user-invokable: false
tools:
  [read, codewiki-mcp/*]
---

Workflow:
1. codewiki_read_structure → cheapest discovery
2. codewiki_list_topics → titles + 200-char previews
3. codewiki_read_contents(section_title=...) → targeted reads
4. codewiki_search_wiki → specific implementation questions
5. Synthesize with citations to CodeWiki sections

2b. CodeWiki Code Review

File: codewiki-reviewer.agent.md — Helps developers understand unfamiliar code during reviews.

---
name: CodeWiki Code Review
description: Helps developers understand unfamiliar codebases during code review
model: GPT-5 mini
user-invokable: false
tools:
  [read, codewiki-mcp/*]
---

Focus: Code structure, patterns, implementation details.
Tone: Concise, technical, review-note style.
Output: References specific modules, classes, or functions.

2c. CodeWiki Architecture Explorer

File: codewiki-architect.agent.md — Maps and explains project architectures.

---
name: CodeWiki Architecture Explorer
description: Maps and explains project architectures
model: GPT-5 mini
user-invokable: false
tools:
  [read, codewiki-mcp/*]
---

Output Format:
- Overview: One paragraph summary
- Key Components: Bullet list with descriptions
- Data Flow: How data moves through the system
- Patterns: Design patterns and architectural decisions
- Extension Points: How to extend or customize

2d. CodeWiki Comparison

File: codewiki-comparison.agent.md — Side-by-side multi-repo comparison.

---
name: CodeWiki Comparison
description: Compares multiple open-source repositories side-by-side
model: GPT-5 mini
user-invokable: false
tools:
  [read, codewiki-mcp/*]
---

Output Format: Structured comparison table
| Aspect       | Repo A         | Repo B         |
|--------------|----------------|----------------|
| Architecture | ...            | ...            |
| Key Pattern  | ...            | ...            |

Handles NOT_INDEXED gracefully — continues with available repos,
notes which comparisons are incomplete.

2e. CodeWiki Synthesizer

File: codewiki-synthesizer.agent.md — Combines features, patterns, and architectures from multiple repos into a new solution blueprint.

---
name: CodeWiki Synthesizer
description: Combines features, patterns, and architectures from multiple repos into a new solution blueprint
model: GPT-5.3-Codex
user-invokable: false
tools:
  [read, codewiki-mcp/*]
---

6-Phase Workflow:
1. DECOMPOSE — Parse repos + desired parts (specific or vague)
2. DISCOVER  — For vague requests: explore repos, find standout
               features, select complementary parts automatically
3. RESEARCH  — codewiki tools to gather relevant sections per repo
4. EXTRACT   — Document interfaces, dependencies, patterns per part
5. RESOLVE   — Identify and fix cross-repo incompatibilities
6. DESIGN    — Integration architecture (how parts connect)
7. BLUEPRINT — Directory structure, code snippets, implementation guide

Handles two request types:
- Specific: "Take auth from A, events from B" → skip DISCOVER
- Vague: "Combine best parts from A and B" → DISCOVER first

Output: Parts table, compatibility analysis, Mermaid architecture
diagram, directory structure, integration code, step-by-step guide.

Model: GPT-5.3-Codex — this is the most cognitively demanding
subagent (multi-repo context + creative architecture design).

Skills

Skills are SKILL.md files that provide domain-specific knowledge to agents. They are loaded on-demand via the read tool, so agents only consume tokens when they actually need the knowledge.

Folder Structure

.github/
  skills/
    codewiki-usage/
      SKILL.md          ← domain knowledge for CodeWiki MCP usage

Skill File Format

A SKILL.md file uses YAML frontmatter with name and description fields, followed by the skill content in Markdown:

---
name: codewiki-usage
description: Best practices for using Google CodeWiki MCP tools
  to explore open-source repositories. Covers tool selection
  strategy, token efficiency, pagination, error handling, and
  multi-repo workflows.
---

# CodeWiki MCP — Usage Best Practices

## Tool Selection Strategy (ordered by cost)
...

## Recommended Workflow
...

## Anti-Patterns to Avoid
...

How Skills Work

Lessons Learned

Key insights from building, testing, and debugging the VS Code custom agent system.

1. Server Name Must Match Tool Prefix

The server name in .vscode/mcp.json is used as the tool prefix in agent files. If your config says "codewiki-mcp", your agent tools must reference codewiki-mcp/codewiki_list_topics — not codewikiMcp/codewiki_list_topics.

// .vscode/mcp.json — this name ↓ ...
{
  "servers": {
    "codewiki-mcp": {
      "type": "stdio",
      "command": "codewiki-mcp"
    }
  }
}

// ... must match this prefix ↓ in .agent.md files
tools:
  - 'codewiki-mcp/codewiki_list_topics'

2. Master Must Expose MCP Tools for Subagents

The master agent must declare codewiki-mcp/* in its tools list — not because the master calls those tools directly, but because subagents need the master to expose MCP tools so they can access them when spawned. Without codewiki-mcp/* on the master, subagents would have no connection to the CodeWiki MCP server. The master still acts as a router in its system prompt — it delegates via the agent tool and never calls CodeWiki tools directly.

# Master tools — all three are required:
tools:
  [read, agent, codewiki-mcp/*]
#  ↑ read skills  ↑ spawn subagents  ↑ expose MCP to subagents

3. Subagents Are Stateless — Let Them Do All the Work

Subagents receive only the delegation prompt — no chat history, no pre-fetched data. They call their own tools independently. This means the master doesn't need to check repo availability before routing. The subagent handles everything: discovery, reading, NOT_INDEXED detection, and indexing requests.

4. user-invokable: false Prevents Bypass

Without this flag, users can type @codewiki-researcher directly, bypassing the orchestrator's routing and pre-fetch logic. Setting user-invokable: false on all subagents ensures the master is the only entry point.

5. Custom Agents Only Work in VS Code Chat Panel

VS Code custom agents (.agent.md files) are activated via @agentname in the Chat panel (Ctrl+Shift+I). They do NOT work in:

  • Inline Chat (Ctrl+I)
  • Terminal inline suggestions
  • Regular Copilot conversation without the @ prefix

6. Tool Declaration Format

When listing tools in the YAML frontmatter, use shorthand names: read for reading files, agent for spawning subagents, and codewiki-mcp/* as a wildcard for all MCP tools. The agents: property lists which subagents the orchestrator can spawn.

# Master agent tools ✓
tools:
  [read, agent, codewiki-mcp/*]
agents:
  [CodeWiki Researcher, CodeWiki Code Review, ...]

# Subagent tools ✓
tools:
  [read, codewiki-mcp/*]

7. Skills Provide Reusable Domain Knowledge

Skills (SKILL.md files) are separate from agents and loaded on-demand via the read tool. They provide domain-specific best practices (tool selection strategy, anti-patterns, workflows) without bloating agent prompts. Since skills are workspace-wide, all agents — including future ones — can access them automatically.

8. Always Present the Full Subagent Result

A common pitfall: the master receives a detailed response from a subagent (comparison tables, cited sections, code examples) but only shows the user a brief summary like "Done — comparison delivered. Want me to do X?". The subagent's output IS the answer — always present the complete content first, then optionally suggest follow-ups after. The master's synthesis step must never gate or truncate results behind a follow-up question.

9. Don't Use Free/Low-Tier Models for the Master Agent

Free and low-tier models (GPT-5 mini, GPT-4.1, GPT-4.1 nano) produce inconsistent results when used as the master orchestrator. Common failure modes include:

  • Truncated output: The master summarizes the subagent's detailed response into a single sentence instead of presenting it in full.
  • Skipped delegation: The master tries to answer from its own knowledge instead of spawning a subagent.
  • Misrouting: Requests get sent to the wrong specialist (e.g., a comparison routed to the Researcher).
  • Lost context: Multi-step requests (architecture + comparison) only complete the first step.

Recommendation: Use a 1× credit model like GPT-5.3-Codex for the master agent. Subagents can still use cheaper models (GPT-5 mini) since their tasks are more focused and less prone to these failure modes.

Generic Agent Integration

If you're building agents outside VS Code (Claude Desktop, custom Python, LangChain, etc.), use these system prompts and configurations.

Skill Definition

A skill tells your agent when and how to use CodeWiki MCP tools. Use this as a reusable building block in any agent framework.

CodeWiki MCP Skill

Name: codewiki-research
Description: Research and understand open-source codebases using
  Google CodeWiki. Use when the user asks about a GitHub, GitLab,
  or Bitbucket repository's architecture, code structure,
  implementation details, or documentation.

Triggers:
  - User asks "how does [repo] work?"
  - User asks about a repository's architecture or design
  - User needs to understand code in a specific repo
  - User asks "explain [feature] in [repo]"

Available Tools:
  1. codewiki_read_structure    — Table of contents (JSON, cheapest)
  2. codewiki_list_topics  — Titles + short previews (lightweight)
  3. codewiki_read_contents     — Read paginated or section-specific docs
  4. codewiki_search_wiki       — Ask Gemini a question about the repo
  5. codewiki_request_indexing  — Submit unindexed repos for indexing

Recommended Workflow (token-efficient):
  1. Start with codewiki_read_structure (~500-1000 tokens)
  2. Call codewiki_list_topics for titles + previews (~2000-3000 tokens)
  3. Use codewiki_read_contents with section_title for targeted reads
  4. Use codewiki_search_wiki only for specific questions

System Prompt Template

A general-purpose system prompt you can adapt for any LLM agent framework:

Codebase Research Agent

You are a codebase research agent with access to Google CodeWiki
via MCP tools. Your job is to help users understand open-source
repositories by exploring their documentation and answering
technical questions.

## Tools Available (ordered by token efficiency)
- codewiki_read_structure(repo_url) — JSON table of contents (cheapest)
- codewiki_list_topics(repo_url) — Titles + short previews
- codewiki_read_contents(repo_url, section_title?, offset?, limit?) — Read docs
- codewiki_search_wiki(repo_url, query) — Ask Gemini about the repo
- codewiki_request_indexing(repo_url) — Submit unindexed repos

## Workflow
1. codewiki_read_structure → discover sections (cheapest)
2. codewiki_list_topics → titles + 200-char previews
3. codewiki_read_contents(section_title=...) → targeted reads
4. codewiki_search_wiki → specific implementation questions
5. Synthesize into a clear, cited answer

## Rules
- Always cite which section your answer is based on
- If NOT_INDEXED, call codewiki_request_indexing and inform the user
- Use owner/repo shorthand (e.g., "microsoft/vscode") or bare keywords
  (e.g., "vue", "react") — keywords are auto-resolved via CodeWiki search
- Never fabricate information — only report what tools return

MCP Client Configuration

Connect your agent to CodeWiki MCP by adding the server to your MCP client config:

VS Code (.vscode/mcp.json)

{
  "servers": {
    "codewiki-mcp": {
      "type": "stdio",
      "command": "codewiki-mcp"
    }
  }
}

Important: The server name (codewiki-mcp) must match the tool prefix used in your .agent.md files.

Claude Desktop

{
  "mcpServers": {
    "codewiki": {
      "command": "codewiki-mcp"
    }
  }
}

Custom Agent (Python)

# Example: connecting via subprocess
import subprocess, json

proc = subprocess.Popen(
    ["codewiki-mcp"],
    stdin=subprocess.PIPE,
    stdout=subprocess.PIPE,
    text=True
)
# Send MCP JSON-RPC requests to proc.stdin
# Read MCP JSON-RPC responses from proc.stdout

Custom Agent (SSE)

# Start server in SSE mode
codewiki-mcp --sse --port 8080

# Then connect your agent to http://localhost:8080/sse

Agent Error Handling

Teach your agent to handle CodeWiki MCP errors gracefully:

# In your agent's tool-call handler:

result = call_mcp_tool("codewiki_search_wiki", {
    "repo_url": repo,
    "query": question
})

response = json.loads(result)

if response["status"] == "error":
    code = response.get("code", "UNKNOWN")

    if code == "TIMEOUT":
        # Retry once, or fall back to codewiki_read_contents
        pass
    elif code == "NO_CONTENT":
        # Repo may not be indexed — inform the user
        pass
    elif code == "NOT_INDEXED":
        # Repo is not yet in CodeWiki — submit for indexing
        call_mcp_tool("codewiki_request_indexing", {"repo_url": repo})
        # Inform user: repo submitted, check back later
        pass
    elif code == "RATE_LIMIT":
        # Wait and retry, or switch to cached tools
        pass
    elif code == "VALIDATION":
        # Fix the input (bad repo_url format, etc.)
        pass
    else:
        # Log and inform user of unexpected error
        pass

Best Practices

PracticeWhy
Start with topics, then narrow Avoids wasting calls on repos where CodeWiki has limited coverage
Use structure before contents Lets the agent pick the right section instead of reading everything
Prefer section reads over search for broad topics Section content is deterministic and cached; search uses Gemini chat which is slower
Use search for specific implementation questions Gemini chat excels at pointed questions about code behavior
Handle errors gracefully Check status field; repos may not be indexed or responses can time out
Use owner/repo shorthand or keywords Bare keywords like "vue" auto-resolve to the correct repo; owner/repo and full URLs also work
Cache-aware timing First call may take 5-15s (Playwright render); subsequent calls within 5 min are cached

Keyword Resolution & Disambiguation

All tools accept bare product keywords (e.g., "vue", "react", "openclaw") in addition to owner/repo shorthand and full URLs. Keywords are resolved via CodeWiki's search page with interactive disambiguation using the MCP Elicitation protocol (VS Code 0.29+).

How It Works

  1. Input validation detects bare keywords (single words with no / or URL scheme)
  2. CodeWiki's search page is queried with the keyword
  3. Resolution strategy:
    • Single result → auto-select
    • Canonical match (owner == repo == keyword) → auto-select, e.g., "openclaw" → openclaw/openclaw
    • Multiple ambiguous resultsMCP Elicitation: VS Code presents a selection prompt listing the top candidates with star counts, and the user picks the correct repo
    • Fallback (elicitation unavailable) → heuristic selection by star count
  4. The response includes a resolution note showing what was resolved and top alternatives

Elicitation Prompt Example

Multiple repositories match "vue".

1. vuejs/vue (209.9k★)
2. vuejs/core (52.9k★)
3. panjiachen/vue-element-admin (90.3k★)

Which repository do you want to explore?
→ User selects "vuejs/core"

Resolution Note (in response)

> **Resolved:** keyword "vue" → **vuejs/core** (52,900★)
> Other candidates: vuejs/vue (209,900★), panjiachen/vue-element-admin (90,300★)

Token Efficiency Guide

CodeWiki MCP tools vary dramatically in token output. Understanding this helps you write efficient agents.

Tool Token Cost Comparison

ToolTypical TokensUse For
codewiki_read_structure500–1,500Table of contents / discovery
codewiki_list_topics2,000–4,000Titles + content previews
codewiki_read_contents (section)500–5,000Targeted section content
codewiki_read_contents (paginated)3,000–8,000Multiple sections at once
codewiki_search_wiki1,000–6,000Specific questions
codewiki_request_indexing200–500Submit unindexed repos

Best Token-Efficiency Workflow

  1. Start with codewiki_read_structure (cheapest, ~800 tokens)
  2. Read only the sections you need with codewiki_read_contents(section_title=...)
  3. Use pagination (offset/limit) to avoid loading the entire wiki
  4. Reserve codewiki_search_wiki for questions that sections can't answer

Model Selection & Credit Optimization

When using GitHub Copilot, your model choice significantly affects credit consumption and output quality.

GitHub Copilot Model Multipliers

ModelMultiplierCredits per RequestRecommendation
GPT-4.1 / GPT-4.1 miniFree (on paid plans)Subagents only — not for master
GPT-4.1 nanoFree (on paid plans)Subagents only — too weak for routing
GPT-5 miniFree (on paid plans)Subagents only — inconsistent as master
Gemini 2.5 Flash0.33×~0.33Good balance of capability/cost
GPT-5.3-Codex1Recommended for master agent
Claude Sonnet 41Good alternative for master agent
Claude Opus 4.5 / 4.63Use sparingly for complex analysis
Claude Opus 4.110×10Reserve for critical tasks only

⚠️ Master Agent Model Requirement

The master orchestrator should use a 1× credit model minimum (e.g., GPT-5.3-Codex or Claude Sonnet 4). Free/low-tier models produce inconsistent routing, truncated subagent output, and skipped delegation. Subagents can still use free models — their focused tasks are less prone to these failure modes.

Credit Budget Tips

TipSavings
Use GPT-5.3-Codex for master + Synthesizer, GPT-5 mini for other subagents1 credit for routing, 1 for synthesis, 0 for other data gathering
Use codewiki_read_structure first to avoid unnecessary calls~5,000-10,000 tokens saved per skipped tool call
Use section_title parameter instead of reading full pages70-90% fewer tokens per call
Use pagination with small limit valuesRead only what you need, not everything
Leverage caching — repeated calls within 5 min are freeEliminates redundant Playwright renders
Don't use Opus-tier models for routine lookupsSave 3-10× credits per request

See also: Agent Testing Guide — sample prompts and validation checklists for testing the VS Code custom agents.