jianmu.skill¶
适用对象:Skill 作者 / Skill 运行时集成者 / 核心维护者
是否必读:按需
相关模块:jianmu.node, jianmu.tool, jianmu.execution
1. 模块职责¶
jianmu.skill 负责把技能定义从文件系统和元数据装载成可执行对象。
这里的重点是“装载与选择”,不是“实际执行节点”;执行通常由 SkillNode 等上层对象负责。
2. 适合查什么¶
- Skill 数据结构:
Skill、SkillRecord、SkillRequirements - 目录与选择:
SkillsCatalog - 装载器:
SkillLoader、SkillTreeLoader - BT 上下文:
BTSkillContext
3. 注意事项¶
SkillLoader依赖可选包python-frontmatter- BT skill 场景通常还会依赖额外约束与执行环境
- 如果只是使用 skill 节点,通常无需直接操作全部装载细节
4. builtin 路径说明¶
jianmu.skill.builtin 更适合承接“框架随包分发的内建 skill 资源”,而不是普通用户的主导入入口。
这意味着:
jianmu.skill负责 skill 的公开抽象、目录、装载和 BT 集成jianmu.skill.builtin更像内建资源的归档层
如果未来要把某些内建 skill 提升为正式公开 API,也应优先通过 jianmu.skill 或专门的稳定子入口暴露,而不是让主文档默认要求用户直接依赖 builtin 路径。
5. 最小示例¶
from jianmu.skill import SkillLoader
loader = SkillLoader()
skill = loader.load("/path/to/SKILL.md")
一个最小 SKILL.md 可以是:
---
name: repo_summary
description: Summarize this repository
execution: prompt
---
Read the repository and summarize the main architecture.
6. 常见入口¶
- 想从文件加载 skill:看
SkillLoader - 想做 skill 目录发现与覆盖:看
SkillsCatalog - 想加载 BT skill 的
tree.py:看SkillTreeLoader - 想在节点里直接使用 skill:去看
jianmu.node.SkillNode
7. API 参考¶
skill
¶
Skill system for jianmu.
Skill
dataclass
¶
Skill(
name: str,
description: str,
prompt: str,
source: Optional[str] = None,
base_dir: Optional[str] = None,
always: bool = False,
role: Optional[str] = None,
push_to_chat: bool = False,
inputs: Optional[dict[str, Any]] = None,
outputs: Optional[dict[str, Any]] = None,
required: Optional[list[str]] = None,
tools: list[str] = list(),
tools_entry: list[str] = list(),
execution: str = "prompt",
orchestration: str = "react",
tree: Optional[str] = None,
files: list[str] = list(),
constraints: Constraints = Constraints(),
)
Represents a fully parsed skill model in Jianmu.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
name |
str
|
Stable skill identifier used for routing and display. |
description |
str
|
Human-readable summary shown to models and operators. |
prompt |
str
|
Primary prompt body for prompt-based skills. |
source |
Optional[str]
|
Optional source file path of the originating skill definition. |
base_dir |
Optional[str]
|
Optional root directory used to resolve bundled skill files. |
always |
bool
|
Whether the skill should always be injected into prompt context. |
role |
Optional[str]
|
Optional swarm role name associated with the skill. |
push_to_chat |
bool
|
Whether the skill output should be appended to chat history. |
inputs |
Optional[dict[str, Any]]
|
Optional JSON-schema-like input definition. |
outputs |
Optional[dict[str, Any]]
|
Optional JSON-schema-like output definition. |
required |
Optional[list[str]]
|
Optional list of required output field names. |
tools |
list[str]
|
Tool names enabled for this skill. |
tools_entry |
list[str]
|
Optional explicit custom-tool entry files relative to the
skill root. When omitted, docker tool discovery falls back to the
legacy |
execution |
str
|
Execution mode, typically |
orchestration |
str
|
SkillNode execution strategy, |
tree |
Optional[str]
|
Optional behavior-tree file path for BT-backed skills. |
files |
list[str]
|
Additional resource files exposed to the skill at runtime. |
constraints |
Constraints
|
Guard or execution constraints applied to the skill. |
SkillCandidate
dataclass
¶
SkillCandidate(
name: str,
path: str,
source: str,
description: str = "",
available: bool = True,
always: bool = False,
execution: str = "prompt",
orchestration: str = "react",
inputs: dict[str, Any] = dict(),
outputs: dict[str, Any] = dict(),
required: list[str] = list(),
tools: list[str] = list(),
role: str | None = None,
push_to_chat: bool = False,
missing_reasons: str | None = None,
metadata: dict[str, Any] = dict(),
)
Routing candidate generated from a skill, used during routing selection.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
name |
str
|
Candidate skill name presented to the router. |
path |
str
|
Path to the backing skill definition. |
source |
str
|
Origin label such as |
description |
str
|
Human-readable summary for ranking and prompting. |
available |
bool
|
Whether the candidate can run in the current environment. |
always |
bool
|
Whether the candidate must always be included. |
execution |
str
|
Execution mode, typically |
orchestration |
str
|
SkillNode execution strategy, |
inputs |
dict[str, Any]
|
Input schema exposed to the router or caller. |
outputs |
dict[str, Any]
|
Output schema exposed to the router or caller. |
required |
list[str]
|
Required output field names for structured responses. |
tools |
list[str]
|
Tool names granted to the skill. |
role |
str | None
|
Optional associated role for swarm-driven routing. |
push_to_chat |
bool
|
Whether the produced output is mirrored to chat history. |
missing_reasons |
str | None
|
Pre-rendered explanation for unavailability. |
metadata |
dict[str, Any]
|
Extra routing metadata preserved from the source record. |
SkillRecord
dataclass
¶
SkillRecord(
name: str,
path: str,
source: str,
description: str = "",
available: bool = True,
always: bool = False,
requires: SkillRequirements = SkillRequirements(),
missing_bins: list[str] = list(),
missing_env: list[str] = list(),
unsupported_os: list[str] = list(),
raw_metadata: dict[str, Any] = dict(),
)
Internal registry entry for cataloged skill files.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
name |
str
|
Skill name declared by the loaded metadata. |
path |
str
|
Absolute or workspace-relative path to the skill definition file. |
source |
str
|
Origin label such as |
description |
str
|
Short summary extracted from skill metadata. |
available |
bool
|
Whether the skill can run in the current environment. |
always |
bool
|
Whether the skill is always included during routing/prompting. |
requires |
SkillRequirements
|
Structured availability requirements for the skill. |
missing_bins |
list[str]
|
Missing CLI binaries that block execution. |
missing_env |
list[str]
|
Missing environment variables that block execution. |
unsupported_os |
list[str]
|
OS constraints that are not satisfied by the host. |
raw_metadata |
dict[str, Any]
|
Unprocessed metadata dictionary captured from the source. |
missing_reasons_text
¶
Render unmet availability requirements as one display string.
返回:
| 类型 | 描述 |
|---|---|
str
|
A comma-separated string describing missing CLI binaries, env vars, or OS support. |
源代码位于: jianmu/skill/types.py
SkillRequirements
dataclass
¶
Defines execution requirements for a skill, such as platform and binaries.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
bins |
list[str]
|
Required CLI binaries that must be available on the host. |
env |
list[str]
|
Required environment variable names. |
os |
list[str]
|
Supported operating-system names for this skill. |
SkillsCatalog
¶
SkillsCatalog(
*,
workspace_skills_dir: str | Path | None = None,
builtin_skills_dir: str | Path | None = None,
)
Framework-level catalog for builtin and workspace skills.
The catalog is responsible for discovery, precedence, availability checks, and prompt-oriented rendering. Workspace skills override builtin skills by name, so application-local customizations can replace packaged defaults without forking the framework.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
workspace_skills_dir |
Optional project-local skill root. |
|
builtin_skills_dir |
Packaged builtin skill root. |
Configure workspace and builtin skill search roots.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
workspace_skills_dir
|
str | Path | None
|
Optional project-local skill root. Skills here override builtin skills with the same name. |
None
|
builtin_skills_dir
|
str | Path | None
|
Optional override for the packaged builtin skill directory. |
None
|
源代码位于: jianmu/skill/catalog.py
resolve_runtime
classmethod
¶
Resolve the effective skills catalog for the current runtime.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
runtime_prompt
|
'PromptRuntimeContext | None'
|
Optional runtime prompt overrides describing skills context. |
None
|
返回:
| 类型 | 描述 |
|---|---|
'SkillsCatalog | None'
|
Effective skills catalog for the current runtime, or |
源代码位于: jianmu/skill/catalog.py
list_skills
¶
List known skills, optionally filtering unavailable entries.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
filter_unavailable
|
bool
|
Whether to exclude unavailable skills. |
True
|
返回:
| 类型 | 描述 |
|---|---|
list[SkillRecord]
|
A list of SkillRecord objects. |
源代码位于: jianmu/skill/catalog.py
get_skill
¶
Return one skill by name.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
name
|
str
|
The name of the skill to search for. |
必需 |
filter_unavailable
|
bool
|
Whether to exclude unavailable skills. |
False
|
返回:
| 类型 | 描述 |
|---|---|
SkillRecord | None
|
The matching SkillRecord, or None if not found. |
源代码位于: jianmu/skill/catalog.py
resolve_records
¶
resolve_records(
names: Iterable[str] | None = None,
*,
filter_unavailable: bool = True,
) -> list[SkillRecord]
Resolve ordered skill records for one runtime selection request.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
names
|
Iterable[str] | None
|
Collection of name values. |
None
|
filter_unavailable
|
bool
|
Whether unavailable skills should be excluded. |
True
|
返回:
| 类型 | 描述 |
|---|---|
list[SkillRecord]
|
Ordered skill records matching the requested names. |
源代码位于: jianmu/skill/catalog.py
select_records_for_context
¶
Resolve the skill records exposed to prompt context for one run.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
include_unavailable_skills
|
bool
|
Whether unavailable skills may be exposed to prompts. |
False
|
返回:
| 类型 | 描述 |
|---|---|
list[SkillRecord]
|
Skill records exposed to prompt context for the current run. |
源代码位于: jianmu/skill/catalog.py
load_skill_content
¶
Load raw SKILL.md content for one named skill.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
name
|
str
|
The name of the skill. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
str | None
|
The raw Markdown text content of the skill, or None. |
源代码位于: jianmu/skill/catalog.py
load_skill_from_path
¶
Load a skill object directly from a filesystem path.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
path
|
str | Path
|
filesystem path to the skill. |
必需 |
引发:
| 类型 | 描述 |
|---|---|
RuntimeError
|
If SkillLoader dependency is not installed. |
返回:
| 类型 | 描述 |
|---|---|
'Skill'
|
The resulting |
源代码位于: jianmu/skill/catalog.py
load_skills_for_context
¶
Concatenate selected skills into one prompt-ready context block.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
skill_names
|
Iterable[str]
|
An iterable of skill names to load. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
str
|
A prompt-ready concatenated context string. |
源代码位于: jianmu/skill/catalog.py
get_always_skills
¶
Return available skills marked as always-on.
返回:
| 类型 | 描述 |
|---|---|
list[SkillRecord]
|
A list of available SkillRecord objects marked as always-on. |
源代码位于: jianmu/skill/catalog.py
snapshot
¶
Build a stable snapshot digest for skill catalog caching.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
include_unavailable
|
bool
|
Whether to include unavailable skills in the snapshot. |
True
|
返回:
| 类型 | 描述 |
|---|---|
dict[str, Any]
|
A dictionary containing the version hash and rows of skill metadata. |
源代码位于: jianmu/skill/catalog.py
build_skills_summary
¶
build_skills_summary(
records: list[SkillRecord] | None = None,
*,
include_unavailable_reasons: bool = True,
) -> str
Render skills as an XML-like summary block for prompts.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
records
|
list[SkillRecord] | None
|
Optional list of SkillRecord objects. Defaults to all catalog skills. |
None
|
include_unavailable_reasons
|
bool
|
Whether to output XML tag for missing requirements. |
True
|
返回:
| 类型 | 描述 |
|---|---|
str
|
The rendered XML-like skills summary block. |
源代码位于: jianmu/skill/catalog.py
build_candidates
¶
build_candidates(
*,
skill_files: Iterable[str | Path] | None = None,
skills_dir: str | Path | None = None,
enabled_skills: Iterable[str] | None = None,
include_unavailable: bool = False,
) -> list[SkillCandidate]
Build routing candidates from explicit files and/or skill directories.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
skill_files
|
Iterable[str | Path] | None
|
Optional files to load as routing candidates. |
None
|
skills_dir
|
str | Path | None
|
Optional directory containing candidate subdirectories. |
None
|
enabled_skills
|
Iterable[str] | None
|
Optional filter of enabled skill names. |
None
|
include_unavailable
|
bool
|
Whether to load candidates that are currently not available. |
False
|
返回:
| 类型 | 描述 |
|---|---|
list[SkillCandidate]
|
A list of constructed SkillCandidate objects. |
源代码位于: jianmu/skill/catalog.py
build_routing_summary
¶
build_routing_summary(
candidates: list[SkillCandidate],
*,
include_paths: bool = False,
include_requires: bool = False,
) -> str
Render routing candidates into a compact summary string.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
candidates
|
list[SkillCandidate]
|
List of SkillCandidate objects to summarize. |
必需 |
include_paths
|
bool
|
Whether to output file paths. |
False
|
include_requires
|
bool
|
Whether to output missing requirements block. |
False
|
返回:
| 类型 | 描述 |
|---|---|
str
|
A compact newline-separated summary of routing candidates. |
源代码位于: jianmu/skill/catalog.py
SkillSet
¶
Selected skills for one run.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
skills |
Loaded runtime skills selected for the current run. |
|
catalog |
Optional catalog used to resolve the selected skills. |
源代码位于: jianmu/skill/set.py
prompt_skills
property
¶
Return prompt-driven skills in this set.
返回:
| 类型 | 描述 |
|---|---|
list[Skill]
|
Prompt-driven skills selected for the current run. |
bt_skills
property
¶
Return BT skills in this set.
返回:
| 类型 | 描述 |
|---|---|
list[Skill]
|
Behavior-tree-backed skills selected for the current run. |
resolve
classmethod
¶
resolve(
*,
skill_files: Sequence[str | Path] | None = None,
enabled_skills: Sequence[str] | None = None,
explicit_enabled_skills: bool = False,
skills_dir: str | Path | None = None,
runtime_prompt: "PromptRuntimeContext | None" = None,
) -> "SkillSet"
Resolve the selected skills for one runtime request.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
skill_files
|
Sequence[str | Path] | None
|
Collection of skill file values. |
None
|
enabled_skills
|
Sequence[str] | None
|
Collection of enabled skill values. |
None
|
explicit_enabled_skills
|
bool
|
Whether an explicitly provided empty
|
False
|
skills_dir
|
str | Path | None
|
Optional workspace skill directory override. |
None
|
runtime_prompt
|
'PromptRuntimeContext | None'
|
Optional runtime prompt overrides describing skills context. |
None
|
返回:
| 类型 | 描述 |
|---|---|
'SkillSet'
|
Resolved runtime skill set. |
源代码位于: jianmu/skill/set.py
from_records
classmethod
¶
from_records(
records: Sequence[SkillRecord],
*,
catalog: SkillsCatalog | None = None,
) -> "SkillSet"
Build a skill set from an existing catalog record selection.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
records
|
Sequence[SkillRecord]
|
Records to process. |
必需 |
catalog
|
SkillsCatalog | None
|
Optional catalog associated with the selected records. |
None
|
返回:
| 类型 | 描述 |
|---|---|
'SkillSet'
|
Skill set loaded from the provided catalog records. |
源代码位于: jianmu/skill/set.py
has_skill
¶
Return whether one selected skill matches the given name.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
name
|
str
|
Skill name to look up. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
bool
|
|
源代码位于: jianmu/skill/set.py
builtin_tool_names
¶
Return builtin tool names declared by the selected skills.
返回:
| 类型 | 描述 |
|---|---|
list[str]
|
Builtin tool names declared across all selected skills. |
源代码位于: jianmu/skill/set.py
SkillLoader
¶
Parse SKILL.md files into runtime Skill objects.
SkillLoader is the lowest-level entrypoint for file-based skills. It
reads frontmatter metadata, prompt body, execution mode, bundled files, and
embedded constraints, then produces a normalized Skill instance.
Minimal skill file::
---
name: repo_summary
description: Summarize this repository
execution: prompt
---
Read the repository and produce a short summary.
load
¶
Parse a SKILL.md file and return a Skill object.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
path
|
str
|
Local filesystem path to the SKILL.md file. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
Skill
|
The parsed Skill configuration object. |
引发:
| 类型 | 描述 |
|---|---|
RuntimeError
|
If the frontmatter dependency is not installed. |
ValueError
|
If an unsupported execution mode is specified. |
FileNotFoundError
|
If a behavior tree file is specified but not found. |
Notes
execution: prompt uses the Markdown body as prompt content.
execution: bt additionally resolves a sibling tree.py (or
custom tree field) for behavior-tree-backed skills.
源代码位于: jianmu/skill/loader.py
load_as_node
¶
load_as_node(
name: str,
path: str,
model_client: Optional[Any] = None,
trace: Optional[Any] = None,
model: Optional[str] = None,
) -> Behaviour
Load a SKILL.md as a SkillNode-style behaviour.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
name
|
str
|
The name of the resulting skill node. |
必需 |
path
|
str
|
Local path to the SKILL.md file. |
必需 |
model_client
|
Optional[Any]
|
Optional model client instance. |
None
|
trace
|
Optional[Any]
|
Optional trace configuration. |
None
|
model
|
Optional[str]
|
Optional model name. |
None
|
返回:
| 类型 | 描述 |
|---|---|
Behaviour
|
The loaded SkillNode instance, wrapped in a |
Behaviour
|
skill declares a timeout constraint. |
源代码位于: jianmu/skill/loader.py
SkillTreeLoader
¶
Load and materialize tree.py -> build_tree() for execution=bt skills.
resolve_tree_path
staticmethod
¶
Resolve the tree.py path for a BT skill.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
skill
|
Skill
|
The skill object to resolve the path for. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
Path
|
The resolved absolute Path to the tree.py file. |
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
If the skill has no base directory configured. |
FileNotFoundError
|
If the tree.py file does not exist on disk. |
源代码位于: jianmu/skill/tree_loader.py
load_build_fn
¶
Import and return the build_tree function for a BT skill.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
skill
|
Skill
|
The skill object to load the build function for. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
Callable[..., Any]
|
The imported callable build_tree function. |
引发:
| 类型 | 描述 |
|---|---|
ImportError
|
If the tree.py module fails to import. |
ValueError
|
If the module is missing a callable build_tree function. |
源代码位于: jianmu/skill/tree_loader.py
build_tree
¶
Build and validate the behaviour tree for one BT skill.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
skill
|
Skill
|
The skill object. |
必需 |
ctx
|
BTSkillContext
|
The runtime BTSkillContext context payload. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
Behaviour
|
The instantiated behavior tree root Behaviour node. |
引发:
| 类型 | 描述 |
|---|---|
TypeError
|
If the build function does not return a py_trees Behaviour instance. |
源代码位于: jianmu/skill/tree_loader.py
BTSkillContext
dataclass
¶
BTSkillContext(
skill_result_key: str,
messages: list[Message] = list(),
inputs: dict[str, Any] = dict(),
namespace: str = "",
tools: dict[str, Any] = dict(),
model_client: Any = None,
constraints: Any = None,
)
Runtime context passed to BT skill build_tree().
This keeps behavior-tree-backed skills independent from Jianmu internals by exposing only the inputs they typically need: messages, namespace, tools, model client, and constraints.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
messages |
list[Message]
|
Conversation messages visible to the BT skill. |
inputs |
dict[str, Any]
|
Structured input payload resolved for the BT invocation. |
namespace |
str
|
State namespace prefix reserved for this skill run. |
skill_result_key |
str
|
Namespace-local state key where BT skills should write their final structured result. |
tools |
dict[str, Any]
|
Mapping of enabled tool names to tool objects. |
model_client |
Any
|
Active model client exposed to the skill. |
constraints |
Any
|
Guard or execution constraints applied to the skill run. |