Skip to main content

Python SDK for Skills — 轻松集成到 LangChain 的 skills 功能,支持渐进式披露

Project description

LangSkills

Python SDK for Skills — 轻松集成到 LangChain 的 skills 功能,支持渐进式披露(Progressive Disclosure)。

特性

  • 渐进式披露:启动时只加载每个 Skill 的 frontmatter(name、description),完整内容在 agent 选择该 skill 后才加载
  • 节省 Token:避免将大量 skill 全文一次性注入 context
  • LangChain 原生集成:提供 load_skill Tool,与 LangChain / LangGraph agent 无缝配合
  • 标准 Skill 格式:遵循 Agent Skills / Cursor SKILL.md 规范

安装

pip install langskills
# 或
uv add langskills

快速开始

1. 准备 Skills 目录

每个 skill 是一个子目录,包含 SKILL.md

skills/
├── pdf_parser/
│   └── SKILL.md
├── excel_analysis/
│   └── SKILL.md
└── code_review/
    └── SKILL.md

SKILL.md 格式(YAML frontmatter + Markdown body):

---
name: PDF Text Extractor
description: Extract text and basic structure from PDF documents
version: 1.0
---

This skill parses PDF files and returns cleaned text with page numbers.
Use it when you need to feed document content into an LLM.

2. 集成到 LangChain

from langskills import SkillsLoader

loader = SkillsLoader.from_directory("./skills")
tools = loader.to_langchain_tools()  # 返回 [load_skill] Tool

# 传给 agent
agent = create_agent(model, tools=tools)

3. 渐进式披露流程

  1. Agent 启动时只看到 load_skill 的 description(列出所有 skills 的 name + description)
  2. 用户提问时,agent 判断是否需要某 skill
  3. 若需要,调用 load_skill(skill_name="PDF Text Extractor") 加载完整内容
  4. 根据加载的内容执行任务

API

SkillsLoader

from langskills import SkillsLoader

loader = SkillsLoader.from_directory("./skills")

# 列出所有 skill 名称
loader.list_skill_names()

# 获取 skill 简要信息(仅 metadata)
loader.get_skill_summaries()

# 按需加载完整内容
loader.load_skill_content("PDF Text Extractor")

LangChain 集成

from langskills import SkillsLoader, create_load_skill_tool, to_langchain_tools

loader = SkillsLoader.from_directory("./skills")

# 方式 1:直接获取 tools 列表
tools = loader.to_langchain_tools()

# 方式 2:仅创建 load_skill Tool
load_skill_tool = create_load_skill_tool(loader)

开发与测试

# 安装开发依赖
uv sync  # 或 pip install -e ".[dev]"

# 运行测试
pytest

发布到 PyPI

# 安装构建工具
pip install build twine

# 构建
uv build
# 或: python -m build

# 上传(需要 PyPI 账号,首次需配置 ~/.pypirc)
twine upload dist/*

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langskills-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langskills-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file langskills-0.1.0.tar.gz.

File metadata

  • Download URL: langskills-0.1.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for langskills-0.1.0.tar.gz
Algorithm Hash digest
SHA256 969cf8073061867350299ae782b7ba17736363d3fe1e051e7d1966ee440481f9
MD5 95285244236d2a1684bab0505fa7de57
BLAKE2b-256 6e38105a4886c655f523dc16aad4cf23eb77ece538ec1be8f11c280c4525e59a

See more details on using hashes here.

File details

Details for the file langskills-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: langskills-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for langskills-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07a609b7192e74d05d6e67b4a062faed4bd5b99a5fa5915b6f4378c336f490e3
MD5 7b14c054cb8d3f38f2bcd06b5d8c7ba0
BLAKE2b-256 45a3c847ab842a8215c05ec38127cf346aef4c8e1942462294fcf7b062eca0cb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page