Class: SwarmMemory::Tools::LoadSkill
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- SwarmMemory::Tools::LoadSkill
- Defined in:
- lib/swarm_memory/tools/load_skill.rb
Overview
Tool for loading skills from memory and dynamically swapping agent tools
LoadSkill reads a skill from memory, validates it, and swaps the agent's mutable tools to match the skill's requirements. Immutable tools (Memory*, Think, LoadSkill) are always preserved.
Skills must:
- Be stored in the skill/ hierarchy
- Have type: 'skill' in metadata
- Include tools array in metadata (optional)
- Include permissions hash in metadata (optional)
Instance Method Summary collapse
-
#execute(file_path:) ⇒ String
Execute the tool.
-
#initialize(storage:, agent_name:, chat:, tool_configurator:, agent_definition:) ⇒ LoadSkill
constructor
Initialize with all context needed for tool swapping.
-
#name ⇒ Object
Override name to return simple "LoadSkill".
Constructor Details
#initialize(storage:, agent_name:, chat:, tool_configurator:, agent_definition:) ⇒ LoadSkill
Initialize with all context needed for tool swapping
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/swarm_memory/tools/load_skill.rb', line 137 def initialize(storage:, agent_name:, chat:, tool_configurator:, agent_definition:) super() @storage = storage @agent_name = agent_name @chat = chat @tool_configurator = tool_configurator @agent_definition = agent_definition # Mark memory tools and LoadSkill as immutable # This ensures they won't be removed during skill swapping @chat.mark_tools_immutable( "MemoryWrite", "MemoryRead", "MemoryEdit", "MemoryDelete", "MemoryGlob", "MemoryGrep", "MemoryDefrag", "LoadSkill", ) end |
Instance Method Details
#execute(file_path:) ⇒ String
Execute the tool
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/swarm_memory/tools/load_skill.rb', line 168 def execute(file_path:) # 1. Validate path starts with skill/ unless file_path.start_with?("skill/") return validation_error("Skills must be stored in skill/ hierarchy. Got: #{file_path}") end # 2. Read entry with metadata begin entry = @storage.read_entry(file_path: file_path) rescue ArgumentError => e return validation_error(e.) end # 3. Validate it's a skill unless entry. && entry.["type"] == "skill" type = entry.&.dig("type") || "none" return validation_error("memory://#{file_path} is not a skill (type: #{type})") end # 4. Extract tool requirements required_tools = entry.["tools"] = entry.["permissions"] || {} # 5. Validate and swap tools (only if tools are specified) if required_tools && !required_tools.empty? begin swap_tools(required_tools, ) rescue ArgumentError => e return validation_error(e.) end end # If no tools specified (nil or []), keep current tools (no swap) # 6. Mark skill as loaded @chat.mark_skill_loaded(file_path) # 7. Return content with confirmation message title = entry.title || "Untitled Skill" result = "Loaded skill: #{title}\n\n" result += format_with_line_numbers(entry.content) # 8. Add system reminder if tools were swapped if required_tools && !required_tools.empty? result += "\n\n" result += build_toolset_update_reminder(required_tools) end result end |
#name ⇒ Object
Override name to return simple "LoadSkill"
160 161 162 |
# File 'lib/swarm_memory/tools/load_skill.rb', line 160 def name "LoadSkill" end |