class Riffer::Skills::Context
Skills context for an agent generation cycle.
Coordinates skill discovery, activation, and prompt rendering. Tracks activations with caching to avoid redundant backend reads.
Built by the agent at the start of generate/stream and passed 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 31 def initialize(backend:, skills:, adapter:) @backend = backend @skills = skills @adapter = adapter @activated = {} #: Hash[String, String] end
Creates a new skills context for a generation cycle.
- backend
-
the skills backend for reading skill bodies.
- skills
-
skill catalog indexed by name.
- adapter
-
the adapter used to render skill content.
Public Instance Methods
Source
# File lib/riffer/skills/context.rb, line 44 def activate(name) raise Riffer::ArgumentError, "Unknown skill: '#{name}'" unless skills.key?(name) return @activated[name] if @activated.key?(name) @activated[name] = @backend.read_skill(name) @on_activate&.call(name) @activated[name] 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 56 def activated?(name) @activated.key?(name) end
Returns whether a skill has been activated.
Source
# File lib/riffer/skills/context.rb, line 66 def system_prompt available = available_skills parts = [] parts << @adapter.render_catalog(available) unless available.empty? @activated.each_value { |body| parts << body } parts.join("\n\n") end
Returns the complete skills section for the system prompt.
Includes the catalog and any pre-activated skill bodies.