Core API¶
Flows & Steps¶
protokol.AbstractFlow
¶
Bases: AbstractStep, ABC
A collection of Steps that form a directed graph. Flows inherit from AbstractStep, meaning an entire Flow can be nested as a single step inside another Flow.
Source code in src/protokol/core/flow.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
start_step_id
property
¶
Returns the ID of the first step in the flow (used when nesting flows).
steps
abstractmethod
property
¶
Dictionary mapping step IDs to their corresponding Step classes.
all_steps()
¶
Returns all instantiated steps.
Source code in src/protokol/core/flow.py
32 33 34 | |
get_context(plan)
¶
Flows themselves do not have context; the engine descends into their steps.
Source code in src/protokol/core/flow.py
42 43 44 | |
get_step(step_id)
¶
Retrieves an instantiated step by its ID.
Source code in src/protokol/core/flow.py
26 27 28 29 30 | |
next(plan, output)
¶
When a flow finishes, it should return control to the parent flow (or terminate).
Source code in src/protokol/core/flow.py
50 51 52 | |
process(plan, user_result)
¶
Flows manipulate global state via their child steps.
Source code in src/protokol/core/flow.py
46 47 48 | |
protokol.AbstractStep
¶
Bases: ABC
A single node in the state machine graph. Steps do NOT execute API calls. They define what is needed, process the result, and decide the next node.
Source code in src/protokol/core/step.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
id
abstractmethod
property
¶
The unique identifier for this step within a flow.
get_context(plan)
abstractmethod
¶
Yields the requirements (prompt, tools) for this step. The external engine will execute the LLM based on this context.
Source code in src/protokol/core/step.py
17 18 19 20 21 22 23 | |
next(plan, output)
abstractmethod
¶
Determines the next step(s) in the flow based on the current state and step output. Returns: - str: ID of the next step. - List[str]: IDs of multiple steps to execute in parallel. - None: Terminates the flow.
Source code in src/protokol/core/step.py
34 35 36 37 38 39 40 41 42 43 | |
process(plan, user_result)
abstractmethod
¶
Processes the result returned by the user's execution loop (e.g., the LLM response). Updates the plan.state as needed. Returns a dictionary representing the output of this step.
Source code in src/protokol/core/step.py
25 26 27 28 29 30 31 32 | |
Types¶
protokol.StepContext
dataclass
¶
Yielded by a Step to request execution from the user's domain. It contains the prompt, required tools, and any kwargs (e.g., temperature) the LLM needs.
Source code in src/protokol/core/types.py
60 61 62 63 64 65 66 67 68 | |
protokol.RunPlan
dataclass
¶
The complete, serializable memory of the state machine. This object is passed between steps and can be persisted to a database to pause/resume workflows.
Source code in src/protokol/core/types.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
from_json(data)
classmethod
¶
Hydrates a RunPlan from a JSON string.
Source code in src/protokol/core/types.py
149 150 151 152 153 | |
get_step_state(step_id)
¶
Retrieves or initializes the retry state for a specific step.
Source code in src/protokol/core/types.py
104 105 106 107 108 | |
reset_step_state(step_id)
¶
Resets attempt counters for a step after a successful run.
Source code in src/protokol/core/types.py
110 111 112 113 114 | |
to_json()
¶
Serializes the RunPlan for database persistence.
Source code in src/protokol/core/types.py
145 146 147 | |