Nous.Workflow.State (nous v0.13.3)

View Source

Typed state that flows between workflow nodes.

Each node receives the state as input and returns an updated version. User data lives in data, while node_results provides access to any previous node's raw output by ID.

Fields

FieldTypeDescription
datamap()User-defined workflow data
node_resultsmap()Results keyed by node ID
metadatamap()Workflow-level metadata (hooks, notify_pid, etc.)
errorslist()Errors recorded during execution
started_atDateTime.t()When the workflow started
updated_atDateTime.t()Last state update

Examples

state = Nous.Workflow.State.new(%{query: "research topic"})
state.data.query
#=> "research topic"

Summary

Functions

Create a new workflow state from initial data.

Record an error for a node.

Record a node's result in the state.

Update the user data map.

Types

t()

@type t() :: %Nous.Workflow.State{
  data: map(),
  errors: [{String.t(), term()}],
  metadata: map(),
  node_results: %{required(String.t()) => term()},
  started_at: DateTime.t(),
  updated_at: DateTime.t()
}

Functions

new(data \\ %{})

@spec new(map()) :: t()

Create a new workflow state from initial data.

Examples

iex> state = Nous.Workflow.State.new(%{query: "test"})
iex> state.data.query
"test"
iex> state.node_results
%{}

put_error(state, node_id, error)

@spec put_error(t(), String.t(), term()) :: t()

Record an error for a node.

put_result(state, node_id, result)

@spec put_result(t(), String.t(), term()) :: t()

Record a node's result in the state.

update_data(state, fun)

@spec update_data(t(), (map() -> map())) :: t()

Update the user data map.