# `Nous.Workflow.State`
[🔗](https://github.com/nyo16/nous/blob/v0.17.1/lib/nous/workflow/state.ex#L1)

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

| Field | Type | Description |
|-------|------|-------------|
| `data` | `map()` | User-defined workflow data |
| `node_results` | `map()` | Results keyed by node ID |
| `metadata` | `map()` | Workflow-level metadata (hooks, notify_pid, etc.) |
| `errors` | `list()` | Errors recorded during execution |
| `started_at` | `DateTime.t()` | When the workflow started |
| `updated_at` | `DateTime.t()` | Last state update |

## Examples

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

# `t`

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

# `new`

```elixir
@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`

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

Record an error for a node.

# `put_result`

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

Record a node's result in the state.

# `update_data`

```elixir
@spec update_data(t(), (map() -&gt; map())) :: t()
```

Update the user data map.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
