Class: PromptObjects::Universal::RequestPrimitive
- Inherits:
-
Primitive
show all
- Defined in:
- lib/prompt_objects/universal/request_primitive.rb
Overview
Universal capability to request a primitive from the human.
Requests explicit approval before installing a new tool implementation.
The human can approve, modify, or reject the request.
Instance Attribute Summary
Attributes inherited from Capability
#state
Instance Method Summary
collapse
Methods inherited from Primitive
#initialize
Methods inherited from Capability
#descriptor, execution_policy, execution_policy_definition, #execution_policy_definition, #execution_policy_signature, #initialize, #resolved_execution_policy
Instance Method Details
#description ⇒ Object
13
14
15
|
# File 'lib/prompt_objects/universal/request_primitive.rb', line 13
def description
"Request a new primitive from the human. Use this when you need a tool that doesn't exist. The human can approve and create it, or reject the request."
end
|
#name ⇒ Object
9
10
11
|
# File 'lib/prompt_objects/universal/request_primitive.rb', line 9
def name
"request_primitive"
end
|
#parameters ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/prompt_objects/universal/request_primitive.rb', line 17
def parameters
{
type: "object",
properties: {
name: {
type: "string",
description: "Suggested name for the primitive (lowercase, underscores)"
},
description: {
type: "string",
description: "What this primitive should do"
},
reason: {
type: "string",
description: "Why you need this primitive"
},
suggested_code: {
type: "string",
description: "Optional: Your suggested Ruby implementation for the receive method"
},
parameters_schema: {
type: "object",
description: "Optional: Suggested JSON Schema for parameters"
}
},
required: ["name", "description", "reason"]
}
end
|
#receive(message, context:) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/prompt_objects/universal/request_primitive.rb', line 46
def receive(message, context:)
prim_name = message[:name] || message["name"]
description = message[:description] || message["description"]
reason = message[:reason] || message["reason"]
suggested_code = message[:suggested_code] || message["suggested_code"]
params_schema = message[:parameters_schema] || message["parameters_schema"]
unless prim_name && prim_name.match?(/\A[a-z][a-z0-9_]*\z/)
return "Error: Name must be lowercase letters, numbers, and underscores, starting with a letter."
end
if context.env.registry.exists?(prim_name)
return "Error: A capability named '#{prim_name}' already exists."
end
if context.tui_mode && context.human_queue
return receive_tui(prim_name, description, reason, suggested_code, params_schema, context)
end
receive_repl(prim_name, description, reason, suggested_code, params_schema, context)
end
|