Jido.AI.Directive.Helpers (Jido AI v2.2.0)

Copy Markdown View Source

Helper functions for DirectiveExec implementations.

This module centralizes directive runtime helpers for:

  • Task supervisor resolution
  • Model resolution from directive fields
  • Message normalization/building
  • Request option assembly
  • Error classification

Summary

Functions

Adds req_http_options option to a keyword list if options are specified.

Adds timeout option to a keyword list if timeout is specified.

Adds tools option to a keyword list if tools are specified.

Builds messages for LLM calls from context and optional system prompt.

Classifies an error into a runtime category.

Gets the task supervisor from agent state.

Resolves a model from directive fields.

Functions

add_req_http_options(opts, req_http_options)

@spec add_req_http_options(
  keyword(),
  list() | nil
) :: keyword()

Adds req_http_options option to a keyword list if options are specified.

add_timeout_opt(opts, timeout)

@spec add_timeout_opt(
  keyword(),
  integer() | nil
) :: keyword()

Adds timeout option to a keyword list if timeout is specified.

add_tools_opt(opts, tools)

@spec add_tools_opt(
  keyword(),
  list()
) :: keyword()

Adds tools option to a keyword list if tools are specified.

build_directive_messages(context, system_prompt)

@spec build_directive_messages(term(), String.t() | nil) :: list()

Builds messages for LLM calls from context and optional system prompt.

classify_error(arg1)

@spec classify_error(term()) :: atom()

Classifies an error into a runtime category.

Returns one of: :rate_limit, :auth, :timeout, :provider_error, :network, :validation, :unknown.

get_task_supervisor(state)

Gets the task supervisor from agent state.

First checks the TaskSupervisorSkill's internal state (__task_supervisor_skill__), then falls back to the top-level :task_supervisor field for standalone usage.

Examples

iex> state = %{__task_supervisor_skill__: %{supervisor: supervisor_pid}}
iex> Jido.AI.Directive.Helpers.get_task_supervisor(state)
supervisor_pid

iex> state = %{task_supervisor: supervisor_pid}
iex> Jido.AI.Directive.Helpers.get_task_supervisor(state)
supervisor_pid

resolve_directive_model(arg1)

@spec resolve_directive_model(map()) :: String.t()

Resolves a model from directive fields.

Supports both direct model specification and model alias resolution.