haive.core.graph.node.composer.extract_functions¶

Extract function library for NodeSchemaComposer.

This module provides common extract patterns identified from node analysis, offering pluggable extract functions for flexible I/O configuration.

Based on analysis of 6 node types, these functions handle the most common extraction patterns found in actual Haive nodes.

Classes¶

ExtractFunctions

Library of common extract functions for node I/O composition.

Module Contents¶

class haive.core.graph.node.composer.extract_functions.ExtractFunctions¶

Library of common extract functions for node I/O composition.

Initialize with shared PathResolver instance.

extract_conditional(condition_path, true_path, false_path, true_default=None, false_default=None)¶

Create extract function with conditional logic.

Pattern from: EngineNode multi-strategy selection Usage: Extract different values based on condition

Parameters:
  • condition_path (str) – Path to condition value

  • true_path (str) – Path to extract if condition is truthy

  • false_path (str) – Path to extract if condition is falsy

  • true_default (Any) – Default for true case

  • false_default (Any) – Default for false case

Returns:

Extract function that conditionally extracts values

Return type:

haive.core.graph.node.composer.protocols.ExtractFunction

Examples

# Use different fields based on mode extract_input = extract_conditional(

“config.use_history”, “full_conversation”, “current_message”

) input_data = extract_input(state, {})

extract_messages_content(messages_field='messages')¶

Create extract function for message content.

Pattern from: Multiple nodes working with MessagesState Usage: Extract content from all messages in conversation

Parameters:

messages_field (str) – Name of field containing messages list

Returns:

Extract function that gets content from all messages

Return type:

haive.core.graph.node.composer.protocols.ExtractFunction

Examples

# Extract all message content extract_content = extract_messages_content() contents = extract_content(messages_state, {}) # Returns: [“Hello”, “Hi there”, “How are you?”]

extract_multi_field(field_paths, defaults=None)¶

Create extract function for multiple fields.

Pattern from: OutputParserNode, AgentNodeV3 complex inputs Usage: Extract multiple fields into a single dictionary

Parameters:
  • field_paths (dict[str, str]) – Mapping of output keys to source paths

  • defaults (dict[str, Any] | None) – Default values for each output key

Returns:

Extract function that extracts multiple fields

Return type:

haive.core.graph.node.composer.protocols.ExtractFunction

Examples

# Extract multiple fields for tool input extract_tool_input = extract_multi_field({

“query”: “current_query”, “context”: “messages[-1].content”, “temperature”: “config.temperature”

}, defaults={“temperature”: 0.7})

tool_input = extract_tool_input(state, {}) # Returns: {“query”: “…”, “context”: “…”, “temperature”: 0.7}

extract_simple_field(field_name, default=None)¶

Create extract function for simple field access.

Pattern from: ValidationNodeV2, EngineNode simple cases Usage: Extract single field from state

Parameters:
  • field_name (str) – Name of field to extract

  • default (Any) – Default value if field not found

Returns:

Extract function that gets the specified field

Return type:

haive.core.graph.node.composer.protocols.ExtractFunction

Examples

# Extract messages field extract_msgs = extract_simple_field(“messages”) messages = extract_msgs(state, {})

# Extract with default extract_temp = extract_simple_field(“temperature”, 0.7) temp = extract_temp(state, {})

extract_typed(path, expected_type, default=None)¶

Create extract function with type validation.

Pattern from: ParserNodeV2 safety nets Usage: Extract value and ensure it matches expected type

Parameters:
  • path (str) – Path to extract from

  • expected_type (type) – Expected type of extracted value

  • default (Any) – Default value if extraction fails or type doesn’t match

Returns:

Extract function that validates type

Return type:

haive.core.graph.node.composer.protocols.ExtractFunction

Examples

# Extract with type validation extract_count = extract_typed(“iteration_count”, int, 0) count = extract_count(state, {}) # Always returns int

extract_with_path(path, default=None)¶

Create extract function for complex path access.

Pattern from: EngineNode complex cases, AgentNodeV3 projections Usage: Extract using dot notation, array access, nested paths

Parameters:
  • path (str) – Path string (e.g., “messages[-1].content”, “config.temperature”)

  • default (Any) – Default value if path not found

Returns:

Extract function that gets value at the specified path

Return type:

haive.core.graph.node.composer.protocols.ExtractFunction

Examples

# Extract last message content extract_last = extract_with_path(“messages[-1].content”) content = extract_last(state, {})

# Extract nested config extract_temp = extract_with_path(“config.llm.temperature”, 0.7) temp = extract_temp(state, {})

extract_with_projection(field_name, projection_fields)¶

Create extract function with field projection.

Pattern from: AgentNodeV3 hierarchical updates Usage: Extract object but only include specified fields

Parameters:
  • field_name (str) – Name of field containing object to project

  • projection_fields (list[str]) – List of fields to include in projection

Returns:

Extract function that projects only specified fields

Return type:

haive.core.graph.node.composer.protocols.ExtractFunction

Examples

# Project only name and status from agents extract_agents = extract_with_projection(“agents”, [“name”, “status”]) projected = extract_agents(state, {})