Class: RailsAgents::SkillSet
- Inherits:
-
Object
- Object
- RailsAgents::SkillSet
- Defined in:
- lib/rails_agents/skill_set.rb
Constant Summary collapse
- FILES_BETA =
"files-api-2025-04-14"
Instance Attribute Summary collapse
-
#custom_skills ⇒ Object
readonly
Returns the value of attribute custom_skills.
-
#declarations ⇒ Object
readonly
Returns the value of attribute declarations.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Instance Method Summary collapse
- #anthropic_document_skills? ⇒ Boolean
- #anthropic_request ⇒ Object
-
#initialize(declarations:, provider:) ⇒ SkillSet
constructor
A new instance of SkillSet.
- #portable_tool_classes ⇒ Object
- #server_tool_names ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(declarations:, provider:) ⇒ SkillSet
Returns a new instance of SkillSet.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rails_agents/skill_set.rb', line 9 def initialize(declarations:, provider:) @provider = provider.to_sym @declarations = declarations @custom_skills = [] @options_by_name = declarations.to_h { |declaration| key = declaration.custom? ? declaration.key.to_s : declaration.name.to_s [key, declaration.] } @entries = (resolve) end |
Instance Attribute Details
#custom_skills ⇒ Object (readonly)
Returns the value of attribute custom_skills.
7 8 9 |
# File 'lib/rails_agents/skill_set.rb', line 7 def custom_skills @custom_skills end |
#declarations ⇒ Object (readonly)
Returns the value of attribute declarations.
7 8 9 |
# File 'lib/rails_agents/skill_set.rb', line 7 def declarations @declarations end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
7 8 9 |
# File 'lib/rails_agents/skill_set.rb', line 7 def entries @entries end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
7 8 9 |
# File 'lib/rails_agents/skill_set.rb', line 7 def provider @provider end |
Instance Method Details
#anthropic_document_skills? ⇒ Boolean
30 31 32 |
# File 'lib/rails_agents/skill_set.rb', line 30 def anthropic_document_skills? entries.any?(&:anthropic_document?) || custom_skills.any? end |
#anthropic_request ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rails_agents/skill_set.rb', line 34 def anthropic_request return {} unless provider == :anthropic tools = entries.filter_map { |entry| anthropic_tool_for(entry) } skills = entries.filter_map { |entry| anthropic_skill_for(entry) } + custom_skills headers = anthropic_beta_headers(tools:, skills:) { server_tools: tools.uniq { |tool| tool[:name] }, container: (skills.empty? ? nil : {skills: skills}), beta_headers: headers } end |
#portable_tool_classes ⇒ Object
24 25 26 27 28 |
# File 'lib/rails_agents/skill_set.rb', line 24 def portable_tool_classes return [] unless use_portable? entries.filter_map(&:portable_tool) end |
#server_tool_names ⇒ Object
20 21 22 |
# File 'lib/rails_agents/skill_set.rb', line 20 def server_tool_names entries.select(&:server?).filter_map { |entry| entry.anthropic_tool&.dig(:name) } end |
#validate! ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rails_agents/skill_set.rb', line 48 def validate! if custom_skills.any? && provider != :anthropic raise ConfigurationError, "Custom Anthropic skills require provider :anthropic" end declarations.each do |declaration| next if declaration.custom? next if Skills::Registry.fetch(declaration.name) raise ConfigurationError, "Unknown skill: #{declaration.key}. See RailsAgents::Skills::Registry::ENTRIES" end entries.each do |entry| next if provider == :anthropic next if entry.portable_tool raise ConfigurationError, "Skill :#{entry.name} requires provider :anthropic. " \ "Portable skills: #{Skills::Registry::PORTABLE_SKILL_IDS.join(', ')}" end end |