Skip to main content

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

Project description

LangSkills

Python SDK for Skills — LangChain 渐进式披露(Progressive Disclosure)工具,按需加载 skill 内容,节省 Token。

特性

  • 渐进式披露:启动时仅加载 skill 元信息(name + description),完整内容按需加载
  • 节省 Token:避免一次性注入所有 skill 文档
  • LangChain 原生集成:开箱即用的 load_skill Tool
  • 标准格式:兼容 Agent Skills / Cursor SKILL.md 规范

安装

pip install langskills

快速开始

1. 准备 Skills 目录

skills/
├── pdf_parser/
│   └── SKILL.md
└── weather_query/
    └── SKILL.md

SKILL.md 示例(YAML frontmatter + Markdown):

---
name: Weather Query
description: Get current weather information for any city
version: 1.0
---

Use this skill to fetch real-time weather data.
Call the weather API with city name as parameter.

2. 集成到 LangChain

import uuid
from langchain.chat_models import init_chat_model
from langskills import SkillsLoader
from langchain.agents import create_agent

# 加载 skills
loader = SkillsLoader.from_directory("./skills")
tools = loader.to_langchain_tools()  # 生成 load_skill tool

# 初始化模型
llm = init_chat_model(
    base_url="https://api.example.com/v1",
    api_key="your-api-key",
    model="Qwen/Qwen3-32B",
    model_provider="openai",
)

# 创建 agent
agent = create_agent(llm, tools=tools)

# 调用
response = agent.invoke(
    {"messages": [{"role": "user", "content": "今天天气如何"}]},
    {"configurable": {"thread_id": str(uuid.uuid4())}},
)

print(response["messages"])

工作流程

  1. Agent 启动时看到 load_skill tool(列出所有 skill 名称和描述)
  2. 用户提问后,agent 判断需要哪个 skill
  3. 调用 load_skill(skill_name="Weather Query") 加载完整内容
  4. 根据内容执行任务

API

from langskills import SkillsLoader

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

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

# 获取简要信息(仅元数据)
loader.get_skill_summaries()

# 按需加载完整内容
loader.load_skill_content("Weather Query")

# 转为 LangChain tools
tools = loader.to_langchain_tools()

开发

# 安装依赖
uv sync

# 运行测试
pytest

发布

uv build
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.1.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.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: langskills-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 f9b36444dfc5a50efdebba8430e8cb32ef8c548694d3824ab41e88263ac55f67
MD5 6fcd334ced9bd15ea34f4766ebf50054
BLAKE2b-256 15519d006128170d7daf4ddf4258362cecfb71e5708364724583535df8adf209

See more details on using hashes here.

File details

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

File metadata

  • Download URL: langskills-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4694523a902cb5d76da6e0f5344e9aee754c3efcf0dd1c23136deed1dadf6726
MD5 5181ac0fc24ded9522748342a6054e4a
BLAKE2b-256 bc8118290b68feb69df31fe372873ffb2bd0fba543572df19ec6f6c975e28a48

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