Jidoka.ModelPolicy behaviour (Jidoka v0.9.0)

Copy Markdown View Source

Routes, retries, and falls back model calls at the LLM effect boundary.

Pass a policy with the model_policy: run option. A policy has an ordered model list, an optional selector, and a retry policy. The selector receives the model list and the trusted LLM context for each model call.

Model retries stay inside one LLM effect. They do not retry operation effects. The winning decision and the effect result contain an ordered :model_attempts list.

Summary

Functions

Returns the built-in failure class for a model error.

Builds a model policy from a keyword list or map.

Builds a model policy and raises if it is not valid.

Types

classifier()

@type classifier() :: (term() -> :transient | :permanent) | module() | nil

selector()

@type selector() ::
  ([LLMDB.Model.t()], Jidoka.Context.t() ->
     Jidoka.Config.model_spec()
     | [Jidoka.Config.model_spec()]
     | {:ok, term()}
     | {:error, term()})
  | module()
  | nil

t()

@type t() :: %Jidoka.ModelPolicy{
  classify: classifier(),
  models: [LLMDB.Model.t()],
  retry: Jidoka.Workflow.RetryPolicy.t(),
  select: selector(),
  sleep: (non_neg_integer() -> term())
}

Callbacks

classify(term)

(optional)
@callback classify(term()) :: :transient | :permanent

select(list, t)

(optional)
@callback select([LLMDB.Model.t()], Jidoka.Context.t()) ::
  Jidoka.Config.model_spec()
  | [Jidoka.Config.model_spec()]
  | {:ok, term()}
  | {:error, term()}

Functions

classify(reason)

@spec classify(term()) :: :transient | :permanent

Returns the built-in failure class for a model error.

new(attrs)

@spec new(keyword() | map()) :: {:ok, t()} | {:error, term()}

Builds a model policy from a keyword list or map.

new!(attrs)

@spec new!(keyword() | map()) :: t()

Builds a model policy and raises if it is not valid.