Runic.Workflow.Step (Runic v0.1.0-alpha.7)

Copy Markdown View Source

Step nodes transform input facts into output facts.

A Step receives a fact, applies its work function, and produces a new fact with the result. Steps are the primary computation nodes in a workflow.

Meta Expression Support

Steps can reference workflow state through meta expressions like state_of(:component). When a Step has meta references, the :meta_refs field is populated during macro compilation, and :meta_ref edges are drawn during Component.connect/3.

During the prepare phase, these edges are traversed to populate meta_context in the CausalContext, making the referenced state available during execution.

Runtime Context

Steps can also reference external runtime values via context/1 expressions:

step = Runic.step(fn _x -> context(:api_key) end, name: :call_llm)
step = Runic.step(fn x -> x + context(:offset) end, name: :compute)

When context/1 is detected, the step's work function is rewritten to arity-2 (input, meta_ctx) and meta_refs are populated with kind: :context entries. Values are resolved from the workflow's run_context during the prepare phase.

Summary

Functions

Returns whether this step has meta references that need to be resolved during the prepare phase.

Executes the work function of the Lambda step returning the raw unwrapped value.

Runs the step work function with meta context available.

Types

meta_ref()

@type meta_ref() :: %{
  kind: atom(),
  target: atom() | integer() | {atom(), atom()},
  field_path: [atom()],
  context_key: atom()
}

t()

@type t() :: %Runic.Workflow.Step{
  closure: Runic.Closure.t() | nil,
  hash: String.t() | nil,
  inputs: term(),
  meta_refs: [meta_ref()],
  name: String.t() | atom(),
  outputs: term(),
  work: function(),
  work_hash: String.t() | nil
}

Functions

has_meta_refs?(step)

@spec has_meta_refs?(t()) :: boolean()

Returns whether this step has meta references that need to be resolved during the prepare phase.

new(params)

run(step, input)

Executes the work function of the Lambda step returning the raw unwrapped value.

run_with_meta_context(step, input, meta_context)

@spec run_with_meta_context(t(), term(), map()) :: term()

Runs the step work function with meta context available.

When a step has meta references, its work function is arity 2, receiving (input, meta_context).