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: 14 Imported by: 0

Documentation

Overview

Package graph provides YAML configuration parsing for graph workflows.

Package graph provides graph orchestration service implementation.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidConfig  = errors.New("invalid configuration")
	ErrInvalidGraph   = errors.New("invalid graph")
	ErrInvalidRequest = errors.New("invalid request")
	ErrInvalidBuilder = errors.New("invalid builder function")
	ErrMissingGraphID = errors.New("missing graph ID")
)

Service errors.

Functions

func BuildSimple

func BuildSimple(configYAML []byte) (*wfgraph.Graph, error)

BuildSimple creates a simple graph from YAML without agent registration.

Types

type Agent

type Agent struct {
	ID     string                 `yaml:"id"`
	Type   string                 `yaml:"type"`
	Name   string                 `yaml:"name"`
	Config map[string]interface{} `yaml:"config,omitempty"`
}

Agent defines an agent configuration

type Config

type Config struct {
	// RequestTimeout is the default request timeout.
	RequestTimeout time.Duration
	// MaxRetries is the maximum number of retries.
	MaxRetries int
	// RetryDelay is the delay between retries.
	RetryDelay time.Duration
	// Tracer is the observability tracer.
	Tracer observability.Tracer
	// Limiter is the rate limiter.
	Limiter ratelimit.Limiter
}

Config represents service configuration.

type Edge

type Edge struct {
	From      string `yaml:"from"`
	To        string `yaml:"to"`
	Condition string `yaml:"condition,omitempty"` // expression or condition ID
}

Edge defines a connection between nodes

type ExecuteRequest

type ExecuteRequest struct {
	// GraphID is the graph identifier.
	GraphID string
	// State is the initial state for graph execution.
	State map[string]any
	// Timeout is the execution timeout.
	Timeout time.Duration
}

ExecuteRequest represents a graph execution request.

type ExecuteResponse

type ExecuteResponse struct {
	// GraphID is the graph identifier.
	GraphID string
	// State is the final state after execution.
	State map[string]any
	// Duration is the execution duration.
	Duration time.Duration
	// Error is the execution error if any.
	Error string
}

ExecuteResponse represents a graph execution response.

type GraphBuilder

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

GraphBuilder builds graph instances from configuration.

func NewGraphBuilder

func NewGraphBuilder() *GraphBuilder

NewGraphBuilder creates a new graph builder.

func (*GraphBuilder) Build

func (b *GraphBuilder) Build(config *GraphConfig) (*wfgraph.Graph, error)

Build builds a graph from configuration.

func (*GraphBuilder) RegisterAgent

func (b *GraphBuilder) RegisterAgent(agent base.Agent)

RegisterAgent registers an agent for use in graph configuration.

func (*GraphBuilder) RegisterTool

func (b *GraphBuilder) RegisterTool(id string, tool interface{})

RegisterTool registers a tool for use in graph configuration.

type GraphConfig

type GraphConfig struct {
	Graph GraphDefinition `yaml:"graph"`
}

GraphConfig represents the complete graph configuration from YAML

func ParseGraphConfig

func ParseGraphConfig(data []byte) (*GraphConfig, error)

ParseGraphConfig parses a YAML configuration file

type GraphDefinition

type GraphDefinition struct {
	ID        string  `yaml:"id"`
	StartNode string  `yaml:"start_node"`
	Nodes     []Node  `yaml:"nodes"`
	Edges     []Edge  `yaml:"edges"`
	Agents    []Agent `yaml:"agents,omitempty"`
}

GraphDefinition defines a graph structure

func (*GraphDefinition) GetAgentByID

func (g *GraphDefinition) GetAgentByID(id string) (*Agent, bool)

GetAgentByID retrieves an agent by its ID

func (*GraphDefinition) GetNodeByID

func (g *GraphDefinition) GetNodeByID(id string) (*Node, bool)

GetNodeByID retrieves a node by its ID

type GraphInfo

type GraphInfo struct {
	GraphID string
}

GraphInfo represents graph information.

type Node

type Node struct {
	ID          string                 `yaml:"id"`
	Type        string                 `yaml:"type"` // function, agent, tool
	Description string                 `yaml:"description,omitempty"`
	Config      map[string]interface{} `yaml:"config,omitempty"`
}

Node defines a graph node

type RateLimit

type RateLimit struct {
	Enabled bool           `yaml:"enabled"`
	Type    string         `yaml:"type"` // token_bucket
	Config  map[string]any `yaml:"config,omitempty"`
}

RateLimit defines rate limiting configuration

type Service

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

Service provides graph orchestration operations.

func BuildWithService

func BuildWithService(configYAML []byte, builder *GraphBuilder) (*Service, *wfgraph.Graph, error)

BuildWithService creates a complete graph service from configuration.

func NewService

func NewService(config *Config) (*Service, error)

NewService creates a new graph service instance. Args: config - service configuration. Returns new graph service instance or error.

func (*Service) Execute

func (s *Service) Execute(ctx context.Context, g *wfgraph.Graph, request *ExecuteRequest) (*ExecuteResponse, error)

Execute executes a graph with the given request. Args: ctx - context for cancellation and timeout. graph - the graph to execute. request - execution parameters. Returns execution response or error.

func (*Service) ExecuteWithGraphBuilder

func (s *Service) ExecuteWithGraphBuilder(
	ctx context.Context,
	graphID string,
	builder func(*wfgraph.Graph) *wfgraph.Graph,
	request *ExecuteRequest,
) (*ExecuteResponse, error)

ExecuteWithGraphBuilder executes a graph built with a builder function. Args: ctx - context for cancellation and timeout. graphID - graph identifier. builder - function to build the graph. request - execution parameters. Returns execution response or error.

func (*Service) GetGraphInfo

func (s *Service) GetGraphInfo(g *wfgraph.Graph) *GraphInfo

GetGraphInfo returns information about a graph. Args: graph - the graph to inspect. Returns graph information.

func (*Service) ValidateGraph

func (s *Service) ValidateGraph(g *wfgraph.Graph) error

ValidateGraph validates a graph definition. Args: graph - the graph to validate. Returns validation error or nil if valid.

type ServiceConfig

type ServiceConfig struct {
	RequestTimeout time.Duration `yaml:"request_timeout"`
	TracerType     string        `yaml:"tracer_type"`
	LogLevel       string        `yaml:"log_level"`
	RateLimit      *RateLimit    `yaml:"rate_limit,omitempty"`
}

ServiceConfig represents service-level configuration

Jump to

Keyboard shortcuts

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