graph

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 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 AgentNode

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

AgentNode wraps an existing agent to be used as a node.

func NewAgentNode

func NewAgentNode(agent base.Agent) *AgentNode

NewAgentNode creates a new agent node.

NOTE: This function will panic if agent is nil. This is intentional as it indicates a programming error in the calling code. These constructors are used during workflow graph initialization (startup phase), and invalid parameters represent fatal startup failures that should prevent application launch. This follows the coding standard allowing panic for fatal startup errors.

Args: agent - agent instance, must not be nil. Returns new agent node.

func (*AgentNode) Execute

func (n *AgentNode) Execute(ctx context.Context, state *State) error

Execute runs the agent node.

func (*AgentNode) ID

func (n *AgentNode) ID() string

ID returns the agent ID.

type Condition

type Condition func(state *State) bool

Condition defines a predicate function for edge traversal.

func IfFunc

func IfFunc(fn func(state *State) bool) Condition

IfFunc creates a condition from a function.

type DefaultScheduler

type DefaultScheduler struct{}

DefaultScheduler provides FIFO scheduling, consistent with Workflow Engine.

func NewDefaultScheduler

func NewDefaultScheduler() *DefaultScheduler

NewDefaultScheduler creates a new default scheduler.

func (*DefaultScheduler) Select

func (s *DefaultScheduler) Select(ready []string) string

Select returns the first ready node (FIFO).

type Edge

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

Edge represents a connection between two nodes with optional condition.

type FuncNode

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

FuncNode wraps a simple function to be used as a node.

func NewFuncNode

func NewFuncNode(id string, fn func(context.Context, *State) error) *FuncNode

NewFuncNode creates a new function node.

NOTE: This function will panic if id is empty or fn is nil. This is intentional as it indicates a programming error in the calling code. These constructors are used during workflow graph initialization (startup phase), and invalid parameters represent fatal startup failures that should prevent application launch. This follows the coding standard allowing panic for fatal startup errors.

Args: id - unique node identifier, must not be empty. fn - function to execute, must not be nil. Returns new function node.

func (*FuncNode) Execute

func (n *FuncNode) Execute(ctx context.Context, state *State) error

Execute runs the function node.

func (*FuncNode) ID

func (n *FuncNode) ID() string

ID returns the function node ID.

type Graph

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

Graph represents a DAG of nodes with conditional edges.

func NewGraph

func NewGraph(id string) *Graph

NewGraph creates a new graph with the given ID.

NOTE: This function will panic if id is empty. This is intentional as it indicates a programming error in the calling code. This constructor is used during workflow graph initialization (startup phase), and invalid parameters represent fatal startup failures that should prevent application launch. This follows the coding standard allowing panic for fatal startup errors.

Args: id - unique graph identifier, must not be empty. Returns new graph instance.

func NewGraphWithLimiter

func NewGraphWithLimiter(id string, limiter ratelimit.Limiter) *Graph

NewGraphWithLimiter creates a new graph with a custom rate limiter.

NOTE: This function will panic if id is empty. This is intentional as it indicates a programming error in the calling code. This constructor is used during workflow graph initialization (startup phase), and invalid parameters represent fatal startup failures that should prevent application launch. This follows the coding standard allowing panic for fatal startup errors.

Args: id - unique graph identifier, must not be empty. limiter - rate limiter for execution throttling. Returns new graph instance.

func NewGraphWithTracer

func NewGraphWithTracer(id string, tracer observability.Tracer) *Graph

NewGraphWithTracer creates a new graph with a custom tracer.

NOTE: This function will panic if id is empty or tracer is nil. This is intentional as it indicates a programming error in the calling code. This constructor is used during workflow graph initialization (startup phase), and invalid parameters represent fatal startup failures that should prevent application launch. This follows the coding standard allowing panic for fatal startup errors.

Args: id - unique graph identifier, must not be empty. tracer - observability tracer, must not be nil. Returns new graph instance.

func (*Graph) Edge

func (g *Graph) Edge(from, to string, cond ...Condition) *Graph

Edge adds an edge from one node to another with optional condition.

NOTE: This method will panic if graph is nil, from id is empty, or to id is empty. This is intentional as it indicates a programming error in the calling code. These methods are used during workflow graph initialization (startup phase), and invalid parameters represent fatal startup failures that should prevent application launch. This follows the coding standard allowing panic for fatal startup errors.

Args: from - source node ID, must not be empty. to - target node ID, must not be empty. cond - optional edge traversal condition. Returns graph for method chaining.

func (*Graph) Execute

func (g *Graph) Execute(ctx context.Context, state *State) (*Result, error)

Execute runs the graph with the given state.

func (*Graph) ID

func (g *Graph) ID() string

ID returns the graph ID.

func (*Graph) Node

func (g *Graph) Node(id string, node Node) *Graph

Node adds a node to the graph.

