Class: OllamaAgent::Runtime::ApprovalGate
- Inherits:
-
Object
- Object
- OllamaAgent::Runtime::ApprovalGate
- Defined in:
- lib/ollama_agent/runtime/approval_gate.rb
Overview
Governs whether a tool call or action requires explicit user approval.
Policy precedence (highest to lowest):
1. auto_approve: true — approve everything silently
2. Tool's requires_approval flag
3. Registered per-tool overrides
4. Risk-level threshold
Constant Summary collapse
- RISK_ORDER =
{ low: 0, medium: 1, high: 2, critical: 3 }.freeze
Instance Attribute Summary collapse
-
#last_decision ⇒ Object
readonly
Record a decision (useful for tests / audit).
Instance Method Summary collapse
-
#approved?(tool_name, args: {}, risk_level: :low, approval_required: false) ⇒ Boolean
Decide whether this tool call is approved.
-
#initialize(auto_approve: false, risk_threshold: :medium, tool_overrides: {}, stdin: $stdin, stdout: $stdout) ⇒ ApprovalGate
constructor
A new instance of ApprovalGate.
Constructor Details
#initialize(auto_approve: false, risk_threshold: :medium, tool_overrides: {}, stdin: $stdin, stdout: $stdout) ⇒ ApprovalGate
Returns a new instance of ApprovalGate.
20 21 22 23 24 25 26 27 |
# File 'lib/ollama_agent/runtime/approval_gate.rb', line 20 def initialize(auto_approve: false, risk_threshold: :medium, tool_overrides: {}, stdin: $stdin, stdout: $stdout) @auto_approve = auto_approve @risk_threshold = risk_threshold.to_sym @tool_overrides = tool_overrides.transform_keys(&:to_s) @stdin = stdin @stdout = stdout end |
Instance Attribute Details
#last_decision ⇒ Object (readonly)
Record a decision (useful for tests / audit).
44 45 46 |
# File 'lib/ollama_agent/runtime/approval_gate.rb', line 44 def last_decision @last_decision end |
Instance Method Details
#approved?(tool_name, args: {}, risk_level: :low, approval_required: false) ⇒ Boolean
Decide whether this tool call is approved.
35 36 37 38 39 40 41 |
# File 'lib/ollama_agent/runtime/approval_gate.rb', line 35 def approved?(tool_name, args: {}, risk_level: :low, approval_required: false) return true if @auto_approve return @tool_overrides[tool_name.to_s] if @tool_overrides.key?(tool_name.to_s) return true unless needs_gate?(risk_level, approval_required) prompt_user(tool_name, args, risk_level) end |