haive.core.common.mixins.state_interface_mixin¶
State interface mixin for managing state access in components.
This module provides a mixin class that adds state management configuration to Pydantic models, allowing components to specify whether they use state and which key they access in the state store.
- Usage:
from pydantic import BaseModel from haive.core.common.mixins import StateInterfaceMixin
- class MyStatefulComponent(StateInterfaceMixin, BaseModel):
# Other fields name: str
- def process(self, inputs, state=None):
- if self.use_state and state:
# Access state using the configured key component_state = state.get(self.state_key, {}) # Update state component_state[“visits”] = component_state.get(“visits”, 0) + 1 state[self.state_key] = component_state
return {“result”: f”Processed {self.name}”}
Classes¶
Mixin that adds state management configuration to any Pydantic model. |
Module Contents¶
- class haive.core.common.mixins.state_interface_mixin.StateInterfaceMixin(/, **data)[source]¶
Bases:
pydantic.BaseModelMixin that adds state management configuration to any Pydantic model.
This mixin allows components to declare whether they use a state store and which key they use to access their portion of the state. This is commonly used in stateful nodes within a processing graph.
- Parameters:
data (Any)
- use_state¶
Boolean flag indicating whether this component uses state.
- state_key¶
The key used to access this component’s state in the state store.
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.