Synaptic (synaptic v0.2.6)

View Source

Synaptic provides a declarative workflow engine with a DSL for orchestrating LLM-backed steps, human-in-the-loop pauses, and resumable executions.

Summary

Functions

Returns the step-level history collected for a workflow run.

Returns a snapshot of the current workflow state for a run id.

Returns a list of currently running workflows with their run ids, workflow module, and snapshot context.

Resumes a previously suspended workflow run with the supplied payload.

Starts a workflow module with the provided input context.

Stops a running workflow. Returns :ok when the runner terminates or {:error, :not_found} if the run id is unknown.

Subscribes the calling process to PubSub events for the given run_id.

Unsubscribes the calling process from workflow events for the given run_id.

Fetches the compiled workflow definition for a module.

Functions

history(run_id)

Returns the step-level history collected for a workflow run.

inspect(run_id, timeout \\ 5000)

Returns a snapshot of the current workflow state for a run id.

Options

  • :timeout - Timeout in milliseconds for the snapshot call (default: 5000). Use :infinity to wait indefinitely.

list_runs()

Returns a list of currently running workflows with their run ids, workflow module, and snapshot context.

resume(run_id, payload)

Resumes a previously suspended workflow run with the supplied payload.

start(workflow_module, input \\ %{}, opts \\ [])

Starts a workflow module with the provided input context.

Options

  • :run_id - Custom run ID (defaults to auto-generated)
  • :start_at_step - Start execution at a specific step by name (atom). The step must exist in the workflow definition. The provided context should contain all data that would have been accumulated up to that step.

Examples

# Start from the beginning (default)
{:ok, run_id} = Synaptic.start(MyWorkflow, %{initial: :data})

# Start at a specific step with pre-populated context
{:ok, run_id} = Synaptic.start(MyWorkflow, %{precomputed: :value}, start_at_step: :middle_step)

stop(run_id, reason \\ :canceled)

Stops a running workflow. Returns :ok when the runner terminates or {:error, :not_found} if the run id is unknown.

subscribe(run_id)

Subscribes the calling process to PubSub events for the given run_id.

Events are delivered as {:synaptic_event, %{run_id: ..., event: ...}} tuples.

unsubscribe(run_id)

Unsubscribes the calling process from workflow events for the given run_id.

workflow_definition(module)

Fetches the compiled workflow definition for a module.