workflow

package
v1.13.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	context.Context

	SessionID    string
	InvocationID string
	State        map[string]any
}

Context is passed to workflow nodes during graph execution.

type Edge

type Edge struct {
	From  Node
	To    Node
	Route Route
}

Edge connects two workflow nodes. A nil Route is an unconditional edge.

func Chain

func Chain(nodes ...Node) []Edge

Chain wires nodes into a sequential route.

func Concat

func Concat(groups ...[]Edge) []Edge

Concat joins multiple edge slices.

type EdgeBuilder

type EdgeBuilder struct {
	// contains filtered or unexported fields
}

EdgeBuilder provides a fluent way to assemble graph edges.

func NewEdgeBuilder

func NewEdgeBuilder() *EdgeBuilder

func (*EdgeBuilder) Add

func (b *EdgeBuilder) Add(from, to Node) *EdgeBuilder

func (*EdgeBuilder) AddFanIn

func (b *EdgeBuilder) AddFanIn(sources []Node, target Node) *EdgeBuilder

func (*EdgeBuilder) AddFanOut

func (b *EdgeBuilder) AddFanOut(from Node, targets ...Node) *EdgeBuilder

func (*EdgeBuilder) AddRoute

func (b *EdgeBuilder) AddRoute(from, to Node, route Route) *EdgeBuilder

func (*EdgeBuilder) Build

func (b *EdgeBuilder) Build() []Edge

type EmitFunc

type EmitFunc func(*Event) error

EmitFunc lets a node publish one or more explicit workflow events.

type Event

type Event struct {
	Output   any
	Message  string
	Routes   []any
	Metadata map[string]string
}

Event carries node output and optional route selections to successor edges.

type Graph

type Graph struct {
	// contains filtered or unexported fields
}

Graph executes workflow nodes according to explicit edges and routes.

func NewGraph

func NewGraph(edges []Edge, config GraphConfig) (*Graph, error)

NewGraph validates and constructs a workflow graph.

func (*Graph) Edges

func (g *Graph) Edges() []Edge

Edges returns a copy of graph edges.

func (*Graph) Run

func (g *Graph) Run(ctx context.Context, sessionID string, input any) (any, error)

Run executes the graph from START with input as the first node input.

type GraphConfig

type GraphConfig struct {
	MaxSteps    int
	JoinTimeout time.Duration
}

GraphConfig configures workflow graph execution.

type JoinFunc added in v1.13.2

type JoinFunc func(Context, map[string]any) (any, error)

JoinFunc combines the outputs of every direct predecessor of a JoinNode. The map is keyed by the predecessor node name.

type Node

type Node interface {
	Name() string
	Description() string
	// contains filtered or unexported methods
}

Node is an executable step in a workflow graph.

var Start Node = startNode{}

Start is the synthetic graph entry point used in edges and chains.

func NewAgentNode

func NewAgentNode(name string, runner SessionGenerator, config NodeConfig) Node

NewAgentNode wraps a session-aware agent as a graph node.

func NewEmittingFunctionNode

func NewEmittingFunctionNode[I, O any](name string, fn func(Context, I, EmitFunc) (O, error), config NodeConfig) Node

NewEmittingFunctionNode wraps a function that can emit explicit Events. Returning nil and emitting no events suppresses automatic output.

func NewFunctionNode

func NewFunctionNode[I, O any](name string, fn func(Context, I) (O, error), config NodeConfig) Node

NewFunctionNode wraps a plain Go function as a workflow node. The returned value is forwarded to successor nodes through Event.Output.

func NewJoinNode added in v1.13.2

func NewJoinNode(name string, fn JoinFunc, config NodeConfig) Node

NewJoinNode creates a barrier node. It runs once after every direct predecessor has produced one output for the current graph invocation. The reducer receives a map keyed by predecessor node name. A join needs at least two distinct direct predecessors; NewGraph validates that requirement.

func NewToolNode

func NewToolNode(name string, tool goagent.Tool, config NodeConfig) Node

NewToolNode wraps an agent.Tool as a graph node. Map inputs are passed as arguments; other inputs are passed as the "input" argument.

type NodeConfig

type NodeConfig struct {
	Description string
}

NodeConfig carries metadata for workflow nodes.

type Route

type Route interface {
	Match(Event) bool
	// contains filtered or unexported methods
}

Route selects successor edges based on emitted Event.Routes.

var Default Route = routeFunc{
	// contains filtered or unexported fields
}

Default matches only when no non-default route from the same node matches.

func BoolRoute

func BoolRoute(value bool) Route

BoolRoute matches an emitted bool route value.

func IntRoute

func IntRoute(value int) Route

IntRoute matches an emitted int route value.

func MultiRoute

func MultiRoute[T comparable](values ...T) Route

MultiRoute matches any emitted route value in values.

func StringRoute

func StringRoute(value string) Route

StringRoute matches an emitted string route value.

type SessionGenerator

type SessionGenerator interface {
	Generate(ctx context.Context, sessionID, input string) (any, error)
}

SessionGenerator is the minimal surface needed to wrap an agent node.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL