SkillKit.Scope protocol (SkillKit v0.1.0)

Copy Markdown View Source

Protocol for structured scope resolution in SkillKit.

Scopes carry authorization permissions and resolve named variables for skill template substitution and handler context injection.

Implementation

Define a struct and implement the protocol:

defmodule MyApp.Scope do
  defstruct [:user, permissions: []]
end

defimpl SkillKit.Scope, for: MyApp.Scope do
  def permissions(scope), do: scope.permissions

  def resolve(scope, "USERNAME", _context), do: {:ok, scope.user}
  def resolve(_scope, _key, _context), do: :error
end

Pass the scope at agent start:

SkillKit.start_agent("agents/my-agent", scope: %MyApp.Scope{user: "alice"})

Summary

Types

t()

All the types that implement this protocol.

Functions

Returns the list of permission strings for authorization checks.

Resolves a named variable from the scope.

Types

resolve_context()

@type resolve_context() :: %{agent: String.t(), skill: String.t()}

t()

@type t() :: term()

All the types that implement this protocol.

Functions

permissions(scope)

@spec permissions(t()) :: [String.t()]

Returns the list of permission strings for authorization checks.

resolve(scope, variable_name, context)

@spec resolve(t(), String.t(), resolve_context()) :: {:ok, String.t()} | :error

Resolves a named variable from the scope.

Context provides the agent name and skill name so resolution can vary based on who is asking.

Returns {:ok, value} or :error if the variable is not known.