graph

package
v1.0.0-alpha.7 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command[S any] struct {
	Update    *S
	Goto      string
	Interrupt *Interrupt
	End       bool
}

func End

func End[S any]() Command[S]

func Goto

func Goto[S any](target string) Command[S]

func InterruptRun

func InterruptRun[S any](reason string, payload any) Command[S]

func Noop

func Noop[S any]() Command[S]

func Update

func Update[S any](state S) Command[S]

func UpdateAndGoto

func UpdateAndGoto[S any](state S, target string) Command[S]

type EdgeKind

type EdgeKind string
const (
	EdgeKindFixed       EdgeKind = "fixed"
	EdgeKindConditional EdgeKind = "conditional"
	EdgeKindOtherwise   EdgeKind = "otherwise"
	EdgeKindDynamic     EdgeKind = "dynamic"
)

type EdgeSnapshot

type EdgeSnapshot struct {
	From        string `json:"from"`
	To          string `json:"to"`
	Kind        string `json:"kind"`
	Label       string `json:"label,omitempty"`
	Description string `json:"description,omitempty"`
	Order       int    `json:"order,omitempty"`
	Default     bool   `json:"default,omitempty"`
}

type Interrupt

type Interrupt struct {
	ID           string
	Kind         string
	Reason       string
	Payload      any
	RunID        string
	NodeID       string
	CheckpointID string
	ResumeNode   string
}

type NodeFunc

type NodeFunc[S any] func(context.Context, S) (Command[S], error)

type NodeKind

type NodeKind string
const (
	NodeKindStep  NodeKind = "step"
	NodeKindLLM   NodeKind = "llm"
	NodeKindTool  NodeKind = "tool"
	NodeKindHuman NodeKind = "human"
)

type NodeSnapshot

type NodeSnapshot struct {
	ID       string            `json:"id"`
	Kind     string            `json:"kind"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

type NodeSpec

type NodeSpec[S any] struct {
	ID       string
	Kind     NodeKind
	Run      NodeFunc[S]
	Metadata map[string]string
}

type Predicate

type Predicate[S any] func(context.Context, S) (bool, error)

type ReachableOption

type ReachableOption func(*dynamicEdge)

func EdgeDescription

func EdgeDescription(description string) ReachableOption

func EdgeLabel

func EdgeLabel(label string) ReachableOption

type RouteBuilder

type RouteBuilder[S any] struct {
	// contains filtered or unexported fields
}

func (*RouteBuilder[S]) Otherwise

func (b *RouteBuilder[S]) Otherwise(target string) *StateGraph[S]

func (*RouteBuilder[S]) When

func (b *RouteBuilder[S]) When(predicate Predicate[S], target string) *RouteBuilder[S]

type RouteSelection

type RouteSelection struct {
	Target  string
	Kind    EdgeKind
	Order   int
	Default bool
}

type Snapshot

type Snapshot struct {
	WorkflowID string         `json:"workflow_id"`
	Start      string         `json:"start"`
	Finish     []string       `json:"finish"`
	Nodes      []NodeSnapshot `json:"nodes"`
	Edges      []EdgeSnapshot `json:"edges"`
}

type StateGraph

type StateGraph[S any] struct {
	// contains filtered or unexported fields
}

func NewStateGraph

func NewStateGraph[S any](workflowID string) *StateGraph[S]

func (*StateGraph[S]) Edge

func (g *StateGraph[S]) Edge(from string, to string) *StateGraph[S]

func (*StateGraph[S]) Finish

func (g *StateGraph[S]) Finish(ids ...string) *StateGraph[S]

func (*StateGraph[S]) FixedTargets

func (g *StateGraph[S]) FixedTargets(id string) []string

func (*StateGraph[S]) Flow

func (g *StateGraph[S]) Flow(ids ...string) *StateGraph[S]

func (*StateGraph[S]) HasNode

func (g *StateGraph[S]) HasNode(id string) bool

func (*StateGraph[S]) IsFinish

func (g *StateGraph[S]) IsFinish(id string) bool

func (*StateGraph[S]) Node

func (g *StateGraph[S]) Node(spec NodeSpec[S]) *StateGraph[S]

func (*StateGraph[S]) NodeFunc

func (g *StateGraph[S]) NodeFunc(id string) (NodeFunc[S], bool)

func (*StateGraph[S]) Reachable

func (g *StateGraph[S]) Reachable(from string, to string, opts ...ReachableOption) *StateGraph[S]

func (*StateGraph[S]) Route

func (g *StateGraph[S]) Route(from string) *RouteBuilder[S]

func (*StateGraph[S]) SelectRoute

func (g *StateGraph[S]) SelectRoute(ctx context.Context, from string, state S) (RouteSelection, bool, error)

func (*StateGraph[S]) Snapshot

func (g *StateGraph[S]) Snapshot() Snapshot

func (*StateGraph[S]) Start

func (g *StateGraph[S]) Start(id string) *StateGraph[S]

func (*StateGraph[S]) StartNode

func (g *StateGraph[S]) StartNode() string

func (*StateGraph[S]) Step

func (g *StateGraph[S]) Step(id string, fn NodeFunc[S]) *StateGraph[S]

func (*StateGraph[S]) Validate

func (g *StateGraph[S]) Validate() error

func (*StateGraph[S]) WorkflowID

func (g *StateGraph[S]) WorkflowID() string

type Workflow

type Workflow interface {
	WorkflowID() string
	Snapshot() Snapshot
	Validate() error
}

Jump to

Keyboard shortcuts

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