Class: PromptObjects::Universal::CreateCapability
- Inherits:
-
Primitive
- Object
- Capability
- Primitive
- PromptObjects::Universal::CreateCapability
- Defined in:
- lib/prompt_objects/universal/create_capability.rb
Overview
Universal capability to create new capabilities at runtime. Can create both prompt objects (markdown) and primitives (Ruby code). This enables self-modification - the system can create new specialists and tools.
Instance Attribute Summary
Attributes inherited from Capability
Instance Method Summary collapse
Methods inherited from Primitive
Methods inherited from Capability
#descriptor, execution_policy, execution_policy_definition, #execution_policy_definition, #execution_policy_signature, #initialize, #resolved_execution_policy
Constructor Details
This class inherits a constructor from PromptObjects::Primitive
Instance Method Details
#description ⇒ Object
15 16 17 18 19 |
# File 'lib/prompt_objects/universal/create_capability.rb', line 15 def description "Create a new capability. Use type='prompt_object' for LLM-backed specialists, or type='primitive' for deterministic Ruby tools. " \ "For prompt objects, capabilities are the exact callable tools/delegates the new object receives; an informational delegate " \ "does not grant access to that delegate's tools." end |
#name ⇒ Object
11 12 13 |
# File 'lib/prompt_objects/universal/create_capability.rb', line 11 def name "create_capability" end |
#parameters ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/prompt_objects/universal/create_capability.rb', line 21 def parameters { type: "object", properties: { type: { type: "string", enum: ["prompt_object", "primitive"], description: "Type of capability: 'prompt_object' for LLM specialists, 'primitive' for Ruby tools" }, name: { type: "string", description: "Name for the capability (lowercase, underscores allowed)" }, description: { type: "string", description: "Brief description of what this capability does" }, # For prompt_objects: capabilities: { type: "array", items: { type: "string" }, description: "(prompt_object only) Exact tools and delegates this PO may call. Grant direct action tools for every action it must perform; do not use a related PO as a proxy for tools it does not expose." }, identity: { type: "string", description: "(prompt_object only) Who is this prompt object? Their personality and role." }, behavior: { type: "string", description: "(prompt_object only) How should this prompt object behave?" }, # For primitives: parameters_schema: { type: "object", description: "(primitive only) JSON Schema for the parameters this primitive accepts" }, ruby_code: { type: "string", description: "(primitive only) Ruby code for the receive method body. Has access to 'message' (Hash) and 'context'." } }, required: ["type", "name", "description"] } end |
#receive(message, context:) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/prompt_objects/universal/create_capability.rb', line 66 def receive(, context:) type = [:type] || ["type"] cap_name = [:name] || ["name"] # Validate name unless cap_name && cap_name.match?(/\A[a-z][a-z0-9_]*\z/) return "Error: Name must be lowercase letters, numbers, and underscores, starting with a letter." end # Check if already exists if context.env.registry.exists?(cap_name) return "Error: A capability named '#{cap_name}' already exists." end result = case type when "prompt_object" create_prompt_object(, context) when "primitive" create_primitive(, context) else return "Error: type must be 'prompt_object' or 'primitive'" end # If creation succeeded, add the new capability to the creating PO if result && !result.start_with?("Error:") added_msg = add_to_creator(cap_name, context) result = "#{result} #{added_msg}" if added_msg end result end |