Agentic.Strategy behaviour (agentic v0.2.2)

Copy Markdown

Behaviour for orchestration strategies.

A strategy controls how the agent loop runs: it can modify opts before each run, decide whether to re-run, react to events, and contribute telemetry tags.

Callbacks

CallbackWhenPurpose
init/1Before first runStrategy-specific setup
prepare_run/2Before each Agentic.runModify profile, mode, system prompt, etc.
handle_result/3After each run completesDecide: done, rerun, or record
telemetry_tags/0In telemetry eventsStrategy-specific dimensions

Summary

Types

ctx()

@type ctx() :: Agentic.Loop.Context.t()

opts()

@type opts() :: keyword()

state()

@type state() :: term()

Callbacks

description()

@callback description() :: String.t()

display_name()

@callback display_name() :: String.t()

handle_result(result, opts, state)

@callback handle_result(
  result :: {:ok, map()} | {:error, term()},
  opts :: keyword(),
  state :: state()
) ::
  {:ok, new_state :: state()}
  | {:rerun, new_opts :: keyword(), new_state :: state()}
  | {:done, final_result :: map(), new_state :: state()}
  | {:error, term()}

id()

@callback id() :: atom()

init(opts)

@callback init(opts :: keyword()) :: {:ok, state()} | {:error, term()}

prepare_run(opts, state)

@callback prepare_run(opts :: keyword(), state :: state()) ::
  {:ok, prepared_opts :: keyword(), new_state :: state()} | {:error, term()}

telemetry_tags()

(optional)
@callback telemetry_tags() :: [{atom(), term()}]