NodeActor
Unified NodeActor supporting both sync and async execution
Attributes
attribute
idUUID
= actor_id or uuid4()
attribute
nodeT
= node
attribute
llm= llm
attribute
node_state= node.get_new_state()
attribute
status= NodeActorStatus.IDLE
attribute
errorNodeActorError | None
= None
attribute
logger= logging.LoggerAdapter(logger, {'actor_id': str(self.id)})
attribute
composite_idstr
Functions
func
__init____init__(self, /, node, actor_id=None, llm=None)
param
selfparam
nodeT
param
actor_idUUID | None
= None
param
llmBaseChatModel | None
= None
Returns
None
func
__repr____repr__(self) -> str
param
selfReturns
str
func
can_restorecan_restore(cls, /, node, saved_state) -> bool
Check if NodeActor can be restored based on node type and status
param
clsparam
nodeBaseNode[S, NS]
param
saved_statedict[str, Any]
Returns
bool
func
createcreate(cls, /, node, actor_id=None, llm=None) -> Self
Create a NodeActor instance from a node.
Args: node: The node to wrap in this actor actor_id: Optional custom actor ID llm: Optional LLM instance for LLMNodes
Returns: Configured NodeActor instance
param
clsparam
nodeT
param
actor_idUUID | None
= None
param
llmBaseChatModel | None
= None
Returns
Self
func
create_or_restorecreate_or_restore(cls, /, node, state, llm=None) -> Self
Create a new NodeActor or restore from saved state
Args: node: The node to wrap in this actor state: Saved state to restore llm: Optional LLM instance for LLMNodes
Returns: NodeActor instance (new or restored)
param
clsparam
nodeT
param
statedict[str, Any] | None
param
llmBaseChatModel | None
= None
Returns
Self
func
executeexecute(self, /, input_, execution_id, context=None) -> Result
Execute the wrapped node with the provided inputs (async version).
Args: input_: Input for the node context: Additional execution context execution_id: Execution tracking ID
Returns: Result from node execution
Raises: NodeActorError: If execution fails or actor is in invalid state
param
selfparam
input_Any
param
execution_idUUID
param
contextdict[str, Any] | None
= None
Returns
Result
func
serialize_stateserialize_state(self) -> dict[str, Any]
Serialize NodeActor state for persistence
param
selfReturns
dict[str, Any]
func
_initialize_initialize(self) -> None
Initialize the actor and prepare for execution (async version)
param
selfReturns
None
func
_execute_internal_execute_internal(self, /, input_, context, execution_id) -> Result
param
selfparam
input_Any
param
contextdict[str, Any]
param
execution_idUUID
Returns
Result
func
_execute_llm_node_execute_llm_node(self, /, input_) -> LangChainMessage
param
selfparam
input_Any
Returns
LangChainMessage
func
_execute_tool_node_execute_tool_node(self, /, input_, execution_context) -> ToolMessage
param
selfparam
input_Any
param
execution_contextExecutionContext[ToolNodeState]
Returns
ToolMessage
func
_execute_function_node_execute_function_node(self, /, input_, execution_context) -> Any
param
selfparam
input_Any
param
execution_contextExecutionContext[NS]
Returns
Any
func
_get_next_nodes_get_next_nodes(self, /, output) -> list[NextNode]
Get the next nodes to execute based on the output
param
selfparam
outputLangChainMessage | ToolMessage | dict[str, Any] | None
Returns
list[NextNode]
func
_get_node_edges_get_node_edges(self) -> list[tuple[type[Node | LLMNode], EdgeSpec]]
param
selfReturns
list[tuple[type[Node | LLMNode], EdgeSpec]]
func
_build_evaluation_context_build_evaluation_context(self, /, output) -> tuple[dict[str, Any], dict[str, Any]]
Build context for edge condition evaluation Variables with $ prefix: $output, $status, $state Variables without $ prefix: taken from $state.context
param
selfparam
outputAny
Returns
tuple[dict[str, Any], dict[str, Any]]
func
_should_follow_edge_should_follow_edge(self, /, edge, context, state_context, transformer) -> bool
Determine if an edge should be followed based on its conditions
param
selfparam
edgeEdgeSpec
param
contextdict[str, Any]
param
state_contextdict[str, Any]
param
transformerWhenTransformer
Returns
bool
func
_prepare_execution_context_prepare_execution_context(self, /, context, execution_id) -> ExecutionContext[Any]
Prepare execution context with actor metadata
param
selfparam
contextdict[str, Any]
param
execution_idUUID
Returns
ExecutionContext[Any]
func
_restore_state_restore_state(self, /, state) -> None
Restore NodeActor state from serialized data
param
selfparam
statedict[str, Any]
Returns
None
Last updated on