Class: Riffer::Skills::Context

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#adapterObject (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

#skillsObject (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

Returns:

  • (Boolean)


60
61
62
# File 'lib/riffer/skills/context.rb', line 60

def activated?(name)
  @activated.key?(name)
end

#system_promptObject

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