haive.core.graph.node.composer.update_functions

Update function library for NodeSchemaComposer.

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

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

Classes

UpdateFunctions

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

Module Contents

class haive.core.graph.node.composer.update_functions.UpdateFunctions

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

Initialize with shared PathResolver instance.

update_conditional(condition_path, true_field, false_field)

Create update function with conditional logic.

Pattern from: EngineNode multi-strategy selection Usage: Update different fields based on state condition

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

  • true_field (str) – Field to update if condition is truthy

  • false_field (str) – Field to update if condition is falsy

Returns:

Update function that conditionally updates fields

Return type:

haive.core.graph.node.composer.protocols.UpdateFunction

Examples

# Update different fields based on mode update_output = update_conditional(

“config.save_history”, “conversation_history”, “current_response”

) updates = update_output(result, state, {})

update_hierarchical(base_field, projection_fields=None)

Create update function for hierarchical state updates.

Pattern from: AgentNodeV3 hierarchical projections Usage: Update nested objects with field projections

Parameters:
  • base_field (str) – Base field containing the object to update

  • projection_fields (list[str] | None) – List of fields to include in update (None = all)

Returns:

Update function that updates hierarchical structure

Return type:

haive.core.graph.node.composer.protocols.UpdateFunction

Examples

# Update agent with specific fields only update_agent = update_hierarchical(“current_agent”, [“status”, “last_action”]) agent_update = {“status”: “active”, “last_action”: “search”, “other”: “ignored”} updates = update_agent(agent_update, state, {})

update_messages_append(messages_field='messages')

Create update function for appending to messages.

Pattern from: Multiple nodes working with MessagesState Usage: Append new message to conversation history

Parameters:

messages_field (str) – Name of field containing messages list

Returns:

Update function that appends message to list

Return type:

haive.core.graph.node.composer.protocols.UpdateFunction

Examples

# Append AI message to conversation update_msgs = update_messages_append() updates = update_msgs(ai_message, state, {})

update_multi_field(field_mappings)

Create update function for multiple field updates.

Pattern from: OutputParserNode, AgentNodeV3 complex outputs Usage: Update multiple fields from single result

Parameters:

field_mappings (dict[str, str]) – Mapping of result keys to target field names

Returns:

Update function that updates multiple fields

Return type:

haive.core.graph.node.composer.protocols.UpdateFunction

Examples

# Split result into multiple fields update_multi = update_multi_field({

“response”: “ai_response”, “confidence”: “response_confidence”, “tokens”: “token_usage”

})

result = {“response”: “Hello”, “confidence”: 0.9, “tokens”: 25} updates = update_multi(result, state, {})

update_simple_field(field_name, merge_mode='replace')

Create update function for simple field updates.

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

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

  • merge_mode (str) – How to handle updates (“replace”, “append”, “merge”)

Returns:

Update function that sets the specified field

Return type:

haive.core.graph.node.composer.protocols.UpdateFunction

Examples

# Replace field value update_result = update_simple_field(“result”) updates = update_result(“new_value”, state, {})

# Append to list field update_messages = update_simple_field(“messages”, “append”) updates = update_messages(“new message”, state, {})

update_type_aware(field_name, expected_type)

Create update function with type validation.

Pattern from: ParserNodeV2 safety nets Usage: Update field ensuring result matches expected type

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

  • expected_type (type) – Expected type of update value

Returns:

Update function that validates type before updating

Return type:

haive.core.graph.node.composer.protocols.UpdateFunction

Examples

# Update with int validation update_count = update_type_aware(“iteration_count”, int) updates = update_count(5, state, {})

update_with_path(target_path, merge_mode='replace')

Create update function for complex path updates.

Pattern from: AgentNodeV3 hierarchical updates, EngineNode complex cases Usage: Update using dot notation, array access, nested paths

Parameters:
  • target_path (str) – Path string for update target

  • merge_mode (str) – How to handle updates (“replace”, “append”, “merge”)

Returns:

Update function that updates value at the specified path

Return type:

haive.core.graph.node.composer.protocols.UpdateFunction

Examples

# Update nested config value update_temp = update_with_path(“config.temperature”) updates = update_temp(0.8, state, {})

# Append to nested list update_msgs = update_with_path(“agents[0].messages”, “append”) updates = update_msgs(“new message”, state, {})

update_with_transform(field_name, transform_func)

Create update function with value transformation.

Pattern from: OutputParserNode value processing Usage: Transform result before updating field

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

  • transform_func (callable) – Function to transform the result

Returns:

Update function that transforms then updates

Return type:

haive.core.graph.node.composer.protocols.UpdateFunction

Examples

# Transform to uppercase before updating update_upper = update_with_transform(“title”, str.upper) updates = update_upper(“hello world”, state, {})

# Parse JSON before updating import json update_parsed = update_with_transform(“data”, json.loads) updates = update_parsed(‘{“key”: “value”}’, state, {})