Skip to contents

Adds a predicate to this session's registry. Persisted rules refer to the predicate by id, and an installed policy pins its version. No R code is persisted: a session must register a compatible implementation before rules that use it can be satisfied. A predicate that is not registered, or that is registered with a different version than the pinned one, fails at evaluation and produces a finding.

Usage

bg_register_rule_predicate(
  id,
  fn,
  arguments = character(),
  version = "1",
  replace = FALSE,
  optional = character()
)

Arguments

id

Dotted predicate id, for example "mylab.prereg_match". Undotted ids are reserved for built-in predicates.

fn

A function fn(subject, args) returning TRUE or FALSE. subject is list(state, action, candidate, actor), where state is the research state before the action. args holds the condition's arguments.

arguments

Argument names every condition must supply, with a non-NULL value.

version

Implementation version recorded when a policy is installed.

replace

Replace an existing registration with the same id.

optional

Argument names a condition may supply.

Value

The registration, invisibly: list(id, version, arguments, optional).

Details

A host that exposes the research interface to agents must control predicate registration as well as actor identity. This is a protocol, not a sandbox.

Examples

bg_register_rule_predicate(
  "mylab.has_label",
  function(subject, args) identical(subject$action$label, args$label),
  arguments = "label"
)