Class: OllamaAgent::Runtime::ApprovalGate

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(auto_approve: false, risk_threshold: :medium, tool_overrides: {}, stdin: $stdin, stdout: $stdout) ⇒ ApprovalGate

Returns a new instance of ApprovalGate.

Parameters:

  • auto_approve (Boolean) (defaults to: false)

    skip all approvals

  • risk_threshold (Symbol) (defaults to: :medium)

    auto-approve tools below this risk (:low, :medium, :high, :critical)

  • tool_overrides (Hash) (defaults to: {})

    { “tool_name” => true/false } per-tool override

  • stdin (IO) (defaults to: $stdin)
  • stdout (IO) (defaults to: $stdout)


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_decisionObject (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.

Parameters:

  • tool_name (String)
  • args (Hash) (defaults to: {})
  • risk_level (Symbol) (defaults to: :low)

    from the tool definition

  • approval_required (Boolean) (defaults to: false)

    from the tool definition

Returns:

  • (Boolean)


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