haive.core.graph.node.decorators¶

from typing import Any, Dict. Decorators for creating and registering nodes.

This module provides decorators that make it easy to create various types of nodes from functions, with proper configuration and registration.

Functions¶

branch_node(condition, routes[, name, input_mapping])

Create a branch node.

debug_node([name])

Decorator to add detailed debug logging to a node function.

register_node([name, node_type, command_goto, ...])

Decorator to register a function as a node.

send_node(send_targets, send_field[, name, input_mapping])

Create a send node.

tool_node(tools[, name, command_goto, messages_field, ...])

Create a tool node.

validation_node(schemas[, name, command_goto, ...])

Create a validation node.

Module Contents¶

haive.core.graph.node.decorators.branch_node(condition, routes, name=None, input_mapping=None)¶

Create a branch node.

This decorator creates a node that evaluates a condition on the state and routes to different nodes based on the result.

Parameters:
  • condition (collections.abc.Callable) – Function that evaluates the state and returns a key for routing

  • routes (dict[Any, str]) – Mapping from condition outputs to node names

  • name (str | None) – Optional name for the node

  • input_mapping (dict[str, str] | None) – Mapping from state keys to condition function input keys

haive.core.graph.node.decorators.debug_node(name=None)¶

Decorator to add detailed debug logging to a node function. Logs input state and output result but does not modify the function behavior.

Parameters:

name (str | None) – Name for the node in logs (defaults to function name)

Returns:

Decorated function

haive.core.graph.node.decorators.register_node(name=None, node_type=None, command_goto=None, input_mapping=None, output_mapping=None, retry_policy=None, **kwargs)¶

Decorator to register a function as a node.

This decorator wraps a function as a node function, with proper configuration for node type, command routing, input/output mapping, and retry policy.

Parameters:
  • name (str | None) – Optional name for the node (defaults to function name)

  • node_type (haive.core.graph.node.types.NodeType | None) – Type of node to create

  • command_goto (haive.core.graph.node.types.CommandGoto | None) – Next node to go to after this node

  • input_mapping (dict[str, str] | None) – Mapping from state keys to function input keys

  • output_mapping (dict[str, str] | None) – Mapping from function output keys to state keys

  • retry_policy (langgraph.types.RetryPolicy | None) – Retry policy for the node

  • **kwargs – Additional options for the node configuration

Returns:

Decorated function as a node function

haive.core.graph.node.decorators.send_node(send_targets, send_field, name=None, input_mapping=None)¶

Create a send node.

This decorator creates a node that generates Send objects to route to different nodes with different states. It’s useful for fan-out operations.

Parameters:
  • send_targets (list[str]) – List of target node names

  • send_field (str) – Key in the state containing items to send

  • name (str | None) – Optional name for the node

  • input_mapping (dict[str, str] | None) – Mapping from state keys to field with items

haive.core.graph.node.decorators.tool_node(tools, name=None, command_goto=None, messages_field='messages', handle_tool_errors=True)¶

Create a tool node.

This decorator creates a node that handles tool calls using LangGraph’s ToolNode. It’s a specialized version of register_node.

Parameters:
  • tools (list) – List of tools for the node

  • name (str | None) – Optional name for the node

  • command_goto (haive.core.graph.node.types.CommandGoto | None) – Next node to go to after this node

  • messages_field (str) – Name of the messages key in the state

  • handle_tool_errors (bool | str | collections.abc.Callable[Ellipsis, str]) – How to handle tool errors

haive.core.graph.node.decorators.validation_node(schemas, name=None, command_goto=None, messages_field='messages')¶

Create a validation node.

This decorator creates a node that validates inputs against a schema using LangGraph’s ValidationNode. It’s a specialized version of register_node.

Parameters:
  • schemas (list) – List of validation schemas

  • name (str | None) – Optional name for the node

  • command_goto (haive.core.graph.node.types.CommandGoto | None) – Next node to go to after this node

  • messages_field (str) – Name of the messages key in the state