haive.core.graph.node.practical_stateful_example¶

from typing import Any, Dict. Practical Stateful Node Example - Real Implementation.

This shows how to practically implement stateful nodes that work with the current SimpleAgent, LLMState, and MetaStateSchema architecture without breaking changes.

The key insight is that the existing architecture already provides most of what we need: - SimpleAgent.engines dict for engine discovery - LLMState.tool_routes for tool routing - MetaStateSchema for agent composition - Existing node *_config classes for patterns

We just need to enhance the discovery mechanisms in the existing nodes.

Classes¶

StatefulParserNodeV2

Enhanced ParserNodeConfig with stateful discovery capabilities.

StatefulSimpleAgent

Enhanced SimpleAgent that uses stateful nodes for dynamic discovery.

StatefulValidationNodeV2

Enhanced ValidationNodeConfigV2 with stateful discovery capabilities.

Functions¶

backward_compatibility_example()

Show that existing code continues to work unchanged.

meta_state_integration_example()

Show how stateful nodes work with MetaStateSchema.

practical_stateful_example()

Practical example showing how stateful nodes work with current architecture.

Module Contents¶

class haive.core.graph.node.practical_stateful_example.StatefulParserNodeV2(/, **data)¶

Bases: haive.core.graph.node.parser_node_config.ParserNodeConfig

Enhanced ParserNodeConfig with stateful discovery capabilities.

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)

discover_agent_node(state)¶

Discover agent node destination from state.

Parameters:

state (Any)

Return type:

str

class haive.core.graph.node.practical_stateful_example.StatefulSimpleAgent¶

Bases: haive.agents.simple.agent.SimpleAgent

Enhanced SimpleAgent that uses stateful nodes for dynamic discovery.

build_graph()¶

Override build_graph to use stateful nodes.

Return type:

Any

create_runnable(runnable_config=None)¶

Override to inject routing config into state.

Parameters:

runnable_config (dict[str, Any] | None)

class haive.core.graph.node.practical_stateful_example.StatefulValidationNodeV2(/, **data)¶

Bases: haive.core.graph.node.validation_node_config_v2.ValidationNodeConfigV2

Enhanced ValidationNodeConfigV2 with stateful discovery capabilities.

This extends the existing ValidationNodeConfigV2 to add dynamic discovery while maintaining full backward compatibility.

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)

discover_routing_destinations(state)¶

Discover routing destinations from state dynamically.

Parameters:

state (Any)

Return type:

dict[str, str]

haive.core.graph.node.practical_stateful_example.backward_compatibility_example()¶

Show that existing code continues to work unchanged.

Return type:

dict[str, Any]

haive.core.graph.node.practical_stateful_example.meta_state_integration_example()¶

Show how stateful nodes work with MetaStateSchema.

Return type:

Any

haive.core.graph.node.practical_stateful_example.practical_stateful_example()¶

Practical example showing how stateful nodes work with current architecture.

Return type:

Any