Module: RobotLab::Robot::AgentSkillMatching

Included in:
RobotLab::Robot
Defined in:
lib/robot_lab/robot/agent_skill_matching.rb

Overview

Prepended module that intercepts run() to inject relevant AgentSkills.io skills into the system prompt and tool list for the duration of each call.

Owns: @_active_agent_skills, @_agent_skill_original_instructions, @_agent_skill_injected_tools Reads: @pending_agent_skills, @agent_skill_store, @local_tools, @chat, @name Contract: prepended (wraps super); requires TemplateRendering to have set @pending_agent_skills

Skills are matched by embedding similarity between the incoming message and each pending skill’s description (via DocumentStore/fastembed). Injected content is fully restored in an ensure block after run() returns.

Constant Summary collapse

SIMILARITY_THRESHOLD =
0.70

Instance Method Summary collapse

Instance Method Details

#rerender_template(run_context) ⇒ Object

Override to re-inject skill instructions after template re-render replaces the system prompt during a run() call with runtime kwargs.



28
29
30
31
32
33
34
# File 'lib/robot_lab/robot/agent_skill_matching.rb', line 28

def rerender_template(run_context)
  super
  return unless @_active_agent_skills&.any?

  @_agent_skill_original_instructions = current_agent_skill_instructions
  prepend_skill_instructions(@_active_agent_skills)
end

#run(message = nil) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/robot_lab/robot/agent_skill_matching.rb', line 18

def run(message = nil, **, &)
  matched = match_agent_skills(message.to_s)
  inject_agent_skills(matched) if matched.any?
  super
ensure
  restore_after_agent_skills if @_active_agent_skills&.any?
end