Documentation
¶
Overview ¶
Package graph provides the core domain types for representing execution graphs.
A graph consists of nodes (execution units) connected by edges (transitions). The graph structure defines the flow of execution through the system.
Node Types:
- ExecutorNode: Executes tasks like LLM calls, tool invocations, or code execution
- RouterNode: Makes routing decisions based on state conditions
- Start/End: Special nodes for graph entry and exit points
This package defines only the domain models and interfaces. Actual implementations of node execution logic should be in the main dago repository.
Index ¶
- type BaseNode
- type Edge
- type ExecutorNode
- type Graph
- func (g *Graph) AddEdge(edge *Edge) error
- func (g *Graph) AddNode(node Node) error
- func (g *Graph) Clone() (*Graph, error)
- func (g *Graph) EdgeCount() int
- func (g *Graph) GetIncomingEdges(nodeID string) []*Edge
- func (g *Graph) GetNode(nodeID string) Node
- func (g *Graph) GetOutgoingEdges(nodeID string) []*Edge
- func (g *Graph) NodeCount() int
- func (g *Graph) RemoveNode(nodeID string)
- func (g *Graph) ToJSON() (string, error)
- func (g *Graph) Validate() error
- type Node
- type NodeType
- type Route
- type RouterNode
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseNode ¶
type BaseNode struct {
ID string `json:"id"`
Type NodeType `json:"type"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
BaseNode provides common fields for all node types. This is a helper struct that can be embedded in concrete node implementations.
type Edge ¶
type Edge struct {
// ID is a unique identifier for this edge.
ID string `json:"id,omitempty"`
// From is the ID of the source node.
From string `json:"from"`
// To is the ID of the target node.
To string `json:"to"`
// Condition is an optional expression that must evaluate to true for this edge to be traversed.
// If empty, the edge is always traversable.
// The expression syntax is implementation-specific.
Condition string `json:"condition,omitempty"`
// Label provides a human-readable description of this edge.
Label string `json:"label,omitempty"`
// Metadata stores additional edge-specific data.
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
Edge represents a directed connection between two nodes in the graph.
func (*Edge) WithCondition ¶
WithCondition sets a condition on the edge.
type ExecutorNode ¶
type ExecutorNode struct {
BaseNode
// ExecutorType specifies what kind of executor this is (e.g., "llm", "tool", "python").
ExecutorType string `json:"executor_type"`
// Config contains executor-specific configuration.
// The structure depends on the ExecutorType.
Config map[string]interface{} `json:"config"`
// InputMapping defines how to map state values to executor inputs.
InputMapping map[string]string `json:"input_mapping,omitempty"`
// OutputMapping defines how to map executor outputs back to state.
OutputMapping map[string]string `json:"output_mapping,omitempty"`
}
ExecutorNode represents a node that executes tasks like LLM calls or tool invocations.
func (*ExecutorNode) Execute ¶
Execute is a placeholder that should be implemented in the main repository.
func (*ExecutorNode) Validate ¶
func (n *ExecutorNode) Validate() error
Validate checks if the executor node configuration is valid.
type Graph ¶
type Graph struct {
// ID is a unique identifier for this graph.
ID string `json:"id"`
// Name is a human-readable name for the graph.
Name string `json:"name,omitempty"`
// Description provides context about what this graph does.
Description string `json:"description,omitempty"`
// Nodes is a map of node ID to node instance.
// Using a map allows O(1) lookups by ID.
Nodes map[string]Node `json:"nodes"`
// Edges defines the connections between nodes.
Edges []*Edge `json:"edges"`
// EntryNode is the ID of the node where execution begins.
EntryNode string `json:"entry_node"`
// Metadata stores additional graph-level data.
Metadata map[string]interface{} `json:"metadata,omitempty"`
// Version is the schema version of this graph definition.
Version string `json:"version,omitempty"`
}
Graph represents a directed graph of nodes and edges that defines the execution flow.
func FromJSON ¶
FromJSON deserializes a graph from JSON. Note: This is a basic implementation. Full deserialization with proper node type handling should be implemented in the main dago repository.
func (*Graph) AddEdge ¶
AddEdge adds an edge to the graph. Validates that both source and target nodes exist.
func (*Graph) AddNode ¶
AddNode adds a node to the graph. Returns an error if a node with the same ID already exists.
func (*Graph) Clone ¶
Clone creates a deep copy of the graph. Note: This uses JSON serialization for simplicity. TODO: Consider more efficient cloning for performance-critical paths.
func (*Graph) GetIncomingEdges ¶
GetIncomingEdges returns all edges targeting the given node.
func (*Graph) GetOutgoingEdges ¶
GetOutgoingEdges returns all edges originating from the given node.
func (*Graph) RemoveNode ¶
RemoveNode removes a node from the graph. Also removes any edges connected to this node.
type Node ¶
type Node interface {
// GetID returns the unique identifier for this node.
GetID() string
// GetType returns the type of this node.
GetType() NodeType
// Execute runs the node's logic with the given context and state.
// It returns the updated state and any error that occurred.
// Implementations should be provided in the main dago repository, not here.
Execute(ctx context.Context, state state.State) (state.State, error)
// Validate checks if the node configuration is valid.
Validate() error
}
Node defines the interface that all graph nodes must implement.
type NodeType ¶
type NodeType string
NodeType represents the type of a node in the graph.
const ( // NodeTypeExecutor represents a node that executes a task (calls LLM, runs tools, etc). NodeTypeExecutor NodeType = "executor" // NodeTypeRouter represents a node that makes routing decisions based on state. NodeTypeRouter NodeType = "router" // NodeTypeStart represents the entry point of the graph. NodeTypeStart NodeType = "start" // NodeTypeEnd represents an exit point of the graph. NodeTypeEnd NodeType = "end" )
type Route ¶
type Route struct {
// Condition is an expression evaluated against the state.
// The expression syntax is implementation-specific (e.g., JSONPath, simple comparisons).
Condition string `json:"condition"`
// Target is the ID of the node to route to if the condition is true.
Target string `json:"target"`
// Description provides human-readable context for this route.
Description string `json:"description,omitempty"`
}
Route represents a conditional routing rule.
type RouterNode ¶
type RouterNode struct {
BaseNode
// Routes defines the routing logic.
// Each route has a condition and target node ID.
Routes []Route `json:"routes"`
// DefaultRoute is the fallback route if no conditions match.
DefaultRoute string `json:"default_route,omitempty"`
}
RouterNode represents a node that makes routing decisions based on state.
func (*RouterNode) Execute ¶
Execute is a placeholder that should be implemented in the main repository.
func (*RouterNode) Validate ¶
func (n *RouterNode) Validate() error
Validate checks if the router node configuration is valid.
type ValidationError ¶
ValidationError represents a node validation error.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface.