Class: Riffer::Skills::Context
- Inherits:
-
Object
- Object
- Riffer::Skills::Context
- Defined in:
- lib/riffer/skills/context.rb
Overview
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].
See Riffer::Skills::Backend, Riffer::Skills::Frontmatter.
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
The skill adapter used for this context.
-
#on_activate ⇒ Object
writeonly
Optional callback invoked when a skill is first activated.
-
#skills ⇒ Object
readonly
Skill catalog indexed by name.
Instance Method Summary collapse
-
#activate(name) ⇒ Object
Activates a skill by name.
-
#activated?(name) ⇒ Boolean
Returns whether a skill has been activated.
-
#initialize(backend:, skills:, adapter:) ⇒ Context
constructor
Creates a new skills context for a generation cycle.
-
#system_prompt ⇒ Object
Returns the complete skills section for the system prompt.
Constructor Details
#initialize(backend:, skills:, adapter:) ⇒ Context
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.
– : (backend: Riffer::Skills::Backend, skills: Hash[String, Riffer::Skills::Frontmatter], adapter: Riffer::Skills::Adapter) -> void
31 32 33 34 35 36 |
# File 'lib/riffer/skills/context.rb', line 31 def initialize(backend:, skills:, adapter:) @backend = backend @skills = skills @adapter = adapter @activated = {} #: Hash[String, String] end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
The skill adapter used for this context.
18 19 20 |
# File 'lib/riffer/skills/context.rb', line 18 def adapter @adapter end |
#on_activate=(value) ⇒ Object (writeonly)
Optional callback invoked when a skill is first activated.
21 22 23 |
# File 'lib/riffer/skills/context.rb', line 21 def on_activate=(value) @on_activate = value end |
#skills ⇒ Object (readonly)
Skill catalog indexed by name.
15 16 17 |
# File 'lib/riffer/skills/context.rb', line 15 def skills @skills end |
Instance Method Details
#activate(name) ⇒ Object
Activates a skill by name. Returns the cached body on re-activation.
Raises Riffer::ArgumentError if the skill is not in the catalog.
– : (String) -> String
44 45 46 47 48 49 50 |
# 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 |
#activated?(name) ⇒ Boolean
Returns whether a skill has been activated.
– : (String) -> bool
56 57 58 |
# File 'lib/riffer/skills/context.rb', line 56 def activated?(name) @activated.key?(name) end |
#system_prompt ⇒ Object
Returns the complete skills section for the system prompt.
Includes the catalog and any pre-activated skill bodies.
– : () -> String
66 67 68 69 70 71 72 |
# 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 |