# `Jidoka.Workflow`
[🔗](https://github.com/agentjido/jidoka/blob/v0.9.0/lib/jidoka/workflow.ex#L1)

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.

# `definition`

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

# `description`
*optional* 

```elixir
@callback description() :: String.t() | nil
```

Returns the optional description shown to the model.

# `id`

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

Returns the stable workflow identifier.

# `parameters_schema`
*optional* 

```elixir
@callback parameters_schema() :: map() | nil
```

Returns the optional JSON-compatible input schema.

# `run`

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

Runs a callback workflow with normalized input and runtime context.

# `__using__`
*macro* 

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

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

Returns the normalized workflow definition for a workflow module.

# `definition!`

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

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

# `resume`

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

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

---

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