zcbot/tools/skill_tool.py

46 lines
1.5 KiB
Python

"""load_skill 工具: agent 主动加载某个 skill 的完整 SKILL.md。
这是渐进披露的中间层 (Activation): 启动时只看到 name+description,
认为自己要做某类任务时,调 load_skill 拿到完整指引。
"""
from __future__ import annotations
from pathlib import Path
from typing import Optional
from core.skills import SkillRegistry
from .base import Tool
class LoadSkillTool(Tool):
name = "load_skill"
description = (
"Load full instructions for a skill. Call this when the current task matches "
"a skill's domain (e.g. writing PPT, coding, research proposal). "
"Returns the SKILL.md body, which may reference further files in skills/<name>/references."
)
parameters = {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Skill name as listed in the system prompt's discovery block",
}
},
"required": ["name"],
}
def __init__(self, registry: SkillRegistry, base_dir: Optional[Path] = None) -> None:
super().__init__(base_dir)
self.registry = registry
def execute(self, name: str) -> str:
skill = self.registry.get(name)
if skill is None:
available = ", ".join(self.registry.skills.keys()) or "(none)"
return f"[Error] skill '{name}' not found. Available: {available}"
body = skill.full_content()
header = f"[skill={skill.name}, dir={skill.skill_dir}]\n"
return header + body