class Riffer::Skills::Context
Skills context for an agent generation cycle — coordinates discovery, activation, and prompt rendering, caching skill bodies to avoid redundant backend reads. Exposed to tools via context.skills.
Attributes
The skill adapter used for this context.
Optional callback invoked when a skill is first activated.
Skill catalog indexed by name.
Public Class Methods
Source
# File lib/riffer/skills/context.rb, line 24 def initialize(backend:, skills:, adapter:) @backend = backend @skills = skills @adapter = adapter @bodies = {} #: Hash[String, String] @activated = [] #: Array[String] @preactivated = [] #: Array[String] end
Public Instance Methods
Source
# File lib/riffer/skills/context.rb, line 118 def activatable? available_skills.any? end
Returns whether any skill is available for the model to activate.
Source
# File lib/riffer/skills/context.rb, line 51 def activate(name) body = read(name) unless @activated.include?(name) @activated << name @on_activate&.call(name) end body end
Activates a skill by name. Returns the cached body on re-activation.
Raises Riffer::ArgumentError if the skill is not in the catalog.
Source
# File lib/riffer/skills/context.rb, line 101 def activated?(name) @activated.include?(name) end
Returns whether a skill has been activated.
Source
# File lib/riffer/skills/context.rb, line 67 def activation_prompt(name) body = activate(name) @adapter.render_activation(skills.fetch(name), body) end
Activates a skill and returns its body wrapped for injection as a user message.
Raises Riffer::ArgumentError if the skill is not in the catalog.
Source
# File lib/riffer/skills/context.rb, line 90 def deactivate(name) raise Riffer::ArgumentError, "Unknown skill: '#{name}'" unless skills.key?(name) @activated.delete(name) nil end
Clears a skill’s activation so the next activation is treated as the first.
Raises Riffer::ArgumentError if the skill is not in the catalog.
Source
# File lib/riffer/skills/context.rb, line 108 def model_invocable?(name) skill = skills[name] return false unless skill !skill.disable_model_invocation end
Returns whether a skill exists and may be activated by the model.
Source
# File lib/riffer/skills/context.rb, line 79 def preactivate(name) activate(name) @preactivated << name unless @preactivated.include?(name) end
Activates a skill whose body renders in the system prompt rather than the conversation.
Raises Riffer::ArgumentError if the skill is not in the catalog.
Source
# File lib/riffer/skills/context.rb, line 39 def read(name) raise Riffer::ArgumentError, "Unknown skill: '#{name}'" unless skills.key?(name) @bodies[name] ||= @backend.read_skill(name) end
Returns a skill’s body without recording an activation.
Raises Riffer::ArgumentError if the skill is not in the catalog.
Source
# File lib/riffer/skills/context.rb, line 126 def system_prompt available = available_skills parts = [] #: Array[String] parts << @adapter.render_catalog(available) unless available.empty? @preactivated.each { |name| parts << @adapter.render_activation(skills.fetch(name), @bodies.fetch(name)) } parts.join("\n\n") end
Returns the complete skills section for the system prompt — the catalog plus any pre-activated skill bodies.