Class: Agentic::CapabilityProvider
- Inherits:
-
Object
- Object
- Agentic::CapabilityProvider
- Defined in:
- lib/agentic/capability_provider.rb
Overview
Provider for a capability implementation
Instance Attribute Summary collapse
-
#capability ⇒ CapabilitySpecification
readonly
The capability specification.
-
#implementation ⇒ Proc, Class
readonly
The implementation of the capability.
Instance Method Summary collapse
-
#execute(inputs = {}) ⇒ Hash
Execute the capability.
-
#initialize(capability:, implementation:) ⇒ CapabilityProvider
constructor
Initialize a new capability provider.
Constructor Details
#initialize(capability:, implementation:) ⇒ CapabilityProvider
Initialize a new capability provider
13 14 15 16 |
# File 'lib/agentic/capability_provider.rb', line 13 def initialize(capability:, implementation:) @capability = capability @implementation = implementation end |
Instance Attribute Details
#capability ⇒ CapabilitySpecification (readonly)
The capability specification
7 8 9 |
# File 'lib/agentic/capability_provider.rb', line 7 def capability @capability end |
#implementation ⇒ Proc, Class (readonly)
The implementation of the capability
7 8 9 |
# File 'lib/agentic/capability_provider.rb', line 7 def implementation @implementation end |
Instance Method Details
#execute(inputs = {}) ⇒ Hash
Execute the capability
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/agentic/capability_provider.rb', line 21 def execute(inputs = {}) # Validate inputs against capability specification validate_inputs!(inputs) # Execute the implementation result = case @implementation when Proc @implementation.call(inputs) when Class instance = @implementation.new instance.execute(inputs) else raise "Invalid implementation type: #{@implementation.class}" end # Validate outputs against capability specification validate_outputs!(result) result end |