Wardrik.Scope (wardrik_protocol v0.1.0-rc.6)

Copy Markdown

Who an operation runs for. Every operation takes one.

# user_42
scope = MyApp.AgentRuntime.as("user_42")

# user_42's agent, through its own tools
scope = MyApp.AgentRuntime.as("user_42", actor: {:agent, "agt_1"})

Your app's Wardrik.Authorizer decides what each scope may do.

Fields

  • :server - the Wardrik.Server that runs its operations.
  • :wardrik - which Wardrik, by name.
  • :principal - the WardrikCore.Principal it runs for.
  • :actor - {:agent, id} or {:channel, name} when one acts for the principal, or nil.
  • :context - facts for the authorizer, like a channel's :asked_by. %{} unless set.
  • :policy - in an agent's scope, the policy every agent it defines is held to.
  • :labels - in an agent's scope, the labels of what its run has read.
  • :operation - the operation running, while one runs.

Summary

Types

Who acts for the principal, as {kind, id}, or nil.

t()

Functions

Returns a scope run by server.

Runs operation id with input through the scope's server.

Streams operation id with input through the scope's server.

Types

actor()

@type actor() :: {atom(), String.t()} | nil

Who acts for the principal, as {kind, id}, or nil.

t()

@type t() :: %Wardrik.Scope{
  actor: actor(),
  context: map(),
  labels: [String.t()],
  operation: WardrikProtocol.operation() | nil,
  policy: String.t() | map() | nil,
  principal: WardrikCore.Principal.t(),
  server: module(),
  wardrik: atom() | struct()
}

Functions

new(server, args)

@spec new(module(),
  wardrik: atom() | struct(),
  principal: WardrikCore.Principal.t() | String.t(),
  actor: actor(),
  context: map()
) :: t()

Returns a scope run by server.

Wardrik.Scope.new(Wardrik,
  wardrik: MyApp.AgentRuntime,
  principal: "user_42",
  actor: {:channel, "slack"},
  context: %{asked_by: "user_7"}
)

:principal is a WardrikCore.Principal or its ID.

run(scope, id, input)

@spec run(t(), String.t(), map()) :: {:ok, term()} | {:error, Wardrik.Error.t()}

Runs operation id with input through the scope's server.

stream(scope, id, input)

@spec stream(t(), String.t(), map()) ::
  {:ok, Enumerable.t()} | {:error, Wardrik.Error.t()}

Streams operation id with input through the scope's server.