Class: Protege::AgentToolkit

Inherits:
ApplicationRecord show all
Defined in:
app/models/protege/agent_toolkit.rb

Overview

The grant binding one Toolkit to one Agent — and where the toolkit's permission lives. Giving a toolkit to an agent is not just "these tools are available"; it is "these tools are available to the senders I allow here". So the attachment carries the sender gate (its agent_toolkit_rules folded into a Gateway::AccessPolicy, mirroring AccessRule) and allow_proactive (whether the tools may run on this agent's scheduled, senderless runs). Two agents can attach the same toolkit and gate it differently.

Instance Method Summary collapse

Instance Method Details

#access_policyProtege::Gateway::AccessPolicy

The sender gate for this grant as a policy, folded from its rules through the Gateway factory (never constructed by hand), mirroring AccessRule.policy_for. A grant with no rules permits everyone.

Returns:



34
35
36
37
38
39
40
# File 'app/models/protege/agent_toolkit.rb', line 34

def access_policy
  grouped = agent_toolkit_rules.group_by(&:kind)
  Gateway.build_access_policy(
    allow: Array(grouped['allow']).map(&:pattern),
    deny:  Array(grouped['deny']).map(&:pattern)
  )
end

#permits?(sender:) ⇒ Boolean

Whether a sender may unlock this grant's tools, per its gate.

Parameters:

  • sender (String)

    the inbound sender's address

Returns:

  • (Boolean)

    true when the gate permits the sender



46
47
48
# File 'app/models/protege/agent_toolkit.rb', line 46

def permits?(sender:)
  access_policy.permits?(address: sender)
end