Programmatic Workflow Creation Example
This example demonstrates how to create a workflow programmatically using the Fluxor API.
Overview
The example creates a workflow with a structure similar to the following YAML:
stage:
plan:
action: llm:plan
input:
query: ${query}
context: ${context}
model: ${model}
tools: ${sequence}
post:
plan: ${plan}
exec:
action: tool:executePlan
input:
plan: ${plan}
model: ${model}
post:
'results[]': ${results}
decide:
action: llm:plan
input:
query: ${query}
context: ${context}
results: ${results}
model: ${model}
tools: ${sequence}
post:
plan: ${plan}
goto:
when: ${len(plan) > 0}
task: exec
finish:
action: llm:finalize
input:
query: ${query}
context: ${context}
results: ${results}
model: ${model}
post:
answer: ${answer}
Usage
The example demonstrates how to:
- Create a new workflow using
model.NewWorkflow()
- Add tasks to the workflow using
workflow.NewTask()
- Add subtasks to tasks using
task.AddSubTask()
- Configure tasks with actions using
task.WithAction()
- Add post-execution parameters using
task.WithPost()
- Add transitions between tasks using
task.WithGoto()
Running the Example
To run the example:
cd examples/workflow
go run main.go
This will output the JSON representation of the created workflow.
API Reference
Creating a Workflow
// Create a new workflow
workflow := model.NewWorkflow("workflowName")
Adding Tasks
// Add a top-level task
task := workflow.NewTask("taskName")
// Add a subtask
subtask := task.AddSubTask("subtaskName")
Configuring Tasks
// Add an action
task.WithAction("service", "method", inputMap)
// Add initialization parameters
task.WithInit("paramName", paramValue)
// Add post-execution parameters
task.WithPost("paramName", paramValue)
// Add a transition
task.WithGoto("condition", "targetTaskName")
// Set task to run asynchronously
task.WithAsync(true)
// Set auto-pause flag
task.WithAutoPause(true)
Configuring Workflows
// Add a description
workflow.WithDescription("description")
// Add a version
workflow.WithVersion("1.0.0")
// Add initialization parameters
workflow.WithInit("paramName", paramValue)
// Add post-execution parameters
workflow.WithPost("paramName", paramValue)
// Add configuration parameters
workflow.WithConfig("key", value)