Hello World

 1"""
 2Hello World!
 3"""
 4
 5from cognition import Cogent, DecisionProcess, IOContainer, Operator
 6
 7# ===
 8
 9# dp state is boolean, starting as False
10my_cogent = Cogent(DecisionProcess(lambda: False))
11
12
13@my_cogent.dp.operator(
14    "hello", terminal=True
15)  # shortcut to create + add an operator instance
16#    (named "hello" with the terminal flag to stop the DP)
17class HelloOperator(Operator[bool]):
18    """
19    Says hello!
20    """
21
22    def can_perform(self, state: bool, _io: IOContainer) -> bool:
23        # this will only apply if the state is False
24        return not state
25
26    def perform(self, _state: bool, _io: IOContainer) -> bool:
27        print("Hello, World!")
28
29        # mutable state can be just changed;
30        # returned values replace state
31        return True
32
33
34# initial state
35print(f"{my_cogent.dp.state}")
36
37# nifty way to run the cogent 🤓
38# 0. no arguments/sensors/actuators, so just starts the DP
39# 1. elaborate: no elaborators, done!
40# 2. terminal: no checks; no prior action selected; done!
41# 3. propose: hello (via can_perform, where state=False) is proposed!
42# 4. rank: only one action, so hello is selected
43# 5. apply: print, new state applied (via perform, where state=False)
44# 6. elaborate: no elaborators, done!
45# 7. terminal: no checks; prior action was terminal -> stop!
46# 8. by default, cogent doesn't continue after dp -> done!
47my_cogent()
48
49# final state
50print(f"{my_cogent.dp.state}")