graph

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package graph provides dependency graph operations for agent startup ordering.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCycleDetected is returned when a dependency cycle is found in the graph.
	ErrCycleDetected = errors.New("dependency cycle detected")

	// ErrUnknownDependency is returned when an agent depends on an unknown agent.
	ErrUnknownDependency = errors.New("unknown dependency")
)

Functions

This section is empty.

Types

type CycleError

type CycleError struct {
	Path []string
}

CycleError provides detailed information about a dependency cycle.

func (*CycleError) Error

func (e *CycleError) Error() string

Error returns a human-readable description of the cycle.

func (*CycleError) Unwrap

func (e *CycleError) Unwrap() error

Unwrap returns the base error for errors.Is compatibility.

type DependencyGraph

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

DependencyGraph manages agent startup dependencies using a directed acyclic graph. It supports topological sorting to determine the correct startup order.

func NewDependencyGraph

func NewDependencyGraph() *DependencyGraph

NewDependencyGraph creates a new empty dependency graph.

func (*DependencyGraph) AddNode

func (g *DependencyGraph) AddNode(name string, dependencies []string)

AddNode adds an agent to the dependency graph with its dependencies. If dependencies is nil or empty, the agent has no dependencies.

func (*DependencyGraph) GetDependencies

func (g *DependencyGraph) GetDependencies(name string) []string

GetDependencies returns the dependencies for a given agent. Returns nil if the agent is not found.

func (*DependencyGraph) NodeCount

func (g *DependencyGraph) NodeCount() int

NodeCount returns the number of nodes in the graph.

func (*DependencyGraph) TopologicalLevels

func (g *DependencyGraph) TopologicalLevels() ([][]string, error)

TopologicalLevels returns agents grouped by dependency level using Kahn's algorithm. Level 0 contains agents with no dependencies. Level N contains agents whose dependencies are all in levels < N. Agents within the same level can be started in parallel.

Returns an error if the graph contains cycles or unknown dependencies.

func (*DependencyGraph) Validate

func (g *DependencyGraph) Validate() error

Validate checks the graph for cycles and unknown dependencies. Returns an error if validation fails, nil otherwise.

type Node

type Node struct {
	Name         string
	Dependencies []string
}

Node represents an agent in the dependency graph.

Jump to

Keyboard shortcuts

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