Jidoka.Workflow behaviour (Jidoka v0.9.0)

Copy Markdown View Source

Deterministic workflow contract and DSL for Jidoka.

Workflows are application-owned deterministic processes exposed to an agent as one model-callable operation. Callback workflows implement run/2 directly. Declarative workflows use workflow do, steps do, and output and execute through a Runic workflow.

Summary

Callbacks

Returns the optional description shown to the model.

Returns the stable workflow identifier.

Returns the optional JSON-compatible input schema.

Runs a callback workflow with normalized input and runtime context.

Functions

Defines a deterministic workflow.

Returns the normalized workflow definition for a workflow module.

Returns a workflow definition or raises when the workflow module is invalid.

Resumes a declarative workflow from a serialized or decoded snapshot.

Runs a workflow with normalized map input.

Types

definition()

@type definition() :: Jidoka.Workflow.Spec.t()

Callbacks

description()

(optional)
@callback description() :: String.t() | nil

Returns the optional description shown to the model.

id()

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

Returns the stable workflow identifier.

parameters_schema()

(optional)
@callback parameters_schema() :: map() | nil

Returns the optional JSON-compatible input schema.

run(input, context)

@callback run(input :: map(), context :: map()) ::
  {:ok, term()} | {:error, term()} | term()

Runs a callback workflow with normalized input and runtime context.

Functions

__using__(opts \\ [])

(macro)
@spec __using__(keyword()) :: Macro.t()

Defines a deterministic workflow.

Use callback form for a simple opaque operation:

use Jidoka.Workflow, id: :my_workflow

def run(input, context), do: {:ok, %{input: input, context: context}}

Use DSL form for a validated multi-step workflow:

use Jidoka.Workflow

workflow do
  id :my_workflow
  input Zoi.object(%{value: Zoi.integer()})
end

steps do
  function :double, {MyApp.Fns, :double, 2}, input: %{value: input(:value)}
end

output from(:double)

definition(workflow_module)

@spec definition(module()) :: {:ok, definition()} | {:error, term()}

Returns the normalized workflow definition for a workflow module.

definition!(workflow_module)

@spec definition!(module()) :: definition()

Returns a workflow definition or raises when the workflow module is invalid.

resume(snapshot, opts \\ [])

@spec resume(
  Jidoka.Workflow.Snapshot.t() | binary(),
  keyword()
) ::
  {:ok, term()} | {:hibernate, Jidoka.Workflow.Snapshot.t()} | {:error, term()}

Resumes a declarative workflow from a serialized or decoded snapshot.

run(workflow_module, input, opts \\ [])

@spec run(module(), map() | keyword(), keyword()) ::
  {:ok, term()} | {:hibernate, Jidoka.Workflow.Snapshot.t()} | {:error, term()}

Runs a workflow with normalized map input.

Options:

  • :context - runtime context passed to workflow functions, actions, and agent steps.
  • :timeout - total workflow wall-clock timeout in milliseconds.
  • :async - when true, independent workflow steps may execute concurrently.
  • :max_concurrency - maximum concurrent workflow steps when :async is enabled.
  • :agent_opts - options forwarded to nested agent steps.