Class: Agentic::CapabilitySpecification

Inherits:
Object
  • Object
show all
Defined in:
lib/agentic/capability_specification.rb

Overview

Defines the specification for an agent capability

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, description:, version:, inputs: {}, outputs: {}, dependencies: []) ⇒ CapabilitySpecification

Initialize a new capability specification

Parameters:

  • name (String)

    The name of the capability

  • description (String)

    Description of the capability

  • version (String)

    The version of the capability

  • inputs (Hash) (defaults to: {})

    The required inputs for the capability

  • outputs (Hash) (defaults to: {})

    The expected outputs from the capability

  • dependencies (Array<Hash>) (defaults to: [])

    The dependencies of the capability



21
22
23
24
25
26
27
28
# File 'lib/agentic/capability_specification.rb', line 21

def initialize(name:, description:, version:, inputs: {}, outputs: {}, dependencies: [])
  @name = name
  @description = description
  @version = version
  @inputs = inputs
  @outputs = outputs
  @dependencies = dependencies
end

Instance Attribute Details

#dependenciesArray<Hash> (readonly)

The dependencies of the capability

Returns:

  • (Array<Hash>)

    the current value of dependencies



11
12
13
# File 'lib/agentic/capability_specification.rb', line 11

def dependencies
  @dependencies
end

#descriptionString (readonly)

Description of the capability

Returns:

  • (String)

    the current value of description



11
12
13
# File 'lib/agentic/capability_specification.rb', line 11

def description
  @description
end

#inputsHash (readonly)

The required inputs for the capability

Returns:

  • (Hash)

    the current value of inputs



11
12
13
# File 'lib/agentic/capability_specification.rb', line 11

def inputs
  @inputs
end

#nameString (readonly)

The name of the capability

Returns:

  • (String)

    the current value of name



11
12
13
# File 'lib/agentic/capability_specification.rb', line 11

def name
  @name
end

#outputsHash (readonly)

The expected outputs from the capability

Returns:

  • (Hash)

    the current value of outputs



11
12
13
# File 'lib/agentic/capability_specification.rb', line 11

def outputs
  @outputs
end

#versionString (readonly)

The version of the capability

Returns:

  • (String)

    the current value of version



11
12
13
# File 'lib/agentic/capability_specification.rb', line 11

def version
  @version
end

Class Method Details

.from_h(hash) ⇒ CapabilitySpecification

Create from a hash representation

Parameters:

  • hash (Hash)

    The hash representation

Returns:



72
73
74
75
76
77
78
79
80
81
# File 'lib/agentic/capability_specification.rb', line 72

def self.from_h(hash)
  new(
    name: hash[:name] || hash["name"],
    description: hash[:description] || hash["description"],
    version: hash[:version] || hash["version"],
    inputs: hash[:inputs] || hash["inputs"] || {},
    outputs: hash[:outputs] || hash["outputs"] || {},
    dependencies: hash[:dependencies] || hash["dependencies"] || []
  )
end

Instance Method Details

#compatible_with?(other) ⇒ Boolean

Check if this capability is compatible with another capability

Parameters:

Returns:

  • (Boolean)

    True if compatible



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/agentic/capability_specification.rb', line 33

def compatible_with?(other)
  return false unless other.is_a?(CapabilitySpecification)
  return false unless name == other.name

  # Compare versions using semantic versioning rules
  # For now, just check for exact match or higher minor version
  return true if version == other.version

  begin
    my_parts = version.split(".").map(&:to_i)
    other_parts = other.version.split(".").map(&:to_i)

    # Major version must match
    return false unless my_parts[0] == other_parts[0]

    # Our minor version should be >= other's minor version
    my_parts[1] >= other_parts[1]
  rescue
    # If version parsing fails, require exact match
    false
  end
end

#requirements_descriptionString

Get the capability requirements as a human-readable string

Returns:

  • (String)

    The capability requirements



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/agentic/capability_specification.rb', line 85

def requirements_description
  result = "Capability: #{name} (v#{version})\n"
  result += "Description: #{description}\n"

  unless inputs.empty?
    result += "\nInputs:\n"
    inputs.each do |name, spec|
      result += "  #{name}: #{spec[:type] || "any"}"
      result += " (required)" if spec[:required]
      result += " - #{spec[:description]}" if spec[:description]
      result += "\n"
    end
  end

  unless outputs.empty?
    result += "\nOutputs:\n"
    outputs.each do |name, spec|
      result += "  #{name}: #{spec[:type] || "any"}"
      result += " - #{spec[:description]}" if spec[:description]
      result += "\n"
    end
  end

  unless dependencies.empty?
    result += "\nDependencies:\n"
    dependencies.each do |dep|
      result += "  #{dep[:name]} (v#{dep[:version] || "any"})\n"
    end
  end

  result
end

#to_hHash

Convert to a hash representation

Returns:

  • (Hash)

    The hash representation



58
59
60
61
62
63
64
65
66
67
# File 'lib/agentic/capability_specification.rb', line 58

def to_h
  {
    name: @name,
    description: @description,
    version: @version,
    inputs: @inputs,
    outputs: @outputs,
    dependencies: @dependencies
  }
end