技能 架构中,专门的能力被打包为可调用的"技能",以增强 智能体 的行为。技能主要是提示词驱动的专业化能力,智能体可以按需调用。
此模式在概念上与 llms.txt (由 Jeremy Howard 提出)相同,它使用工具调用来渐进式地披露文档。技能模式将相同的方法应用于专门的提示词和领域知识,而不仅仅是文档页面。

主要特点

  • 提示词驱动的专业化:技能主要由专门的提示词定义
  • 渐进式披露:技能根据上下文或用户需求变得可用
  • 团队分布:不同的团队可以独立开发和维护技能
  • 轻量级组合:技能比完整的子智能体更简单

何时使用

当您想要一个具有多种可能专业化的单一 智能体 、不需要在技能之间强制执行特定约束,或者不同的团队需要独立开发能力时,请使用技能模式。常见示例包括编码助手(不同语言或任务的技能)、知识库(不同领域的技能)和创意助手(不同格式的技能)。

基本实现

import { tool, createAgent } from "langchain";
import * as z from "zod";

const loadSkill = tool(
  async ({ skillName }) => {
    // Load skill content from file/database
    return "";
  },
  {
    name: "load_skill",
    description: `Load a specialized skill.

Available skills:
- write_sql: SQL query writing expert
- review_legal_doc: Legal document reviewer

Returns the skill's prompt and context.`,
    schema: z.object({
      skillName: z
        .string()
        .describe("Name of skill to load")
    })
  }
);

const agent = createAgent({
  model: "gpt-4o",
  tools: [loadSkill],
  prompt: (
    "You are a helpful assistant. " +
    "You have access to two skills: " +
    "write_sql and review_legal_doc. " +
    "Use load_skill to access them."
  ),
});
For a complete implementation, see the tutorial below.

Tutorial: Build a SQL assistant with on-demand skills

Learn how to implement skills with progressive disclosure, where the agent loads specialized prompts and schemas on-demand rather than upfront.

Extending the pattern

When writing custom implementations, you can extend the basic skills pattern in several ways:
  • Dynamic tool registration : Combine progressive disclosure with state management to register new tools as skills load. For example, loading a “database_admin” skill could both add specialized context and register database-specific tools (backup, restore, migrate). This uses the same tool-and-state mechanisms used across multi-agent patterns—tools updating state to dynamically change agent capabilities.
  • Hierarchical skills : Skills can define other skills in a tree structure, creating nested specializations. For instance, loading a “data_science” skill might make available sub-skills like “pandas_expert”, “visualization”, and “statistical_analysis”. Each sub-skill can be loaded independently as needed, allowing for fine-grained progressive disclosure of domain knowledge. This hierarchical approach helps manage large knowledge bases by organizing capabilities into logical groupings that can be discovered and loaded on-demand.

Connect these docs to Claude, VSCode, and more via MCP for real-time answers.