NOTE: This method will panic if graph is nil, id is empty, or node is nil. This is intentional as it indicates a programming error in the calling code. These methods are used during workflow graph initialization (startup phase), and invalid parameters represent fatal startup failures that should prevent application launch. This follows the coding standard allowing panic for fatal startup errors.

Args: id - unique node identifier, must not be empty. node - node instance, must not be nil. Returns graph for method chaining.

func (*Graph) SetLimiter

func (g *Graph) SetLimiter(limiter ratelimit.Limiter) *Graph

SetLimiter sets a custom rate limiter for the graph.

NOTE: This method will panic if graph is nil. This is intentional as it indicates a programming error in the calling code. These methods are used during workflow graph initialization (startup phase), and invalid parameters represent fatal startup failures that should prevent application launch. This follows the coding standard allowing panic for fatal startup errors.

Args: limiter - custom rate limiter instance (can be nil for no limiting). Returns graph for method chaining.

func (*Graph) SetScheduler

func (g *Graph) SetScheduler(scheduler Scheduler) *Graph

SetScheduler sets a custom scheduler for the graph.

NOTE: This method will panic if graph is nil or scheduler is nil. This is intentional as it indicates a programming error in the calling code. These methods are used during workflow graph initialization (startup phase), and invalid parameters represent fatal startup failures that should prevent application launch. This follows the coding standard allowing panic for fatal startup errors.

Args: scheduler - custom scheduler instance, must not be nil. Returns graph for method chaining.

func (*Graph) SetTracer

func (g *Graph) SetTracer(tracer observability.Tracer) *Graph

SetTracer sets a custom tracer for the graph.

NOTE: This method will panic if graph is nil or tracer is nil. This is intentional as it indicates a programming error in the calling code. These methods are used during workflow graph initialization (startup phase), and invalid parameters represent fatal startup failures that should prevent application launch. This follows the coding standard allowing panic for fatal startup errors.

Args: tracer - custom tracer instance, must not be nil. Returns graph for method chaining.

func (*Graph) Start

func (g *Graph) Start(id string) *Graph

Start sets the starting node for the graph.

NOTE: This method will panic if graph is nil or id is empty. This is intentional as it indicates a programming error in the calling code. These methods are used during workflow graph initialization (startup phase), and invalid parameters represent fatal startup failures that should prevent application launch. This follows the coding standard allowing panic for fatal startup errors.

Args: id - starting node ID, must not be empty. Returns graph for method chaining.

type Node

type Node interface {
	// Execute runs the node with the given state.
	Execute(ctx context.Context, state *State) error
	// ID returns the unique identifier of the node.
	ID() string
}

Node represents an executable unit in the graph.

type PriorityScheduler

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

PriorityScheduler provides priority-based scheduling.

func NewPriorityScheduler

func NewPriorityScheduler(priorities map[string]int) *PriorityScheduler

NewPriorityScheduler creates a new priority scheduler.

func (*PriorityScheduler) Select

func (s *PriorityScheduler) Select(ready []string) string

Select returns the ready node with the highest priority.

type Result

type Result struct {
	GraphID  string
	State    *State
	Duration time.Duration
	Error    error
}

Result represents the result of graph execution.

type Scheduler

type Scheduler interface {
	// Select returns the next node ID to execute from the ready queue.
	Select(ready []string) string
}

Scheduler defines the interface for node scheduling.

type ShortJobScheduler

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

ShortJobScheduler provides shortest-job-first scheduling.

func NewShortJobScheduler

func NewShortJobScheduler(estimates map[string]int) *ShortJobScheduler

NewShortJobScheduler creates a new short-job scheduler.

func (*ShortJobScheduler) Select

func (s *ShortJobScheduler) Select(ready []string) string

Select returns the ready node with the shortest estimated execution time.

type State

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

State represents the shared runtime state for graph execution. It is lock-free as graph execution is single-threaded by default.

func NewState

func NewState() *State

NewState creates a new empty state instance.

func (*State) Get

func (s *State) Get(key string) (any, bool)

Get retrieves a value from the state by key. Returns the value and a boolean indicating whether the key exists.

func (*State) Set

func (s *State) Set(key string, val any)

Set stores a value in the state with the given key.

func (*State) ToParams

func (s *State) ToParams() map[string]any

ToParams converts the state to a map for tool parameter passing.

type ToolNode

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

ToolNode wraps an existing tool to be used as a node.

func NewToolNode

func NewToolNode(tool core.Tool) *ToolNode

NewToolNode creates a new tool node.

NOTE: This function will panic if tool is nil. This is intentional as it indicates a programming error in the calling code. These constructors are used during workflow graph initialization (startup phase), and invalid parameters represent fatal startup failures that should prevent application launch. This follows the coding standard allowing panic for fatal startup errors.

Args: tool - tool instance, must not be nil. Returns new tool node.

func (*ToolNode) Execute

func (n *ToolNode) Execute(ctx context.Context, state *State) error

Execute runs the tool node.

func (*ToolNode) ID

func (n *ToolNode) ID() string

ID returns the tool name.

Jump to

Keyboard shortcuts

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