Class: A2A::Types::AgentSkill

Inherits:
BaseModel show all
Defined in:
lib/a2a/types/agent_card.rb

Overview

Represents an agent skill

Skills define specific capabilities that an agent can perform, including supported input/output modes and security requirements.

Examples:

Creating a skill

skill = A2A::Types::AgentSkill.new(
  id: "text_analysis",
  name: "Text Analysis",
  description: "Analyze and process text content",
  tags: ["nlp", "analysis"],
  examples: [
    {
      input: "Analyze this text",
      output: "Analysis results..."
    }
  ],
  input_modes: ["text"],
  output_modes: ["text", "data"],
  security: ["api_key"]
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#==, #camelize, from_h, from_json, #hash, #to_h, #to_json, underscore, #valid?, #validate_array_type, #validate_inclusion, #validate_required, #validate_type

Constructor Details

#initialize(id:, name:, description:, tags: nil, examples: nil, input_modes: nil, output_modes: nil, security: nil) ⇒ AgentSkill

Initialize a new agent skill

Parameters:

  • Skill identifier (required)

  • Skill name (required)

  • Skill description (required)

  • (defaults to: nil)

    Skill tags for categorization

  • (defaults to: nil)

    Usage examples with input/output

  • (defaults to: nil)

    Supported input modes (text, file, data)

  • (defaults to: nil)

    Supported output modes (text, file, data)

  • (defaults to: nil)

    Security requirements for this skill



220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/a2a/types/agent_card.rb', line 220

def initialize(id:, name:, description:, tags: nil, examples: nil,
               input_modes: nil, output_modes: nil, security: nil)
  @id = id
  @name = name
  @description = description
  @tags = tags
  @examples = examples
  @input_modes = input_modes
  @output_modes = output_modes
  @security = security

  validate!
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



207
208
209
# File 'lib/a2a/types/agent_card.rb', line 207

def description
  @description
end

#examplesObject (readonly)

Returns the value of attribute examples.



207
208
209
# File 'lib/a2a/types/agent_card.rb', line 207

def examples
  @examples
end

#idObject (readonly)

Returns the value of attribute id.



207
208
209
# File 'lib/a2a/types/agent_card.rb', line 207

def id
  @id
end

#input_modesObject (readonly)

Returns the value of attribute input_modes.



207
208
209
# File 'lib/a2a/types/agent_card.rb', line 207

def input_modes
  @input_modes
end

#nameObject (readonly)

Returns the value of attribute name.



207
208
209
# File 'lib/a2a/types/agent_card.rb', line 207

def name
  @name
end

#output_modesObject (readonly)

Returns the value of attribute output_modes.



207
208
209
# File 'lib/a2a/types/agent_card.rb', line 207

def output_modes
  @output_modes
end

#securityObject (readonly)

Returns the value of attribute security.



207
208
209
# File 'lib/a2a/types/agent_card.rb', line 207

def security
  @security
end

#tagsObject (readonly)

Returns the value of attribute tags.



207
208
209
# File 'lib/a2a/types/agent_card.rb', line 207

def tags
  @tags
end

Instance Method Details

#requires_security?(requirement) ⇒ Boolean

Check if the skill has a specific security requirement

Parameters:

  • The security requirement to check

Returns:

  • True if required



261
262
263
264
265
# File 'lib/a2a/types/agent_card.rb', line 261

def requires_security?(requirement)
  return false if @security.nil?

  @security.include?(requirement)
end

#supports_input_mode?(mode) ⇒ Boolean

Check if the skill supports a specific input mode

Parameters:

  • The input mode to check

Returns:

  • True if supported



239
240
241
242
243
# File 'lib/a2a/types/agent_card.rb', line 239

def supports_input_mode?(mode)
  return true if @input_modes.nil? # nil means all modes supported

  @input_modes.include?(mode)
end

#supports_output_mode?(mode) ⇒ Boolean

Check if the skill supports a specific output mode

Parameters:

  • The output mode to check

Returns:

  • True if supported



250
251
252
253
254
# File 'lib/a2a/types/agent_card.rb', line 250

def supports_output_mode?(mode)
  return true if @output_modes.nil? # nil means all modes supported

  @output_modes.include?(mode)
end

#validate!Object (private)



269
270
271
272
273
274
275
276
277
278
279
# File 'lib/a2a/types/agent_card.rb', line 269

def validate!
  validate_required(:id, :name, :description)
  validate_type(:id, String)
  validate_type(:name, String)
  validate_type(:description, String)
  validate_array_type(:tags, String) if @tags
  validate_array_type(:input_modes, String) if @input_modes
  validate_array_type(:output_modes, String) if @output_modes
  validate_array_type(:security, String) if @security
  validate_examples if @examples
end

#validate_examplesObject (private)

Validate examples structure



283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/a2a/types/agent_card.rb', line 283

def validate_examples
  validate_type(:examples, Array)
  @examples.each_with_index do |example, index|
    raise ArgumentError, "examples[#{index}] must be a Hash" unless example.is_a?(Hash)

    # Examples should have at least input or description
    unless example.key?(:input) || example.key?("input") ||
           example.key?(:description) || example.key?("description")
      raise ArgumentError, "examples[#{index}] must have input or description"
    end
  end
end