Class: PromptObjects::Capability
- Inherits:
-
Object
- Object
- PromptObjects::Capability
- Defined in:
- lib/prompt_objects/capability.rb
Overview
Base class for all capabilities (both primitives and prompt objects). Everything in the system implements this interface.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#state ⇒ Object
Returns the value of attribute state.
Class Method Summary collapse
- .execution_policy(parallel_safe: false, side_effect: :exclusive, resource_keys: nil, workload: :blocking) ⇒ Object
- .execution_policy_definition ⇒ Object
Instance Method Summary collapse
-
#descriptor ⇒ Hash
Generate a tool descriptor for LLM function calling.
- #execution_policy_definition ⇒ Object
- #execution_policy_signature ⇒ Object
-
#initialize ⇒ Capability
constructor
A new instance of Capability.
-
#parameters ⇒ Hash
Define the parameters this capability accepts.
-
#receive(message, context:) ⇒ String
Handle a message and return a response.
- #resolved_execution_policy(arguments:, context:) ⇒ Object
Constructor Details
#initialize ⇒ Capability
Returns a new instance of Capability.
10 11 12 |
# File 'lib/prompt_objects/capability.rb', line 10 def initialize @state = :idle end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
7 8 9 |
# File 'lib/prompt_objects/capability.rb', line 7 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/prompt_objects/capability.rb', line 7 def name @name end |
#state ⇒ Object
Returns the value of attribute state.
8 9 10 |
# File 'lib/prompt_objects/capability.rb', line 8 def state @state end |
Class Method Details
.execution_policy(parallel_safe: false, side_effect: :exclusive, resource_keys: nil, workload: :blocking) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/prompt_objects/capability.rb', line 15 def execution_policy(parallel_safe: false, side_effect: :exclusive, resource_keys: nil, workload: :blocking) @execution_policy = Execution::Policy.new( parallel_safe: parallel_safe, side_effect: side_effect, resource_keys: resource_keys, workload: workload ) end |
.execution_policy_definition ⇒ Object
24 25 26 27 28 |
# File 'lib/prompt_objects/capability.rb', line 24 def execution_policy_definition return @execution_policy if defined?(@execution_policy) && @execution_policy superclass.respond_to?(:execution_policy_definition) ? superclass.execution_policy_definition : nil end |
Instance Method Details
#descriptor ⇒ Hash
Generate a tool descriptor for LLM function calling.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/prompt_objects/capability.rb', line 57 def descriptor { type: "function", function: { name: name, description: description, parameters: sanitize_schema(parameters) } } end |
#execution_policy_definition ⇒ Object
40 41 42 43 44 45 |
# File 'lib/prompt_objects/capability.rb', line 40 def execution_policy_definition self.class.execution_policy_definition || Execution::Policy.new( parallel_safe: false, side_effect: :exclusive ) end |
#execution_policy_signature ⇒ Object
36 37 38 |
# File 'lib/prompt_objects/capability.rb', line 36 def execution_policy_signature execution_policy_definition.signature(self) end |
#parameters ⇒ Hash
Define the parameters this capability accepts. Override in subclasses for specific parameter schemas.
93 94 95 96 97 98 99 |
# File 'lib/prompt_objects/capability.rb', line 93 def parameters { type: "object", properties: {}, required: [] } end |
#receive(message, context:) ⇒ String
Handle a message and return a response.
51 52 53 |
# File 'lib/prompt_objects/capability.rb', line 51 def receive(, context:) raise NotImplementedError, "#{self.class} must implement #receive" end |
#resolved_execution_policy(arguments:, context:) ⇒ Object
31 32 33 34 |
# File 'lib/prompt_objects/capability.rb', line 31 def resolved_execution_policy(arguments:, context:) policy = execution_policy_definition policy.resolve(arguments: arguments, context: context, capability: self) end |