Class: LLM::Skill
- Inherits:
-
Object
- Object
- LLM::Skill
- Defined in:
- lib/llm/skill.rb
Overview
LLM::Skill represents a directory-backed packaged capability. A skill directory must contain a ‘SKILL.md` file with YAML frontmatter. Skills can expose themselves as normal LLM::Tool classes through #to_tool. This keeps skills on the same execution path as local tools.
Instance Attribute Summary collapse
-
#description ⇒ String
readonly
Returns the skill description.
-
#frontmatter ⇒ LLM::Object
readonly
Returns the skill frontmatter.
-
#instructions ⇒ String
readonly
Returns the skill instructions.
-
#name ⇒ String
readonly
Returns the skill name.
-
#path ⇒ String
readonly
Returns the skill directory.
-
#tools ⇒ Array<Class<LLM::Tool>>
readonly
Returns the skill tools.
Class Method Summary collapse
-
.load(path) ⇒ LLM::Skill
Load a skill from a directory.
Instance Method Summary collapse
-
#call(ctx) ⇒ Hash
Execute the skill by wrapping it in a small agent with the skill instructions.
- #initialize(path) ⇒ LLM::Skill constructor
-
#load! ⇒ LLM::Skill
Load and parse the skill.
-
#to_tool(ctx) ⇒ Class<LLM::Tool>
Expose the skill as a normal LLM::Tool.
Constructor Details
#initialize(path) ⇒ LLM::Skill
52 53 54 55 56 57 58 59 |
# File 'lib/llm/skill.rb', line 52 def initialize(path) @path = path.to_s @name = ::File.basename(@path) @description = "Skill: #{@name}" @instructions = "" @frontmatter = LLM::Object.from({}) @tools = [] end |
Instance Attribute Details
#description ⇒ String (readonly)
Returns the skill description.
31 32 33 |
# File 'lib/llm/skill.rb', line 31 def description @description end |
#frontmatter ⇒ LLM::Object (readonly)
Returns the skill frontmatter.
41 42 43 |
# File 'lib/llm/skill.rb', line 41 def frontmatter @frontmatter end |
#instructions ⇒ String (readonly)
Returns the skill instructions.
36 37 38 |
# File 'lib/llm/skill.rb', line 36 def instructions @instructions end |
#name ⇒ String (readonly)
Returns the skill name.
26 27 28 |
# File 'lib/llm/skill.rb', line 26 def name @name end |
#path ⇒ String (readonly)
Returns the skill directory.
21 22 23 |
# File 'lib/llm/skill.rb', line 21 def path @path end |
#tools ⇒ Array<Class<LLM::Tool>> (readonly)
Returns the skill tools.
46 47 48 |
# File 'lib/llm/skill.rb', line 46 def tools @tools end |
Class Method Details
.load(path) ⇒ LLM::Skill
Load a skill from a directory.
14 15 16 |
# File 'lib/llm/skill.rb', line 14 def self.load(path) new(path).tap(&:load!) end |
Instance Method Details
#call(ctx) ⇒ Hash
Execute the skill by wrapping it in a small agent with the skill instructions. The context is bound explicitly by the caller so the nested agent can inherit context-level behavior such as streaming.
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/llm/skill.rb', line 76 def call(ctx) instructions, tools = self.instructions, self.tools params = ctx.params.merge(mode: ctx.mode).reject { [:tools, :schema].include?(_1) } agent = Class.new(LLM::Agent) do instructions(instructions) tools(*tools) end.new(ctx.llm, params) agent..concat((ctx)) res = agent.talk("Solve the user's query.") {content: res.content} end |
#load! ⇒ LLM::Skill
Load and parse the skill.
64 65 66 67 68 |
# File 'lib/llm/skill.rb', line 64 def load! path = ::File.join(@path, "SKILL.md") parse(::File.read(path)) self end |
#to_tool(ctx) ⇒ Class<LLM::Tool>
Expose the skill as a normal LLM::Tool. The context is bound explicitly when the tool class is built.
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/llm/skill.rb', line 93 def to_tool(ctx) skill = self Class.new(LLM::Tool) do name skill.name description skill.description define_method(:call) do skill.call(ctx) end end end |