SystemOneDSL.Runner (SystemOneDSL v1.0.0)

Copy Markdown View Source

Runtime evaluation, bounded concurrent batch execution, two-tier (L1 + L2) cache orchestration, and deterministic test stubbing for SystemOneDSL contract modules backed by ReqLLM.Evaluation.

Telemetry Events

SystemOneDSL.Runner emits :telemetry.span/3 events:

  • [:system_one_dsl, :evaluate, :start | :stop | :exception]

  • [:system_one_dsl, :evaluate_many, :start | :stop | :exception]

Summary

Functions

Resolves the trimmed API key from opts, application config, or environment.

Returns true if the contract module can execute evaluations — either via an injected 1-arity test function (:eval_fn or :eval_fn_key), a configured API key, a test plug in :req_http_options, or an enabled Tier-2 cache (:tier2_cache).

Builds the strict ReqLLM.Evaluation keyword option list from SystemOneDSL merged options.

Computes the deterministic SHA-256 cache key ("jev_<sha256>") using the contract module's merged options (use SystemOneDSL + otp_app config + call overrides).

Evaluates a single state map against contract_key defined in contract_mod.

Evaluates a single state map against contract_key or raises SystemOneDSL.Error.

Evaluates a list of states concurrently against contract_key using bounded Task.async_stream/3 (:max_concurrency default 10, ordered: true). Resolves L1 and L2 cache hits first and only dispatches uncached misses over the network.

Returns true if a non-empty API key is available.

Functions

api_key(opts \\ [])

@spec api_key(keyword()) :: String.t()

Resolves the trimmed API key from opts, application config, or environment.

available?(contract_mod, opts \\ [], eval_fn_key \\ :eval_fn)

@spec available?(module(), keyword(), atom()) :: boolean()

Returns true if the contract module can execute evaluations — either via an injected 1-arity test function (:eval_fn or :eval_fn_key), a configured API key, a test plug in :req_http_options, or an enabled Tier-2 cache (:tier2_cache).

build_req_llm_options(opts)

@spec build_req_llm_options(keyword()) :: keyword()

Builds the strict ReqLLM.Evaluation keyword option list from SystemOneDSL merged options.

cache_key(contract_mod, contract_key, state, opts \\ [])

@spec cache_key(module(), atom() | String.t(), term(), keyword()) :: String.t()

Computes the deterministic SHA-256 cache key ("jev_<sha256>") using the contract module's merged options (use SystemOneDSL + otp_app config + call overrides).

evaluate(contract_mod, contract_key, state, opts \\ [])

@spec evaluate(module(), atom() | String.t(), map(), keyword()) ::
  {:ok, ReqLLM.Response.t() | map()} | {:error, term()}

Evaluates a single state map against contract_key defined in contract_mod.

evaluate!(contract_mod, contract_key, state, opts \\ [])

@spec evaluate!(module(), atom() | String.t(), map(), keyword()) ::
  ReqLLM.Response.t() | map()

Evaluates a single state map against contract_key or raises SystemOneDSL.Error.

evaluate_many(contract_mod, contract_key, states, opts \\ [])

@spec evaluate_many(module(), atom() | String.t(), [map()], keyword()) :: [
  ok: ReqLLM.Response.t() | map(),
  error: term()
]

Evaluates a list of states concurrently against contract_key using bounded Task.async_stream/3 (:max_concurrency default 10, ordered: true). Resolves L1 and L2 cache hits first and only dispatches uncached misses over the network.

has_api_key?(opts \\ [])

@spec has_api_key?(keyword()) :: boolean()

Returns true if a non-empty API key is available.