Skip to main content
This tutorial shows how to use progressive disclosure - a context management technique where the agent loads information on-demand rather than upfront - to implement skills (specialized prompt-based instructions). The agent loads skills via tool calls, rather than dynamically changing the system prompt, discovering and loading only the skills it needs for each task. Use case: Imagine building an agent to help write SQL queries across different business verticals in a large enterprise. Your organization might have separate datastores for each vertical, or a single monolithic database with thousands of tables. Either way, loading all schemas upfront would overwhelm the context window. Progressive disclosure solves this by loading only the relevant schema when needed. This architecture also enables different product owners and stakeholders to independently contribute and maintain skills for their specific business verticals. What you’ll build: A SQL query assistant with two skills (sales analytics and inventory management). The agent sees lightweight skill descriptions in its system prompt, then loads full database schemas and business logic through tool calls only when relevant to the user’s query.
For a complete example of a SQL agent with query execution, error correction, and validation, see our SQL Agent tutorial. This tutorial focuses on the progressive disclosure pattern which can be applied to any domain.
Progressive disclosure was popularized by Anthropic as a technique for building scalable agent skills systems. This approach uses a three-level architecture (metadata → core content → detailed resources) where agents load information only as needed. For more on this technique, see Equipping agents for the real world with Agent Skills.

How it works

Here’s the flow when a user asks for a SQL query: Why progressive disclosure:
  • Reduces context usage - load only the 2-3 skills needed for a task, not all available skills
  • Enables team autonomy - different teams can develop specialized skills independently (similar to other multi-agent architectures)
  • Scales efficiently - add dozens or hundreds of skills without overwhelming context
  • Simplifies conversation history - single agent with one conversation thread
What are skills: Skills, as popularized by Claude Code, are primarily prompt-based: self-contained units of specialized instructions for specific business tasks. In Claude Code, skills are exposed as directories with files on the file system, discovered through file operations. Skills guide behavior through prompts and can provide information about tool usage or include sample code for a coding agent to execute.
Skills with progressive disclosure can be viewed as a form of RAG (Retrieval-Augmented Generation), where each skill is a retrieval unit—though not necessarily backed by embeddings or keyword search, but by tools for browsing content (like file operations or, in this tutorial, direct lookup).
Trade-offs:
  • Latency: Loading skills on-demand requires additional tool calls, which adds latency to the first request that needs each skill
  • Workflow control: Basic implementations rely on prompting to guide skill usage - you cannot enforce hard constraints like “always try skill A before skill B” without custom logic
Implementing your own skills systemWhen building your own skills implementation (as we do in this tutorial), the core concept is progressive disclosure - loading information on-demand. Beyond that, you have full flexibility in implementation:
  • Storage: databases, S3, in-memory data structures, or any backend
  • Discovery: direct lookup (this tutorial), RAG for large skill collections, file system scanning, or API calls
  • Loading logic: customize latency characteristics and add logic to search through skill content or rank relevance
  • Side effects: define what happens when a skill loads, such as exposing tools associated with that skill (covered in section 8)
This flexibility lets you optimize for your specific requirements around performance, storage, and workflow control.

Setup

Installation

This tutorial requires the langchain package:
For more details, see our Installation guide.

LangSmith

Set up LangSmith to inspect what is happening inside your agent. Then set the following environment variables:

Select an LLM

Select a chat model from LangChain’s suite of integrations:
👉 Read the OpenAI chat model integration docs

1. Define skills

First, define the structure for skills. Each skill has a name, a brief description (shown in the system prompt), and full content (loaded on-demand):
Now define example skills for a SQL query assistant. The skills are designed to be lightweight in description (shown to the agent upfront) but detailed in content (loaded only when needed):

2. Create skill loading tool

Create a tool to load full skill content on-demand:
The load_skill tool returns the full skill content as a string, which becomes part of the conversation as a ToolMessage. For more details on creating and using tools, see the Tools guide.

3. Build skill middleware

Create custom middleware that injects skill descriptions into the system prompt. This middleware makes skills discoverable without loading their full content upfront.
This guide demonstrates creating custom middleware. For a comprehensive guide on middleware concepts and patterns, see the custom middleware documentation.
The middleware appends skill descriptions to the system prompt, making the agent aware of available skills without loading their full content. The load_skill tool is registered as a class variable, making it available to the agent.
Production consideration: This tutorial loads the skill list in __init__ for simplicity. In a production system, you may want to load skills in the before_agent hook instead, allowing them to be refreshed periodically to reflect up-to-date changes (e.g., when new skills are added or existing ones are modified). See the before_agent hook documentation for details.

