Class: Ask::Agent::Policies::ApprovalPolicy
- Inherits:
-
Object
- Object
- Ask::Agent::Policies::ApprovalPolicy
- Defined in:
- lib/ask/agent/policies/approval_policy.rb
Overview
Approval policy hook: classifies tool calls as approval-required and routes them into an ApprovalQueue.
Wire it as a before_tool hook on a Session (or enable it with
Session.new(approval: true)), and any tool whose class declares
approval_required true — or whose name matches the policy's
rule-based lists — is queued for human approval instead of executed.
The agent receives a pending result and continues; the tool runs only
after a human approves it.
Instance Method Summary collapse
-
#before_tool_call(tool_call, _context) ⇒ Hash
Hook entry point — matches the
before_toolhook signature. -
#initialize(queue:, require_approval: nil, rules: nil, tools: nil) ⇒ ApprovalPolicy
constructor
A new instance of ApprovalPolicy.
Constructor Details
#initialize(queue:, require_approval: nil, rules: nil, tools: nil) ⇒ ApprovalPolicy
Returns a new instance of ApprovalPolicy.
43 44 45 46 47 48 |
# File 'lib/ask/agent/policies/approval_policy.rb', line 43 def initialize(queue:, require_approval: nil, rules: nil, tools: nil) @queue = queue @require_approval = require_approval @rules = rules @tools = Array(tools) end |
Instance Method Details
#before_tool_call(tool_call, _context) ⇒ Hash
Hook entry point — matches the before_tool hook signature.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ask/agent/policies/approval_policy.rb', line 57 def before_tool_call(tool_call, _context) case @rules&.classify(tool_call.name, tool_call.arguments) when :deny return { action: :block, reason: "Denied by permission rules: '#{tool_call.name}'" } when :allow return { action: :proceed } when :ask return queue_for_approval(tool_call, auto_approvable: false) end return { action: :proceed } unless approval_required?(tool_call.name) queue_for_approval(tool_call, auto_approvable: tool_auto_approvable?(tool_call.name)) end |