Jido. Tools. ActionPlan behaviour
(Jido Action v2.3.0)
View Source
A behavior and macro for creating actions that execute Jido Plans.
Provides a standardized way to create actions that build and execute plans with configurable plan building and result transformation.
Usage
defmodule MyWorkflowAction do
use Jido.Tools.ActionPlan,
name: "my_workflow",
description: "Executes a multi-step workflow"
@impl Jido.Tools.ActionPlan
def build(params, context) do
Plan.new(context: context)
|> Plan.add(:fetch, MyApp.FetchAction, params)
|> Plan.add(:validate, MyApp.ValidateAction, depends_on: :fetch)
|> Plan.add(:save, MyApp.SaveAction, depends_on: :validate)
end
@impl Jido.Tools.ActionPlan
def transform_result(result) do
# Optional: Transform the execution result
{:ok, %{workflow_result: result}}
end
endCallbacks
build/2(required) - Build the Plan struct from params and contexttransform_result/1(optional) - Transform the execution result
Summary
Callbacks
Required callback for building a Plan struct.
Optional callback for transforming the execution result.
Functions
Macro for setting up a module as an ActionPlan with plan execution capabilities.
Callbacks
@callback build(params :: map(), context :: map()) :: Jido.Plan.t()
Required callback for building a Plan struct.
Takes the action parameters and context and returns a Plan struct that will be executed.
@callback transform_result(map()) :: {:ok, map()} | {:error, Exception.t() | term()}
Optional callback for transforming the execution result.
Takes the plan execution result and returns a transformed result.