Petal Flow Getting Started
Getting Started
Section titled “Getting Started”This guide walks you through building your first Petal Flow workflow graph.
Prerequisites
Section titled “Prerequisites”- Go 1.21 or later
- A Go module initialized (
go mod init)
Installation
Section titled “Installation”go get github.com/petal-labs/petalflowYour First Workflow
Section titled “Your First Workflow”- Create a graph — Graphs are containers for nodes and edges.
- Add nodes — Nodes perform work on the envelope data.
- Set the entry point — Define where execution begins.
- Run with the runtime — Execute the graph and get results.
package main
import ( "context" "fmt" "strings"
"github.com/petal-labs/petalflow")
func main() { // Create a new graph with a name g := petalflow.NewGraph("hello")
// Create a function node that transforms input node := petalflow.NewFuncNode("greet", func(ctx context.Context, env *petalflow.Envelope) (*petalflow.Envelope, error) { name := env.GetVarString("name") env.SetVar("greeting", fmt.Sprintf("Hello, %s!", strings.ToUpper(name))) return env, nil })
// Add the node and set it as the entry point g.AddNode(node) g.SetEntry("greet")
// Create an envelope with initial data env := petalflow.NewEnvelope().WithVar("name", "world")
// Run the graph runtime := petalflow.NewRuntime() result, err := runtime.Run(context.Background(), g, env, petalflow.DefaultRunOptions()) if err != nil { fmt.Printf("Error: %v\n", err) return }
fmt.Println(result.GetVarString("greeting")) // Output: Hello, WORLD!}Next Steps
Section titled “Next Steps”- Learn the primitives in Concepts
- Add LLM nodes via Iris Integration
- Explore real workflows in Examples