The chain package provides a flexible framework for building and executing sequential workflows of actions. It allows you to define a series of steps, each represented by an Action, which processes inputs and produces outputs. The package supports conditional branching, customizable execution paths, and error handling, enabling complex workflows with minimal boilerplate.
-
Action and Workflow Composition
Create modular, reusable units of work (Action) and orchestrate them into robust workflows usingWorkflow. -
DAG-based Execution Plans
Ensure predictable execution and robust validation with built-in cycle detection to enforce acyclic workflows. -
Nested Workflows
Use Workflows as actions within other Workflows, enabling modular and hierarchical workflow designs. -
Conditional Branching
Support forSuccess,Failure,Abortand custom direction-based branching within your execution flows. -
AggregateAction Support
Simplify the orchestration of complex workflows by combiningActions orWorkflows of different types into a unified control flow using AggregateAction.
To install the chain package, use the following command:
go get github.com/JSYoo5B/chainAn Action represents a single task in the Workflow. Each action can process input data and return output or an error.
type Action[T any] interface {
Name() string
Run(ctx context.Context, input T) (output T, err error)
}A BranchAction extends Action and supports conditional branching. It can change the execution flow based on the results of the action, allowing for multiple execution paths.
type BranchAction[T any] interface {
Name() string
Run(ctx context.Context, input T) (output T, err error)
Directions() []string
NextDirection(ctx context.Context, output T) (direction string, err error)
}A Workflow is a sequence of Actions executed in order. It orchestrates the flow of data between actions and handles branching, success, error, and abort conditions.
An ActionPlan is a map that associates a direction (e.g., success, error, abort) with the next Action to execute, defining the flow of a Workflow.
type ActionPlan[T any] map[string]Action[T]Practical examples for using the chain package will be added in future updates. Stay tuned!