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 during Agent.new and exposed to tools via context.skills on the agent’s Riffer::Agent::Context.
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. The adapter carries the activation tool class via its initializer.
– : (backend: Riffer::Skills::Backend, skills: Hash[String, Riffer::Skills::Frontmatter], adapter: Riffer::Skills::Adapter) -> void
35 36 37 38 39 40 |
# File 'lib/riffer/skills/context.rb', line 35 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.
21 22 23 |
# File 'lib/riffer/skills/context.rb', line 21 def adapter @adapter end |
#on_activate=(value) ⇒ Object (writeonly)
Optional callback invoked when a skill is first activated.
24 25 26 |
# File 'lib/riffer/skills/context.rb', line 24 def on_activate=(value) @on_activate = value end |
#skills ⇒ Object (readonly)
Skill catalog indexed by name.
18 19 20 |
# File 'lib/riffer/skills/context.rb', line 18 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
48 49 50 51 52 53 54 |
# File 'lib/riffer/skills/context.rb', line 48 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
60 61 62 |
# File 'lib/riffer/skills/context.rb', line 60 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
70 71 72 73 74 75 76 |
# File 'lib/riffer/skills/context.rb', line 70 def system_prompt available = available_skills parts = [] #: Array[String] parts << @adapter.render_catalog(available) unless available.empty? @activated.each_value { |body| parts << body } parts.join("\n\n") end |