4. Create the agent with skill support

Now create the agent with the skill middleware and a checkpointer for state persistence:
The agent now has access to skill descriptions in its system prompt and can call load_skill to retrieve full skill content when needed. The checkpointer maintains conversation history across turns.

5. Test progressive disclosure

Test the agent with a question that requires skill-specific knowledge:
Expected output:
The agent saw the lightweight skill description in its system prompt, recognized the question required sales database knowledge, called load_skill("sales_analytics") to get the full schema and business logic, and then used that information to write a correct query following the database conventions.

6. Advanced: Add constraints with custom state

You can add constraints to enforce that certain tools are only available after specific skills have been loaded. This requires tracking which skills have been loaded in custom agent state.

Define custom state

First, extend the agent state to track loaded skills:

Update load_skill to modify state

Modify the load_skill tool to update state when a skill is loaded:

Create constrained tool

Create a tool that’s only usable after a specific skill has been loaded:

Update middleware and agent

Update the middleware to use the custom state schema:
Create the agent with the middleware that registers the constrained tool:
Now if the agent tries to use write_sql_query before loading the required skill, it will receive an error message prompting it to load the appropriate skill (e.g., sales_analytics or inventory_management) first. This ensures the agent has the necessary schema knowledge before attempting to validate queries.

Complete example

Here’s a complete, runnable implementation combining all the pieces from this tutorial:
This complete example includes:
  • Skill definitions with full database schemas
  • The load_skill tool for on-demand loading
  • SkillMiddleware that injects skill descriptions into the system prompt
  • Agent creation with middleware and checkpointer
  • Example usage showing how the agent loads skills and writes SQL queries
To run this, you’ll need to:
  1. Install required packages: pip install langchain langchain-openai langgraph
  2. Set your API key (e.g., export OPENAI_API_KEY=...)
  3. Replace the model initialization with your preferred LLM provider

Implementation variations

This tutorial implemented skills as in-memory Python dictionaries loaded through tool calls. However, there are several ways to implement progressive disclosure with skills:Storage backends:
  • In-memory (this tutorial): Skills defined as Python data structures, fast access, no I/O overhead
  • File system (Claude Code approach): Skills as directories with files, discovered via file operations like read_file
  • Remote storage: Skills in S3, databases, Notion, or APIs, fetched on-demand
Skill discovery (how the agent learns which skills exist):
  • System prompt listing: Skill descriptions in system prompt (used in this tutorial)
  • File-based: Discover skills by scanning directories (Claude Code approach)
  • Registry-based: Query a skill registry service or API for available skills
  • Dynamic lookup: List available skills via a tool call
Progressive disclosure strategies (how skill content is loaded):
  • Single load: Load entire skill content in one tool call (used in this tutorial)
  • Paginated: Load skill content in multiple pages/chunks for large skills
  • Search-based: Search within a specific skill’s content for relevant sections (e.g., using grep/read operations on skill files)
  • Hierarchical: Load skill overview first, then drill into specific subsections
Size considerations (uncalibrated mental model - optimize for your system):
  • Small skills (< 1K tokens / ~750 words): Can be included directly in system prompt and cached with prompt caching for cost savings and faster responses
  • Medium skills (1-10K tokens / ~750-7.5K words): Benefit from on-demand loading to avoid context overhead (this tutorial)
  • Large skills (> 10K tokens / ~7.5K words, or > 5-10% of context window): Should use progressive disclosure techniques like pagination, search-based loading, or hierarchical exploration to avoid consuming excessive context
The choice depends on your requirements: in-memory is fastest but requires redeployment for skill updates, while file-based or remote storage enables dynamic skill management without code changes.

Progressive disclosure and context engineering

Progressive disclosure is fundamentally a context engineering technique - you’re managing what information is available to the agent and when. This tutorial focused on loading database schemas, but the same principles apply to other types of context.

Combining with few-shot prompting

For the SQL query use case, you could extend progressive disclosure to dynamically load few-shot examples that match the user’s query:Example approach:
  1. User asks: “Find customers who haven’t ordered in 6 months”
  2. Agent loads sales_analytics schema (as shown in this tutorial)
  3. Agent also loads 2-3 relevant example queries (via semantic search or tag-based lookup):
    • Query for finding inactive customers
    • Query with date-based filtering
    • Query joining customers and orders tables
  4. Agent writes query using both schema knowledge AND example patterns
This combination of progressive disclosure (loading schemas on-demand) and dynamic few-shot prompting (loading relevant examples) creates a powerful context engineering pattern that scales to large knowledge bases while providing high-quality, grounded outputs.

Next steps