haive.core.graph.patterns.base

Base pattern definitions for the Haive framework.

This module provides the core classes for pattern definition, registration, and application in graph-based workflows.

Classes

BranchDefinition

Enhanced branch definition with metadata.

ComponentRequirement

Defines a requirement for a component needed by a pattern.

GraphPattern

Defines a reusable graph pattern.

ParameterDefinition

Definition of a parameter for patterns and branches.

PatternMetadata

Enhanced metadata for graph patterns.

Module Contents

class haive.core.graph.patterns.base.BranchDefinition(/, **data)[source]

Bases: pydantic.BaseModel

Enhanced branch definition with metadata.

Defines a reusable branch condition that can be applied to graphs.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

apply_to_graph(graph, source_node, **kwargs)[source]

Apply this branch directly to a graph.

Parameters:
  • graph (Any) – Graph to add branch to

  • source_node (str) – Source node for branching

  • **kwargs – Parameter values

Returns:

Modified graph

Return type:

Any

create_condition(**kwargs)[source]

Create a condition function with parameters.

Parameters:

**kwargs – Parameter values

Returns:

Configured condition function

Return type:

collections.abc.Callable

classmethod from_dict(data, func_resolver=None)[source]

Create from a serialized dictionary.

Parameters:
Returns:

New BranchDefinition instance

Return type:

BranchDefinition

to_dict()[source]

Convert to a serializable dictionary.

Returns:

Dictionary representation

Return type:

dict[str, Any]

validate_parameters(params)[source]

Validate parameter values against their definitions.

Parameters:

params (dict[str, Any]) – Parameter values to validate

Returns:

Tuple of (is_valid, error_messages)

Return type:

tuple[bool, list[str]]

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class haive.core.graph.patterns.base.ComponentRequirement(/, **data)[source]

Bases: pydantic.BaseModel

Defines a requirement for a component needed by a pattern.

Component requirements can specify types, capabilities, and other attributes that must be present for a pattern to be applied successfully.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

validate_component(component)[source]

Validate if a component meets this requirement.

Parameters:

component (Any) – Component to validate

Returns:

True if the component meets this requirement

Return type:

bool

class haive.core.graph.patterns.base.GraphPattern(/, **data)[source]

Bases: pydantic.BaseModel

Defines a reusable graph pattern.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

apply(graph, **kwargs)[source]

Apply this pattern to a graph.

Parameters:

graph (Any)

Return type:

Any

abstractmethod create_node_config(node_name, **kwargs)[source]

Create a NodeConfig based on this pattern.

Parameters:
  • node_name (str) – Name for the node

  • **kwargs – Configuration parameters

Returns:

NodeConfig instance

Return type:

Any

classmethod from_dict(data, func_resolver=None)[source]

Create from a serialized dictionary.

Parameters:
Returns:

New GraphPattern instance

Return type:

GraphPattern

to_dict()[source]

Convert to a serializable dictionary.

Returns:

Dictionary representation

Return type:

dict[str, Any]

validate_for_application(components, params)[source]

Validate that a pattern can be applied with the provided components and parameters.

Parameters:
  • components (list[Any]) – List of components to check requirements against

  • params (dict[str, Any]) – Parameter values to validate

Returns:

Tuple of (is_valid, error_messages)

Return type:

tuple[bool, list[str]]

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property name: str

Get the pattern name from metadata.

Return type:

str

class haive.core.graph.patterns.base.ParameterDefinition(/, **data)[source]

Bases: pydantic.BaseModel

Definition of a parameter for patterns and branches.

Includes type information, validation rules, and documentation.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

validate_value(value)[source]

Validate a parameter value against this definition.

Parameters:

value (Any) – Value to validate

Returns:

Tuple of (is_valid, error_message)

Return type:

tuple[bool, str | None]

class haive.core.graph.patterns.base.PatternMetadata(/, **data)[source]

Bases: pydantic.BaseModel

Enhanced metadata for graph patterns.

Provides comprehensive information about a pattern, including its requirements, parameters, and documentation.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

check_required_components(components)[source]

Check if the required components are available.

Parameters:

components (list[Any]) – List of available components

Returns:

List of missing component requirements

Return type:

list[str]

validate_parameters(params)[source]

Validate parameter values against their definitions.

Parameters:

params (dict[str, Any]) – Parameter values to validate

Returns:

Tuple of (is_valid, error_messages)

Return type:

tuple[bool, list[str]]