MCPcopy Create free account
hub / github.com/FastMAS/KVCOMM / Node

Class Node

KVCOMM/graph/node.py:9–274  ·  view source on GitHub ↗

Represents a processing unit within a graph-based framework. This class encapsulates the functionality for a node in a graph, managing connections to other nodes, handling inputs and outputs, and executing assigned operations. It supports both individual and aggregated processing m

Source from the content-addressed store, hash-verified

7
8node_id_ = 0
9class Node(ABC):
10 """
11 Represents a processing unit within a graph-based framework.
12
13 This class encapsulates the functionality for a node in a graph, managing
14 connections to other nodes, handling inputs and outputs, and executing
15 assigned operations. It supports both individual and aggregated processing modes.
16
17 Attributes:
18 id (uuid.UUID): Unique identifier for the node.
19 agent_type(str): Associated agent name for node-specific operations.
20 spatial_predecessors (List[Node]): Nodes that precede this node in the graph.
21 spatial_successors (List[Node]): Nodes that succeed this node in the graph.
22 inputs (List[Any]): Inputs to be processed by the node.
23 outputs (List[Any]): Results produced after node execution.
24 raw_inputs (List[Any]): The original input contains the question or math problem.
25 last_memory (Dict[str,List[Any]]): Input and output of the previous timestamp.
26
27 Methods:
28 add_predecessor(operation):
29 Adds a node as a predecessor of this node, establishing a directed connection.
30 add_successor(operation):
31 Adds a node as a successor of this node, establishing a directed connection.
32 memory_update():
33 Update the last_memory.
34 get_spatial_info():
35 Get all of the info from spatial spatial_predecessors.
36 execute(**kwargs):
37 Processes the inputs through the node's operation, handling each input individually.
38 _execute(input, **kwargs):
39 An internal method that defines how a single input is processed by the node. This method should be implemented specifically for each node type.
40 _process_inputs(raw_inputs, spatial_info, temporal_info, **kwargs)->List[Any]:
41 An internal medthod to process the raw_input, the spatial info and temporal info to get the final inputs.
42 """
43
44 def __init__(self,
45 id: Optional[str],
46 agent_name:str="",
47 domain:str="",
48 llm_name:str = "",
49 ):
50 """
51 Initializes a new Node instance.
52 """
53 global node_id_
54 self.id:str = id if id is not None else str(node_id_)
55 node_id_ += 1
56 self.agent_name:str = agent_name
57 self.domain:str = domain
58 self.llm_name:str = llm_name
59 self.spatial_predecessors: List[Node] = []
60 self.spatial_successors: List[Node] = []
61 self.temporal_predecessors: List[Node] = []
62 self.temporal_successors: List[Node] = []
63 self.inputs: List[Any] = []
64 self.outputs: List[Any] = []
65 self.raw_inputs: List[Any] = []
66 self.role = ""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected