Chapter 18 of 32 · ~15 min read & lab+65 XP
Chapter 18 · Agentic AI

Agent Skills & Progressive Tool Discovery: Scaling Beyond 100 Tools

Stop stuffing 150 tool schemas into every prompt—learn how progressive disclosure, Agent Skills, and dynamic tool search keep context lean and tool accuracy high

What Is It?

Progressive tool disclosure (and Agent Skills) is a context-engineering pattern where an agent starts with only lightweight skill summaries and loads full tool schemas or domain instructions on demand.

Why Is It Required?

Dumping 100+ MCP tool schemas into the system prompt burns 20,000–40,000 tokens on every single turn, destroys prompt caching, spikes cost, and causes tool-selection accuracy to plummet due to schema distraction.

Everyday Analogy: A skilled surgeon doesn't dump every surgical textbook and 500 instruments onto the operating table at once; they keep a compact index on the wall and open the exact tray and checklist needed for today's procedure.
Why ML Engineers & Data Scientists Actually Need This

Once an enterprise connects 5–10 MCP servers (GitHub, Jira, Slack, Postgres, Stripe, Datadog), the agent suddenly faces 150+ tools—and naive tool injection breaks both latency and accuracy.

ML / AI Engineer

You implement a 2-tier catalog: a compact index of skills/tools in the system prompt, plus a search_tools or load_skill meta-tool that dynamically mounts only the 3–8 schemas needed for the active task.

Data Scientist

You benchmark tool-selection F1 and input tokens per turn as the catalog grows from 10 to 500 tools.

Interview & Debug Edge

Explaining 'Progressive Disclosure' (L1: name + 1-line summary → L2: full instructions/schema on demand → L3: executable scripts/references) is the hallmark of a Staff-level Agentic AI Engineer.

Step 0 · Test Your Gut Before Any Math!

Your agent connects to 8 MCP servers exposing 160 tools (~220 tokens per JSON schema). Roughly how many prompt tokens are wasted BEFORE the user even types 'Hi'?

What You Will Master in This Chapter
  • Model Context Protocol (MCP) Architecture
  • Context Engineering: Compaction & Scratchpads
Story-First Intuition, Visual Diagrams & Interactive Walkthroughs

Context is a scarce attention budget, not an infinite junk drawer. Progressive disclosure applies lazy loading to agent prompts: keep the initial prompt small and cache-friendly, and load heavy instructions or tool schemas only when the current task actually triggers them.

1. The 3-Level Progressive Disclosure Architecture

Modern agent harnesses organize capabilities into three tiers:

TierWhat Is LoadedToken CostWhen Loaded
Level 1: Discovery IndexSkill/tool names + 1-line trigger descriptions~20–40 tokens eachAlways in system prompt (cacheable!)
Level 2: Active Playbook / SchemasFull SKILL.md instructions or exact JSON parameter schemas~500–2,000 tokensDynamically loaded when task matches
Level 3: Supporting AssetsReference docs, SQL templates, helper scriptsOn-demand readsOnly when executing a specific sub-step

2. Tool Search (RAG for Tools)

When an agent has 200+ tools across multiple MCP servers:

  1. Index every tool's name, description, and parameter tags in an in-memory BM25 + embedding index.
  2. Give the LLM a lightweight meta-tool: find_tools(query, top_k=5).
  3. When the user asks "Refund invoice #882 and notify #billing on Slack", the agent searches once, mounts only stripe_refund_invoice and slack_post_message, and executes with near-100% schema accuracy.

3. Protecting Prompt Caching While Loading Dynamically

A subtle production pitfall: never mutate the top of the system prompt when loading a new skill or tool—that invalidates the entire KV prefix cache! Instead:

  • Keep the Level 1 index frozen at the top of the system prompt (100% cache hit).
  • Inject Level 2 skill instructions or dynamically discovered tool schemas as a tool observation message appended to the end of the conversation history.
“Wait, I'm Confused...” · Teacher Office Hours Q&A

The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.

Up to ~15–20 well-differentiated tools, static injection is simpler and faster (zero extra discovery turn). Above ~30–50 tools—or whenever tool schemas exceed ~5,000 tokens—dynamic tool discovery and Agent Skills pay off immediately.

Interactive Visual Lab
Lab Challenge: Visualize how keeping the active context window compact preserves attention and lowers token overhead.
Interactive Animation • 3.3 Deep Lab

Long-Horizon Context Compaction Animator (Beating Context Rot)

Watch context utilization climb toward 80% during a long coding run, then compact cleanly into a 18% high-signal handoff summary.

Window Fill: 20%
Raw Trajectory (24K tok): 14 raw file dumps + 8 full stack traces piling up...
0%
Accumulating Raw Tool Logs
Intuition Takeaway: Scale agents past 50+ tools using Progressive Disclosure: keep a tiny, cacheable Level 1 index in the system prompt and load full schemas or Agent Skills on demand into the active turn.
Production NumPy & PyTorch Code Patterns
# Progressive Tool Discovery: Static Injection vs. On-Demand Top-K Mounting
TOOL_CATALOG = [
    {"name": "stripe_refund", "desc": "Issue a full or partial payment refund for a Stripe charge", "tokens": 240},
    {"name": "stripe_invoice", "desc": "Fetch customer invoice PDF and billing status", "tokens": 210},
    {"name": "slack_post_msg", "desc": "Send a message to a Slack channel or thread", "tokens": 190},
    {"name": "github_create_pr", "desc": "Open a pull request on a GitHub repository", "tokens": 260},
    {"name": "postgres_query", "desc": "Run a read-only SQL query against analytics warehouse", "tokens": 230},
]

def search_tools(query: str, catalog: list[dict], top_k: int = 2) -> list[dict]:
    q_words = set(query.lower().split())
    scored = []
    for t in catalog:
        doc_words = set((t["name"].replace("_", " ") + " " + t["desc"]).lower().split())
        overlap = len(q_words & doc_words)
        scored.append((overlap, t))
    scored.sort(key=lambda x: x[0], reverse=True)
    return [t for score, t in scored[:top_k] if score > 0]

static_tokens = sum(t["tokens"] for t in TOOL_CATALOG)
selected = search_tools("refund payment and post to slack channel", TOOL_CATALOG, top_k=2)
dynamic_tokens = len(TOOL_CATALOG) * 25 + sum(t["tokens"] for t in selected)

print("Selected tools:", [t["name"] for t in selected])
print(f"Prompt schema tokens -> Static: {static_tokens} | Progressive: {dynamic_tokens}")
Common ML Interview Traps & Numerical Pitfalls
Trap #1: Mutating the system prompt's prefix whenever a skill is loaded
Best Practice: this busts prompt caching on every turn instead of appending loaded skills at the tail of the message list.
Trap #2: Over-fragmenting into 500 tiny overlapping tools
Best Practice: even with tool search, clean domain boundaries and well-named tools matter most.
Chapter Mastery Check (+65 XP)
Score: 0 / 1
1Why should dynamically loaded Agent Skills or tool schemas be appended as tool observations rather than spliced into the top of the system prompt?

Apply What You Learned — Solve Matching Coding Problems